def __init__(self, pathtobook, title=None, parent=None, prefs=None): QDialog.__init__(self, parent) self.prefs = prefs or gprefs self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s')%t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(200) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignHCenter|Qt.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...')%t) la.setWordWrap(True) f = la.font() f.setPointSize(20), la.setFont(f) ll.addWidget(la, alignment=Qt.AlignHCenter|Qt.AlignTop) self.toc_view = TOCView(self, self.prefs) self.toc_view.add_new_item.connect(self.add_new_item) self.toc_view.tocw.history_state_changed.connect(self.update_history_buttons) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.undo_button = b = bb.addButton(_('&Undo'), bb.ActionRole) b.setToolTip(_('Undo the last action, if any')) b.setIcon(QIcon(I('edit-undo.png'))) b.clicked.connect(self.toc_view.undo) self.explode_done.connect(self.read_toc, type=Qt.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.QueuedConnection) self.resize(950, 630) geom = self.prefs.get('toc_editor_window_geom', None) if geom is not None: self.restoreGeometry(bytes(geom)) self.stacks.currentChanged.connect(self.update_history_buttons) self.update_history_buttons()
def __init__(self, pathtobook, title=None, parent=None, prefs=None): QDialog.__init__(self, parent) self.prefs = prefs or gprefs self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s')%t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(200) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignHCenter|Qt.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...')%t) la.setWordWrap(True) la.setStyleSheet('QLabel { font-size: 20pt }') ll.addWidget(la, alignment=Qt.AlignHCenter|Qt.AlignTop) self.toc_view = TOCView(self, self.prefs) self.toc_view.add_new_item.connect(self.add_new_item) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.explode_done.connect(self.read_toc, type=Qt.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.QueuedConnection) self.resize(950, 630) geom = self.prefs.get('toc_editor_window_geom', None) if geom is not None: self.restoreGeometry(bytes(geom))
class TOCEditor(QDialog): # {{{ explode_done = pyqtSignal(object) writing_done = pyqtSignal(object) def __init__(self, pathtobook, title=None, parent=None): QDialog.__init__(self, parent) self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s')%t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(200) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignHCenter|Qt.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...')%t) la.setWordWrap(True) la.setStyleSheet('QLabel { font-size: 20pt }') ll.addWidget(la, alignment=Qt.AlignHCenter|Qt.AlignTop) self.toc_view = TOCView(self) self.toc_view.add_new_item.connect(self.add_new_item) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.explode_done.connect(self.read_toc, type=Qt.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.QueuedConnection) self.resize(950, 630) geom = gprefs.get('toc_editor_window_geom', None) if geom is not None: self.restoreGeometry(bytes(geom)) def add_new_item(self, item, where): self.item_edit(item, where) self.stacks.setCurrentIndex(2) def accept(self): if self.stacks.currentIndex() == 2: self.toc_view.update_item(*self.item_edit.result) gprefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState()) self.stacks.setCurrentIndex(1) elif self.stacks.currentIndex() == 1: self.working = False Thread(target=self.write_toc).start() self.pi.startAnimation() self.wait_label.setText(_('Writing %s, please wait...')% self.book_title) self.stacks.setCurrentIndex(0) self.bb.setEnabled(False) def really_accept(self, tb): gprefs['toc_editor_window_geom'] = bytearray(self.saveGeometry()) if tb: error_dialog(self, _('Failed to write book'), _('Could not write %s. Click "Show details" for' ' more information.')%self.book_title, det_msg=tb, show=True) gprefs['toc_editor_window_geom'] = bytearray(self.saveGeometry()) super(TOCEditor, self).reject() return super(TOCEditor, self).accept() def reject(self): if not self.bb.isEnabled(): return if self.stacks.currentIndex() == 2: gprefs['toc_edit_splitter_state'] = bytearray(self.item_edit.splitter.saveState()) self.stacks.setCurrentIndex(1) else: self.working = False gprefs['toc_editor_window_geom'] = bytearray(self.saveGeometry()) super(TOCEditor, self).reject() def start(self): t = Thread(target=self.explode) t.daemon = True self.log = GUILog() t.start() def explode(self): tb = None try: self.ebook = get_container(self.pathtobook, log=self.log) except: import traceback tb = traceback.format_exc() if self.working: self.working = False self.explode_done.emit(tb) def read_toc(self, tb): if tb: error_dialog(self, _('Failed to load book'), _('Could not load %s. Click "Show details" for' ' more information.')%self.book_title, det_msg=tb, show=True) self.reject() return self.pi.stopAnimation() self.toc_view(self.ebook) self.item_edit.load(self.ebook) self.stacks.setCurrentIndex(1) def write_toc(self): tb = None try: toc = self.toc_view.create_toc() commit_toc(self.ebook, toc, lang=self.toc_view.toc_lang, uid=self.toc_view.toc_uid) self.ebook.commit() except: import traceback tb = traceback.format_exc() self.writing_done.emit(tb)
class TOCEditor(QDialog): # {{{ explode_done = pyqtSignal(object) writing_done = pyqtSignal(object) def __init__(self, pathtobook, title=None, parent=None, prefs=None): QDialog.__init__(self, parent) self.prefs = prefs or gprefs self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s') % t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(200) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignHCenter | Qt.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...') % t) la.setWordWrap(True) f = la.font() f.setPointSize(20), la.setFont(f) ll.addWidget(la, alignment=Qt.AlignHCenter | Qt.AlignTop) self.toc_view = TOCView(self, self.prefs) self.toc_view.add_new_item.connect(self.add_new_item) self.toc_view.tocw.history_state_changed.connect( self.update_history_buttons) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.undo_button = b = bb.addButton(_('&Undo'), bb.ActionRole) b.setToolTip(_('Undo the last action, if any')) b.setIcon(QIcon(I('edit-undo.png'))) b.clicked.connect(self.toc_view.undo) self.explode_done.connect(self.read_toc, type=Qt.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.QueuedConnection) self.resize(950, 630) geom = self.prefs.get('toc_editor_window_geom', None) if geom is not None: self.restoreGeometry(bytes(geom)) self.stacks.currentChanged.connect(self.update_history_buttons) self.update_history_buttons() def update_history_buttons(self): self.undo_button.setVisible(self.stacks.currentIndex() == 1) self.undo_button.setEnabled(bool(self.toc_view.tocw.history)) def add_new_item(self, item, where): self.item_edit(item, where) self.stacks.setCurrentIndex(2) def accept(self): if self.stacks.currentIndex() == 2: self.toc_view.update_item(*self.item_edit.result) self.prefs['toc_edit_splitter_state'] = bytearray( self.item_edit.splitter.saveState()) self.stacks.setCurrentIndex(1) elif self.stacks.currentIndex() == 1: self.working = False Thread(target=self.write_toc).start() self.pi.startAnimation() self.wait_label.setText( _('Writing %s, please wait...') % self.book_title) self.stacks.setCurrentIndex(0) self.bb.setEnabled(False) def really_accept(self, tb): self.prefs['toc_editor_window_geom'] = bytearray(self.saveGeometry()) if tb: error_dialog(self, _('Failed to write book'), _('Could not write %s. Click "Show details" for' ' more information.') % self.book_title, det_msg=tb, show=True) self.prefs['toc_editor_window_geom'] = bytearray( self.saveGeometry()) super(TOCEditor, self).reject() return super(TOCEditor, self).accept() def reject(self): if not self.bb.isEnabled(): return if self.stacks.currentIndex() == 2: self.prefs['toc_edit_splitter_state'] = bytearray( self.item_edit.splitter.saveState()) self.stacks.setCurrentIndex(1) else: self.working = False self.prefs['toc_editor_window_geom'] = bytearray( self.saveGeometry()) super(TOCEditor, self).reject() def start(self): t = Thread(target=self.explode) t.daemon = True self.log = GUILog() t.start() def explode(self): tb = None try: self.ebook = get_container(self.pathtobook, log=self.log) except: import traceback tb = traceback.format_exc() if self.working: self.working = False self.explode_done.emit(tb) def read_toc(self, tb): if tb: error_dialog(self, _('Failed to load book'), _('Could not load %s. Click "Show details" for' ' more information.') % self.book_title, det_msg=tb, show=True) self.reject() return self.pi.stopAnimation() self.toc_view(self.ebook) self.item_edit.load(self.ebook) self.stacks.setCurrentIndex(1) def write_toc(self): tb = None try: toc = self.toc_view.create_toc() toc.toc_title = getattr(self.toc_view, 'toc_title', None) commit_toc(self.ebook, toc, lang=self.toc_view.toc_lang, uid=self.toc_view.toc_uid) self.ebook.commit() except: import traceback tb = traceback.format_exc() self.writing_done.emit(tb)
def __init__(self, pathtobook, title=None, parent=None, prefs=None, write_result_to=None): QDialog.__init__(self, parent) self.write_result_to = write_result_to self.prefs = prefs or te_prefs self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s') % t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(QSize(200, 200)) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...') % t) la.setWordWrap(True) f = la.font() f.setPointSize(20), la.setFont(f) ll.addWidget(la, alignment=Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop) self.toc_view = TOCView(self, self.prefs) self.toc_view.add_new_item.connect(self.add_new_item) self.toc_view.tocw.history_state_changed.connect( self.update_history_buttons) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.undo_button = b = bb.addButton( _('&Undo'), QDialogButtonBox.ButtonRole.ActionRole) b.setToolTip(_('Undo the last action, if any')) b.setIcon(QIcon(I('edit-undo.png'))) b.clicked.connect(self.toc_view.undo) self.explode_done.connect(self.read_toc, type=Qt.ConnectionType.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.ConnectionType.QueuedConnection) r = QApplication.desktop().availableGeometry(self) self.resize(r.width() - 100, r.height() - 100) geom = self.prefs.get('toc_editor_window_geom', None) if geom is not None: QApplication.instance().safe_restore_geometry(self, bytes(geom)) self.stacks.currentChanged.connect(self.update_history_buttons) self.update_history_buttons()