Example #1
0
    def book_opened(self, job):
        ef = getattr(self, '_edit_file_on_open', None)
        cn = getattr(self, '_clear_notify_data', True)
        self._edit_file_on_open = None

        if job.traceback is not None:
            if 'DRMError:' in job.traceback:
                from calibre.gui2.dialogs.drm_error import DRMErrorMessage
                return DRMErrorMessage(self.gui).exec_()
            return error_dialog(self.gui, _('Failed to open book'),
                    _('Failed to open book, click Show details for more information.'),
                                det_msg=job.traceback, show=True)
        if cn:
            self.save_manager.clear_notify_data()
        parse_worker.clear()
        container = job.result
        set_current_container(container)
        with BusyCursor():
            self.current_metadata = self.gui.current_metadata = container.mi
            self.global_undo.open_book(container)
            self.gui.update_window_title()
            self.gui.file_list.current_edited_name = None
            self.gui.file_list.build(container, preserve_state=False)
            self.gui.action_save.setEnabled(False)
            self.update_global_history_actions()
            recent_books = list(tprefs.get('recent-books', []))
            path = container.path_to_ebook
            if path in recent_books:
                recent_books.remove(path)
            recent_books.insert(0, path)
            tprefs['recent-books'] = recent_books[:10]
            self.gui.update_recent_books()
            if ef:
                self.gui.file_list.request_edit(ef)
            self.gui.toc_view.update_if_visible()
Example #2
0
 def test(cls):
     from calibre.ebooks.oeb.polish.container import get_container
     from calibre.gui2.tweak_book import set_current_container
     set_current_container(get_container(sys.argv[-1], tweak_mode=True))
     set_book_locale(current_container().mi.language)
     d = cls()
     QTimer.singleShot(0, d.refresh)
     d.exec_()
Example #3
0
 def book_opened(self, job):
     if job.traceback is not None:
         return error_dialog(self, _('Failed to open book'),
                 _('Failed to open book, click Show details for more information.'),
                             det_msg=job.traceback, show=True)
     container = job.result
     set_current_container(container)
     self.current_metadata = container.mi
     self.global_undo.open_book(container)
     self.update_window_title()
     self.file_list.build(container)
Example #4
0
 def book_opened(self, job):
     if job.traceback is not None:
         return error_dialog(self.gui, _('Failed to open book'),
                 _('Failed to open book, click Show details for more information.'),
                             det_msg=job.traceback, show=True)
     container = job.result
     set_current_container(container)
     self.current_metadata = self.gui.current_metadata = container.mi
     self.global_undo.open_book(container)
     self.gui.update_window_title()
     self.gui.file_list.build(container, preserve_state=False)
     self.gui.action_save.setEnabled(False)
     self.update_global_history_actions()
Example #5
0
    def book_opened(self, job):
        ef = getattr(self, '_edit_file_on_open', None)
        cn = getattr(self, '_clear_notify_data', True)
        self._edit_file_on_open = None

        if job.traceback is not None:
            if 'DRMError:' in job.traceback:
                from calibre.gui2.dialogs.drm_error import DRMErrorMessage
                return DRMErrorMessage(self.gui).exec_()
            return error_dialog(
                self.gui,
                _('Failed to open book'),
                _('Failed to open book, click Show details for more information.'
                  ),
                det_msg=job.traceback,
                show=True)
        if cn:
            self.save_manager.clear_notify_data()
        parse_worker.clear()
        container = job.result
        set_current_container(container)
        with BusyCursor():
            self.current_metadata = self.gui.current_metadata = container.mi
            self.global_undo.open_book(container)
            self.gui.update_window_title()
            self.gui.file_list.current_edited_name = None
            self.gui.file_list.build(container, preserve_state=False)
            self.gui.action_save.setEnabled(False)
            self.update_global_history_actions()
            recent_books = list(tprefs.get('recent-books', []))
            path = container.path_to_ebook
            if path in recent_books:
                recent_books.remove(path)
            recent_books.insert(0, path)
            tprefs['recent-books'] = recent_books[:10]
            self.gui.update_recent_books()
            if ef:
                self.gui.file_list.request_edit(ef)
            self.gui.toc_view.update_if_visible()
