def polish(self, action, name): self.commit_all_editors_to_container() with BusyCursor(): self.add_savepoint(name) try: report = tweak_polish(current_container(), {action: True}) except: self.rewind_savepoint() raise self.apply_container_update_to_gui() from calibre.ebooks.markdown import markdown report = markdown("# %s\n\n" % self.current_metadata.title + "\n\n".join(report), output_format="html4") d = QDialog(self.gui) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.Close) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_()
def polish(self, action, name): self.commit_all_editors_to_container() with BusyCursor(): self.add_savepoint(name) try: report = tweak_polish(current_container(), {action: True}) except: self.rewind_savepoint() raise self.apply_container_update_to_gui() from calibre.ebooks.markdown import markdown report = markdown('# %s\n\n' % self.current_metadata.title + '\n\n'.join(report), output_format='html4') d = QDialog(self.gui) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.Close) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_()
def add_builtin_recipe(self): from calibre.web.feeds.recipes.collection import \ get_builtin_recipe_collection, get_builtin_recipe_by_id from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \ QListWidget, QDialogButtonBox, QSize d = QDialog(self) d.l = QVBoxLayout() d.setLayout(d.l) d.list = QListWidget(d) d.list.doubleClicked.connect(lambda x: d.accept()) d.l.addWidget(d.list) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, Qt.Horizontal, d) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.l.addWidget(d.bb) d.setWindowTitle(_('Choose builtin recipe')) items = [] for r in get_builtin_recipe_collection(): id_ = r.get('id', '') title = r.get('title', '') lang = r.get('language', '') if id_ and title: items.append((title + ' [%s]'%lang, id_)) items.sort(key=lambda x:sort_key(x[0])) for title, id_ in items: item = QListWidgetItem(title) item.setData(Qt.UserRole, id_) d.list.addItem(item) d.resize(QSize(450, 400)) ret = d.exec_() d.list.doubleClicked.disconnect() if ret != d.Accepted: return items = list(d.list.selectedItems()) if not items: return item = items[-1] id_ = unicode(item.data(Qt.UserRole).toString()) title = unicode(item.data(Qt.DisplayRole).toString()).rpartition(' [')[0] profile = get_builtin_recipe_by_id(id_, download_recipe=True) if profile is None: raise Exception('Something weird happened') if self._model.has_title(title): if question_dialog(self, _('Replace recipe?'), _('A custom recipe named %s already exists. Do you want to ' 'replace it?')%title): self._model.replace_by_title(title, profile) else: return else: self.model.add(title, profile) self.clear()
def confirm_quit(self): if self.doing_terminal_save: return False if self.save_manager.has_tasks: if not question_dialog( self.gui, _('Are you sure?'), _('The current book is being saved in the background, quitting will abort' ' the save process, are you sure?'), default_yes=False): return False if self.gui.action_save.isEnabled(): d = QDialog(self.gui) d.l = QGridLayout(d) d.setLayout(d.l) d.setWindowTitle(_('Unsaved changes')) d.i = QLabel('') d.i.setPixmap( QPixmap(I('save.png')).scaledToHeight(64, Qt.SmoothTransformation)) d.i.setMaximumSize(QSize(d.i.pixmap().width(), 64)) d.i.setScaledContents(True) d.l.addWidget(d.i, 0, 0) d.m = QLabel( _('There are unsaved changes, if you quit without saving, you will lose them.' )) d.m.setWordWrap(True) d.l.addWidget(d.m, 0, 1) d.bb = QDialogButtonBox(QDialogButtonBox.Cancel) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.l.addWidget(d.bb, 1, 0, 1, 2) d.do_save = None def endit(x): d.do_save = x d.accept() b = d.bb.addButton(_('&Save and Quit'), QDialogButtonBox.ActionRole) b.setIcon(QIcon(I('save.png'))) b.clicked.connect(lambda *args: endit(True)) b = d.bb.addButton(_('&Quit without saving'), QDialogButtonBox.ActionRole) b.clicked.connect(lambda *args: endit(False)) d.resize(d.sizeHint()) if d.exec_() != d.Accepted or d.do_save is None: return False if d.do_save: self.gui.action_save.trigger() self.gui.blocking_job.set_msg(_('Saving, please wait...')) self.gui.blocking_job.start() self.doing_terminal_save = True QTimer.singleShot(50, self.check_terminal_save) return False return True
def confirm_quit(self): if self.doing_terminal_save: return False if self.save_manager.has_tasks: if not question_dialog( self.gui, _("Are you sure?"), _( "The current book is being saved in the background, quitting will abort" " the save process, are you sure?" ), default_yes=False, ): return False if self.gui.action_save.isEnabled(): d = QDialog(self.gui) d.l = QGridLayout(d) d.setLayout(d.l) d.setWindowTitle(_("Unsaved changes")) d.i = QLabel("") d.i.setPixmap(QPixmap(I("save.png")).scaledToHeight(64, Qt.SmoothTransformation)) d.i.setMaximumSize(QSize(d.i.pixmap().width(), 64)) d.i.setScaledContents(True) d.l.addWidget(d.i, 0, 0) d.m = QLabel(_("There are unsaved changes, if you quit without saving, you will lose them.")) d.m.setWordWrap(True) d.l.addWidget(d.m, 0, 1) d.bb = QDialogButtonBox(QDialogButtonBox.Cancel) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.l.addWidget(d.bb, 1, 0, 1, 2) d.do_save = None def endit(x): d.do_save = x d.accept() b = d.bb.addButton(_("&Save and Quit"), QDialogButtonBox.ActionRole) b.setIcon(QIcon(I("save.png"))) b.clicked.connect(lambda *args: endit(True)) b = d.bb.addButton(_("&Quit without saving"), QDialogButtonBox.ActionRole) b.clicked.connect(lambda *args: endit(False)) d.resize(d.sizeHint()) if d.exec_() != d.Accepted or d.do_save is None: return False if d.do_save: self.gui.action_save.trigger() self.gui.blocking_job.set_msg(_("Saving, please wait...")) self.gui.blocking_job.start() self.doing_terminal_save = True QTimer.singleShot(50, self.check_terminal_save) return False return True
def show_report(changed, title, report, parent, show_current_diff): report = format_report(title, report) d = QDialog(parent) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.Close) if changed: b = d.b = d.bb.addButton(_('See what &changed'), d.bb.AcceptRole) b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False) b.clicked.connect(partial(show_current_diff, allow_revert=True)) d.bb.button(d.bb.Close).setDefault(True) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_()
def polish(self, action, name): if not self.check_dirtied(): return self.add_savepoint(name) try: report = tweak_polish(current_container(), {action:True}) except: self.rewind_savepoint() raise self.apply_container_update_to_gui() from calibre.ebooks.markdown import markdown report = markdown('# %s\n\n'%self.current_metadata.title + '\n\n'.join(report), output_format='html4') d = QDialog(self.gui) d.l = QVBoxLayout() d.setLayout(d.l) d.e = QTextBrowser(d) d.l.addWidget(d.e) d.e.setHtml(report) d.bb = QDialogButtonBox(QDialogButtonBox.Close) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) d.resize(600, 400) d.exec_()
dev = self.parent().device_manager.connected_device dev.highlight_ignored_folders = True self.parent().configure_connected_device() dev.highlight_ignored_folders = False if __name__ == "__main__": from calibre.gui2 import Application from calibre.devices.mtp.driver import MTP_DEVICE from calibre.devices.scanner import DeviceScanner s = DeviceScanner() s.scan() app = Application([]) dev = MTP_DEVICE(None) dev.startup() cd = dev.detect_managed_devices(s.devices) dev.open(cd, "test") cw = dev.config_widget() d = QDialog() d.l = QVBoxLayout() d.setLayout(d.l) d.l.addWidget(cw) bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) d.l.addWidget(bb) bb.accepted.connect(d.accept) bb.rejected.connect(d.reject) if d.exec_() == d.Accepted: cw.commit() dev.shutdown()
QDialog.accept(self) dev = self.parent().device_manager.connected_device dev.highlight_ignored_folders = True self.parent().configure_connected_device() dev.highlight_ignored_folders = False if __name__ == '__main__': from calibre.gui2 import Application from calibre.devices.mtp.driver import MTP_DEVICE from calibre.devices.scanner import DeviceScanner s = DeviceScanner() s.scan() app = Application([]) dev = MTP_DEVICE(None) dev.startup() cd = dev.detect_managed_devices(s.devices) dev.open(cd, 'test') cw = dev.config_widget() d = QDialog() d.l = QVBoxLayout() d.setLayout(d.l) d.l.addWidget(cw) bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) d.l.addWidget(bb) bb.accepted.connect(d.accept) bb.rejected.connect(d.reject) if d.exec_() == d.Accepted: cw.commit() dev.shutdown()
def add_builtin_recipe(self): from calibre.web.feeds.recipes.collection import \ get_builtin_recipe_collection, get_builtin_recipe_by_id from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \ QListWidget, QDialogButtonBox, QSize d = QDialog(self) d.l = QVBoxLayout() d.setLayout(d.l) d.list = QListWidget(d) d.list.doubleClicked.connect(lambda x: d.accept()) d.l.addWidget(d.list) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, d) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.l.addWidget(d.bb) d.setWindowTitle(_('Choose builtin recipe')) items = [] for r in get_builtin_recipe_collection(): id_ = r.get('id', '') title = r.get('title', '') lang = r.get('language', '') if id_ and title: items.append((title + ' [%s]' % lang, id_)) items.sort(key=lambda x: sort_key(x[0])) for title, id_ in items: item = QListWidgetItem(title) item.setData(Qt.UserRole, id_) d.list.addItem(item) d.resize(QSize(450, 400)) ret = d.exec_() d.list.doubleClicked.disconnect() if ret != d.Accepted: return items = list(d.list.selectedItems()) if not items: return item = items[-1] id_ = unicode(item.data(Qt.UserRole).toString()) title = unicode(item.data( Qt.DisplayRole).toString()).rpartition(' [')[0] profile = get_builtin_recipe_by_id(id_, download_recipe=True) if profile is None: raise Exception('Something weird happened') if self._model.has_title(title): if question_dialog( self, _('Replace recipe?'), _('A custom recipe named %s already exists. Do you want to ' 'replace it?') % title): self._model.replace_by_title(title, profile) else: return else: self.model.add(title, profile) self.clear()