Example #6
0
 def rewind_savepoint(self):
     container = self.global_undo.rewind_savepoint()
     if container is not None:
         set_current_container(container)
         self.update_global_history_actions()
Example #7
0
 def add_savepoint(self, msg):
     nc = clone_container(current_container(), self.mkdtemp())
     self.global_undo.add_savepoint(nc, msg)
     set_current_container(nc)
     self.update_global_history_actions()
Example #8
0
 def do_global_redo(self):
     container = self.global_undo.redo()
     if container is not None:
         set_current_container(container)
         self.apply_container_update_to_gui()
Example #9
0
            t = Thread(name='DownloadResources', target=self.download_resources, args=(resources,))
            t.daemon = True
            t.start()
            return
        if self.state == 2:
            return
        self.wait.stop()
        Dialog.accept(self)

    def reject(self):
        if self.state == 2:
            return
        self.wait.stop()
        return Dialog.reject(self)

    def sizeHint(self):
        return QSize(800, 500)


if __name__ == '__main__':
    from calibre.gui2 import Application
    import sys
    app = Application([])
    from calibre.gui2.tweak_book import set_current_container
    from calibre.gui2.tweak_book.boss import get_container
    set_current_container(get_container(sys.argv[-1]))
    d = DownloadResources()
    d.exec_()
    print(d.show_diff)
    del d, app
Example #10
0
                       args=(resources, ))
            t.daemon = True
            t.start()
            return
        if self.state == 2:
            return
        self.wait.stop()
        Dialog.accept(self)

    def reject(self):
        if self.state == 2:
            return
        self.wait.stop()
        return Dialog.reject(self)

    def sizeHint(self):
        return QSize(800, 500)


if __name__ == '__main__':
    from calibre.gui2 import Application
    import sys
    app = Application([])
    from calibre.gui2.tweak_book import set_current_container
    from calibre.gui2.tweak_book.boss import get_container
    set_current_container(get_container(sys.argv[-1]))
    d = DownloadResources()
    d.exec_()
    print(d.show_diff)
    del d, app
Example #11
0
    def remove_fonts(self):
        fonts = self.get_selected_data()
        if not fonts:
            return
        changed = False
        for font in fonts:
            changed |= change_font(current_container(), font)
        if changed:
            self.model.build()
            self.container_changed.emit()

    def embed_fonts(self):
        self.embed_all_fonts.emit()

    def subset_fonts(self):
        self.subset_all_fonts.emit()

    def refresh(self):
        self.model.build()


if __name__ == '__main__':
    from calibre.gui2 import Application
    app = Application([])
    c = get_container(sys.argv[-1], tweak_mode=True)
    set_current_container(c)
    d = ManageFonts()
    d.exec_()
    del app
Example #12
0
        l.addWidget(self.bb)

    def reject(self):
        self.keep_going = False
        self.bb.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
        Dialog.reject(self)

    def progress_callback(self, num, total, name):
        self.gui_loop.emit(num, total, name)
        return self.keep_going

    def update_progress(self, num, total, name):
        self.progress.setMaximum(total), self.progress.setValue(num)
        self.msg.setText(name)

# }}}


if __name__ == '__main__':
    from calibre.gui2 import Application
    app = Application([])
    import sys, sip
    from calibre.ebooks.oeb.polish.container import get_container
    c = get_container(sys.argv[-1], tweak_mode=True)
    set_current_container(c)
    d = CompressImages()
    if d.exec_() == QDialog.DialogCode.Accepted:
        pass
    sip.delete(app)
    del app
Example #13
0
 def rewind_savepoint(self):
     container = self.global_undo.rewind_savepoint()
     if container is not None:
         set_current_container(container)
         self.update_global_history_actions()
Example #14
0
 def add_savepoint(self, msg):
     nc = clone_container(current_container(), self.mkdtemp())
     self.global_undo.add_savepoint(nc, msg)
     set_current_container(nc)
     self.update_global_history_actions()
Example #15
0
 def do_global_redo(self):
     container = self.global_undo.redo()
     if container is not None:
         set_current_container(container)
         self.apply_container_update_to_gui()