def import_words(self): d = QDialog(self) d.l = l = QFormLayout(d) d.setWindowTitle(_('Import list of words')) d.w = w = QPlainTextEdit(d) l.addRow(QLabel(_('Enter a list of words, one per line'))) l.addRow(w) d.b = b = QPushButton(_('Paste from clipboard')) l.addRow(b) b.clicked.connect(w.paste) d.la = la = QLabel(_('Words in the user dictionary must have an associated language. Choose the language below:')) la.setWordWrap(True) l.addRow(la) d.le = le = LanguagesEdit(d) lc = canonicalize_lang(get_lang()) if lc: le.lang_codes = [lc] l.addRow(_('&Language:'), le) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addRow(bb) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) if d.exec_() != d.Accepted: return lc = le.lang_codes if not lc: return error_dialog(self, _('Must specify language'), _( 'You must specify a language to import words'), show=True) words = set(filter(None, [x.strip() for x in unicode(w.toPlainText()).splitlines()])) lang = lc[0] words = {(w, lang) for w in words} - self.current_dictionary.words if dictionaries.add_to_user_dictionary(self.current_dictionary.name, words, None): dictionaries.clear_caches() self.show_current_dictionary() self.dictionaries_changed = True
def link_stylesheets(self, names): s = self.categories['styles'] sheets = [unicode(s.child(i).data(0, NAME_ROLE).toString()) for i in xrange(s.childCount())] if not sheets: return error_dialog(self, _('No stylesheets'), _( 'This book currently has no stylesheets. You must first create a stylesheet' ' before linking it.'), show=True) d = QDialog(self) d.l = l = QVBoxLayout(d) d.setLayout(l) d.setWindowTitle(_('Choose stylesheets')) d.la = la = QLabel(_('Choose the stylesheets to link. Drag and drop to re-arrange')) la.setWordWrap(True) l.addWidget(la) d.s = s = QListWidget(d) l.addWidget(s) s.setDragEnabled(True) s.setDropIndicatorShown(True) s.setDragDropMode(self.InternalMove) s.setAutoScroll(True) s.setDefaultDropAction(Qt.MoveAction) for name in sheets: i = QListWidgetItem(name, s) flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable i.setFlags(flags) i.setCheckState(Qt.Checked) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addWidget(bb) if d.exec_() == d.Accepted: sheets = [unicode(s.item(i).text()) for i in xrange(s.count()) if s.item(i).checkState() == Qt.Checked] if sheets: self.link_stylesheets_requested.emit(names, sheets)
def add_word(self): d = QDialog(self) d.l = l = QFormLayout(d) d.setWindowTitle(_('Add a word')) d.w = w = QLineEdit(d) w.setPlaceholderText(_('Word to add')) l.addRow(_('&Word:'), w) d.loc = loc = LanguagesEdit(parent=d) l.addRow(_('&Language:'), d.loc) loc.lang_codes = [canonicalize_lang(get_lang())] d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addRow(bb) if d.exec_() != d.Accepted: return word = unicode(w.text()) lang = (loc.lang_codes or [canonicalize_lang(get_lang())])[0] if not word: return if (word, lang) not in self.current_dictionary.words: dictionaries.add_to_user_dictionary(self.current_dictionary.name, word, DictionaryLocale(lang, None)) dictionaries.clear_caches() self.show_current_dictionary() self.dictionaries_changed = True idx = self.find_word(word, lang) if idx > -1: self.words.scrollToItem(self.words.item(idx))
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 dial(self): dial = QDialog(self) dial.setWindowTitle("Select a layer") layerList = QListWidget(dial) db = GPostGISDatabase() for t in db.tables(): layerList.addItem(t) dial.setBaseSize(layerList.minimumSize()) dial.show()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt4.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QLabel, Qt, QLineEdit, QCheckBox) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): config_dialog.resize(config_dialog.sizeHint()) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) from calibre.customize.ui import (plugin_customization, customize_plugin) help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) bf = QCheckBox(_('Add linked files in breadth first order')) bf.setToolTip( _('Normally, when following links in HTML files' ' calibre does it depth first, i.e. if file A links to B and ' ' C, but B links to D, the files are added in the order A, B, D, C. ' ' With this option, they will instead be added as A, B, C, D')) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() enc = sc.partition('|')[0] bfs = sc.partition('|')[-1] bf.setChecked(bfs == 'bf') sc = QLineEdit(enc, config_dialog) v.addWidget(sc) v.addWidget(bf) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() if bf.isChecked(): sc += '|bf' customize_plugin(self, sc) return config_dialog.result()
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 do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt4.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QLabel, Qt, QLineEdit, QCheckBox) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): config_dialog.resize(config_dialog.sizeHint()) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) from calibre.customize.ui import (plugin_customization, customize_plugin) help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) bf = QCheckBox(_('Add linked files in breadth first order')) bf.setToolTip(_('Normally, when following links in HTML files' ' calibre does it depth first, i.e. if file A links to B and ' ' C, but B links to D, the files are added in the order A, B, D, C. ' ' With this option, they will instead be added as A, B, C, D')) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() enc = sc.partition('|')[0] bfs = sc.partition('|')[-1] bf.setChecked(bfs == 'bf') sc = QLineEdit(enc, config_dialog) v.addWidget(sc) v.addWidget(bf) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() if bf.isChecked(): sc += '|bf' customize_plugin(self, sc) return config_dialog.result()
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.treat_as_image = QCheckBox(d) d.setMinimumWidth(600) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) d.br = b = QPushButton(_('&Browse')) b.setIcon(QIcon(I('document_open.png'))) def cf(): files = choose_files(d, 'select link file', _('Choose file'), select_only_single_file=True) if files: path = files[0] d.url.setText(path) if path and os.path.exists(path): with lopen(path, 'rb') as f: q = what(f) is_image = q in {'jpeg', 'png', 'gif'} d.treat_as_image.setChecked(is_image) b.clicked.connect(cf) d.la = la = QLabel( _('Enter a URL. If you check the "Treat the URL as an image" box ' 'then the URL will be added as an image reference instead of as ' 'a link. You can also choose to create a link to a file on ' 'your computer. ' 'Note that if you create a link to a file on your computer, it ' 'will stop working if the file is moved.')) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.setWidget(0, l.SpanningRole, la) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Treat the URL as an &image'), d.treat_as_image) l.addRow(_('Enter &name (optional):'), d.name) l.addRow(_('Choose a file on your computer:'), d.br) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) link, name, is_image = None, None, False if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode( d.name.text()).strip() is_image = d.treat_as_image.isChecked() return link, name, is_image
def pin_dialog(self, msg): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) vbox.addWidget(matrix) vbox.addLayout(ok_cancel_buttons(d)) d.setLayout(vbox) if not d.exec_(): return return str(matrix.get_value())
def link_stylesheets(self, names): s = self.categories['styles'] sheets = [ unicode(s.child(i).data(0, NAME_ROLE).toString()) for i in xrange(s.childCount()) ] if not sheets: return error_dialog( self, _('No stylesheets'), _('This book currently has no stylesheets. You must first create a stylesheet' ' before linking it.'), show=True) d = QDialog(self) d.l = l = QVBoxLayout(d) d.setLayout(l) d.setWindowTitle(_('Choose stylesheets')) d.la = la = QLabel( _('Choose the stylesheets to link. Drag and drop to re-arrange')) la.setWordWrap(True) l.addWidget(la) d.s = s = QListWidget(d) l.addWidget(s) s.setDragEnabled(True) s.setDropIndicatorShown(True) s.setDragDropMode(self.InternalMove) s.setAutoScroll(True) s.setDefaultDropAction(Qt.MoveAction) for name in sheets: i = QListWidgetItem(name, s) flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable i.setFlags(flags) i.setCheckState(Qt.Checked) d.r = r = QCheckBox(_('Remove existing links to stylesheets')) r.setChecked(tprefs['remove_existing_links_when_linking_sheets']) l.addWidget(r) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addWidget(bb) if d.exec_() == d.Accepted: tprefs['remove_existing_links_when_linking_sheets'] = r.isChecked() sheets = [ unicode(s.item(il).text()) for il in xrange(s.count()) if s.item(il).checkState() == Qt.Checked ] if sheets: self.link_stylesheets_requested.emit(names, sheets, r.isChecked())
def pin_dialog(self): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(self.message)) vbox.addWidget(matrix) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): self.response = None self.response = str(matrix.get_value()) self.done.set()
class MUEhipQTHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL('btchip_done'), self.dialog_stop) self.win.connect(win, SIGNAL('btchip_message_dialog'), self.message_dialog) self.win.connect(win, SIGNAL('btchip_auth_dialog'), self.auth_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL('btchip_done')) def show_message(self, msg): self.message = msg self.win.emit(SIGNAL('btchip_message_dialog')) def prompt_auth(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('btchip_auth_dialog')) self.done.wait() return self.response def auth_dialog(self): response = QInputDialog.getText(None, "MUEhip Authentication", self.message, QLineEdit.Password) if not response[1]: self.response = None else: self.response = str(response[0]) self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle('MUEhip') self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() def dialog_stop(self): if self.d is not None: self.d.hide() self.d = None
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.treat_as_image = QCheckBox(d) d.setMinimumWidth(600) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) d.br = b = QPushButton(_('&Browse')) b.setIcon(QIcon(I('document_open.png'))) def cf(): files = choose_files(d, 'select link file', _('Choose file'), select_only_single_file=True) if files: path = files[0] d.url.setText(path) if path and os.path.exists(path): with lopen(path, 'rb') as f: q = what(f) is_image = q in {'jpeg', 'png', 'gif'} d.treat_as_image.setChecked(is_image) b.clicked.connect(cf) d.la = la = QLabel(_( 'Enter a URL. If you check the "Treat the URL as an image" box ' 'then the URL will be added as an image reference instead of as ' 'a link. You can also choose to create a link to a file on ' 'your computer. ' 'Note that if you create a link to a file on your computer, it ' 'will stop working if the file is moved.')) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.setWidget(0, l.SpanningRole, la) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Treat the URL as an &image'), d.treat_as_image) l.addRow(_('Enter &name (optional):'), d.name) l.addRow(_('Choose a file on your computer:'), d.br) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) link, name, is_image = None, None, False if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode(d.name.text()).strip() is_image = d.treat_as_image.isChecked() return link, name, is_image
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Enter name (optional):'), d.name) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) link, name = None, None if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode(d.name.text()).strip() return link, name
class BTChipQTHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL('btchip_done'), self.dialog_stop) self.win.connect(win, SIGNAL('btchip_message_dialog'), self.message_dialog) self.win.connect(win, SIGNAL('btchip_auth_dialog'), self.auth_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL('btchip_done')) def show_message(self, msg): self.message = msg self.win.emit(SIGNAL('btchip_message_dialog')) def prompt_auth(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('btchip_auth_dialog')) self.done.wait() return self.response def auth_dialog(self): response = QInputDialog.getText(None, "Ledger Wallet Authentication", self.message, QLineEdit.Password) if not response[1]: self.response = None else: self.response = str(response[0]) self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle('Ledger') self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() def dialog_stop(self): if self.d is not None: self.d.hide() self.d = None
def ask_link(self): d = QDialog(self) d.setWindowTitle(_('Create link')) l = QFormLayout() d.setLayout(l) d.url = QLineEdit(d) d.name = QLineEdit(d) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) l.addRow(_('Enter &URL:'), d.url) l.addRow(_('Enter name (optional):'), d.name) l.addRow(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) link, name = None, None if d.exec_() == d.Accepted: link, name = unicode(d.url.text()).strip(), unicode( d.name.text()).strip() return link, name
def show_debug_info(self): info = self.device.device_debug_info() d = QDialog(self) d.l = l = QVBoxLayout() d.setLayout(l) d.v = v = QPlainTextEdit() d.setWindowTitle(self.device.get_gui_name()) v.setPlainText(info) v.setMinimumWidth(400) v.setMinimumHeight(350) l.addWidget(v) bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close) bb.accepted.connect(d.accept) bb.rejected.connect(d.reject) l.addWidget(bb) bb.addButton(_("Copy to clipboard"), bb.ActionRole) bb.clicked.connect(lambda: QApplication.clipboard().setText(v.toPlainText())) d.exec_()
def do_config(self): # Save values that need to be synced between the dialog and the # search widget. self.config['open_external'] = self.open_external.isChecked() # Create the config dialog. It's going to put two config widgets # into a QTabWidget for displaying all of the settings. d = QDialog(self) button_box = QDialogButtonBox(QDialogButtonBox.Close) v = QVBoxLayout(d) button_box.accepted.connect(d.accept) button_box.rejected.connect(d.reject) d.setWindowTitle(_('Customize get books search')) tab_widget = QTabWidget(d) v.addWidget(tab_widget) v.addWidget(button_box) chooser_config_widget = StoreChooserWidget() search_config_widget = StoreConfigWidget(self.config) tab_widget.addTab(chooser_config_widget, _('Choose stores')) tab_widget.addTab(search_config_widget, _('Configure search')) # Restore dialog state. geometry = self.config.get('config_dialog_geometry', None) if geometry: d.restoreGeometry(geometry) else: d.resize(800, 600) tab_index = self.config.get('config_dialog_tab_index', 0) tab_index = min(tab_index, tab_widget.count() - 1) tab_widget.setCurrentIndex(tab_index) d.exec_() # Save dialog state. self.config['config_dialog_geometry'] = bytearray(d.saveGeometry()) self.config['config_dialog_tab_index'] = tab_widget.currentIndex() search_config_widget.save_settings() self.config_changed() self.gui.load_store_plugins() self.setup_store_checks()
def show_debug_info(self): info = self.device.device_debug_info() d = QDialog(self) d.l = l = QVBoxLayout() d.setLayout(l) d.v = v = QPlainTextEdit() d.setWindowTitle(self.device.get_gui_name()) v.setPlainText(info) v.setMinimumWidth(400) v.setMinimumHeight(350) l.addWidget(v) bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close) bb.accepted.connect(d.accept) bb.rejected.connect(d.reject) l.addWidget(bb) bb.addButton(_('Copy to clipboard'), bb.ActionRole) bb.clicked.connect( lambda: QApplication.clipboard().setText(v.toPlainText())) d.exec_()
def customize_remove_unused_css(name, parent, ans): d = QDialog(parent) d.l = l = QVBoxLayout() d.setLayout(d.l) d.setWindowTitle(_('Remove unused CSS')) d.la = la = QLabel(_( 'This will remove all CSS rules that do not match any actual content. You' ' can also have it automatically remove any class attributes from the HTML' ' that do not match any CSS rules, by using the check box below:')) la.setWordWrap(True), l.addWidget(la) d.c = c = QCheckBox(_('Remove unused &class attributes')) c.setChecked(tprefs['remove_unused_classes']) l.addWidget(c) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) if d.exec_() != d.Accepted: raise Abort() ans['remove_unused_classes'] = tprefs['remove_unused_classes'] = c.isChecked()
class DongleWaitingDialog(QThread): def __init__(self): QThread.__init__(self) self.waiting = False def start(self, message): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle("Please Wait") self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() if not self.waiting: self.waiting = True self.d.connect(waitDialog, SIGNAL("dongle_done"), self.stop) def stop(self): self.d.hide() self.waiting = False
def customize_remove_unused_css(name, parent, ans): d = QDialog(parent) d.l = l = QVBoxLayout() d.setLayout(d.l) d.setWindowTitle(_('Remove unused CSS')) d.la = la = QLabel( _('This will remove all CSS rules that do not match any actual content. You' ' can also have it automatically remove any class attributes from the HTML' ' that do not match any CSS rules, by using the check box below:')) la.setWordWrap(True), l.addWidget(la) d.c = c = QCheckBox(_('Remove unused &class attributes')) c.setChecked(tprefs['remove_unused_classes']) l.addWidget(c) d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) d.l.addWidget(d.bb) d.bb.rejected.connect(d.reject) d.bb.accepted.connect(d.accept) if d.exec_() != d.Accepted: raise Abort() ans['remove_unused_classes'] = tprefs[ 'remove_unused_classes'] = c.isChecked()
class TrezorWaitingDialog(QThread): def __init__(self): QThread.__init__(self) self.waiting = False def start(self, message): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle('Please Check Trezor Device') self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() if not self.waiting: self.waiting = True self.d.connect(twd, SIGNAL('trezor_done'), self.stop) def stop(self): self.d.hide() self.waiting = False
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()
class KeepKeyQtHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL('keepkey_done'), self.dialog_stop) self.win.connect(win, SIGNAL('message_dialog'), self.message_dialog) self.win.connect(win, SIGNAL('pin_dialog'), self.pin_dialog) self.win.connect(win, SIGNAL('passphrase_dialog'), self.passphrase_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL('keepkey_done')) def show_message(self, msg_code, msg, client): self.messsage_code = msg_code self.message = msg self.client = client self.win.emit(SIGNAL('message_dialog')) def get_pin(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('pin_dialog')) self.done.wait() return self.response def get_passphrase(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('passphrase_dialog')) self.done.wait() return self.passphrase def pin_dialog(self): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(self.message)) vbox.addWidget(matrix) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): self.response = None self.response = str(matrix.get_value()) self.done.set() def passphrase_dialog(self): if type(self.win) is ElectrumWindow: passphrase = self.win.password_dialog( _("Please enter your KeepKey passphrase")) self.passphrase = unicodedata.normalize( 'NFKD', unicode(passphrase)) if passphrase else '' else: assert type(self.win) is InstallWizard from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog d = QDialog() d.setModal(1) d.setLayout(make_password_dialog(d, None, self.message, False)) confirmed, p, passphrase = run_password_dialog(d, None, None) if not confirmed: QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK')) self.passphrase = None else: self.passphrase = unicodedata.normalize( 'NFKD', unicode(passphrase)) if passphrase else '' self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle('Please Check KeepKey Device') self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) if self.messsage_code in (3, 8): vbox.addLayout(Buttons(CancelButton(self.d))) self.d.connect(self.d, SIGNAL('rejected()'), self.client.cancel) self.d.show() def dialog_stop(self): self.d.hide()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt4.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \ QLabel, Qt, QLineEdit from calibre.gui2 import gprefs prefname = 'plugin config dialog:' + self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: config_dialog.restoreGeometry(geom) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) try: config_widget = self.config_widget() except NotImplementedError: config_widget = None if isinstance(config_widget, tuple): from calibre.gui2 import warning_dialog warning_dialog(parent, _('Cannot configure'), config_widget[0], det_msg=config_widget[1], show=True) return False if config_widget is not None: v.addWidget(config_widget) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: if hasattr(config_widget, 'validate'): if config_widget.validate(): self.save_settings(config_widget) else: self.save_settings(config_widget) else: from calibre.customize.ui import plugin_customization, \ customize_plugin help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() sc = QLineEdit(sc, config_dialog) v.addWidget(sc) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() customize_plugin(self, sc) geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
def ask_about_cc_mismatch(gui, db, newdb, missing_cols, incompatible_cols): # {{{ source_metadata = db.field_metadata.custom_field_metadata(include_composites=True) ndbname = os.path.basename(newdb.library_path) d = QDialog(gui) d.setWindowTitle(_('Different custom columns')) l = QFormLayout() tl = QVBoxLayout() d.setLayout(tl) d.s = QScrollArea(d) tl.addWidget(d.s) d.w = QWidget(d) d.s.setWidget(d.w) d.s.setWidgetResizable(True) d.w.setLayout(l) d.setMinimumWidth(600) d.setMinimumHeight(500) d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) msg = _('The custom columns in the <i>{0}</i> library are different from the ' 'custom columns in the <i>{1}</i> library. As a result, some metadata might not be copied.').format( os.path.basename(db.library_path), ndbname) d.la = la = QLabel(msg) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.addRow(la) if incompatible_cols: la = d.la2 = QLabel(_('The following columns are incompatible - they have the same name' ' but different data types. They will be ignored: ') + ', '.join(sorted(incompatible_cols, key=sort_key))) la.setWordWrap(True) la.setStyleSheet('QLabel { margin-bottom: 1.5ex }') l.addRow(la) missing_widgets = [] if missing_cols: la = d.la3 = QLabel(_('The following columns are missing in the <i>{0}</i> library.' ' You can choose to add them automatically below.').format( ndbname)) la.setWordWrap(True) l.addRow(la) for k in missing_cols: widgets = (k, QCheckBox(_('Add to the %s library') % ndbname)) l.addRow(QLabel(k), widgets[1]) missing_widgets.append(widgets) d.la4 = la = QLabel(_('This warning is only shown once per library, per session')) la.setWordWrap(True) tl.addWidget(la) tl.addWidget(d.bb) d.bb.accepted.connect(d.accept) d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) if d.exec_() == d.Accepted: for k, cb in missing_widgets: if cb.isChecked(): col_meta = source_metadata[k] newdb.create_custom_column( col_meta['label'], col_meta['name'], col_meta['datatype'], len(col_meta['is_multiple']) > 0, col_meta['is_editable'], col_meta['display']) return True return False
class TrezorQtHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL("trezor_done"), self.dialog_stop) self.win.connect(win, SIGNAL("message_dialog"), self.message_dialog) self.win.connect(win, SIGNAL("pin_dialog"), self.pin_dialog) self.win.connect(win, SIGNAL("passphrase_dialog"), self.passphrase_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL("trezor_done")) def show_message(self, msg): self.message = msg self.win.emit(SIGNAL("message_dialog")) def get_pin(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL("pin_dialog")) self.done.wait() return self.response def get_passphrase(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL("passphrase_dialog")) self.done.wait() return self.passphrase def pin_dialog(self): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(self.message)) vbox.addWidget(matrix) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): self.response = None self.response = str(matrix.get_value()) self.done.set() def passphrase_dialog(self): from electrum_boli_gui.qt.password_dialog import make_password_dialog, run_password_dialog d = QDialog() d.setModal(1) d.setLayout(make_password_dialog(d, None, self.message, False)) confirmed, p, passphrase = run_password_dialog(d, None, None) if not confirmed: QMessageBox.critical(None, _("Error"), _("Password request canceled"), _("OK")) self.passphrase = None else: if passphrase is None: passphrase = "" # Even blank string is valid Trezor passphrase self.passphrase = unicodedata.normalize("NFKD", unicode(passphrase)) self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle("Please Check Trezor Device") self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() def dialog_stop(self): self.d.hide()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt4.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \ QLabel, Qt, QLineEdit from calibre.gui2 import gprefs prefname = 'plugin config dialog:'+self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: config_dialog.restoreGeometry(geom) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) try: config_widget = self.config_widget() except NotImplementedError: config_widget = None if isinstance(config_widget, tuple): from calibre.gui2 import warning_dialog warning_dialog(parent, _('Cannot configure'), config_widget[0], det_msg=config_widget[1], show=True) return False if config_widget is not None: v.addWidget(config_widget) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: if hasattr(config_widget, 'validate'): if config_widget.validate(): self.save_settings(config_widget) else: self.save_settings(config_widget) else: from calibre.customize.ui import plugin_customization, \ customize_plugin help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() sc = QLineEdit(sc, config_dialog) v.addWidget(sc) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() customize_plugin(self, sc) geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
class KeepKeyQtHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL("keepkey_done"), self.dialog_stop) self.win.connect(win, SIGNAL("message_dialog"), self.message_dialog) self.win.connect(win, SIGNAL("pin_dialog"), self.pin_dialog) self.win.connect(win, SIGNAL("passphrase_dialog"), self.passphrase_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL("keepkey_done")) def show_message(self, msg_code, msg, client): self.messsage_code = msg_code self.message = msg self.client = client self.win.emit(SIGNAL("message_dialog")) def get_pin(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL("pin_dialog")) self.done.wait() return self.response def get_passphrase(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL("passphrase_dialog")) self.done.wait() return self.passphrase def pin_dialog(self): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(self.message)) vbox.addWidget(matrix) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): self.response = None self.response = str(matrix.get_value()) self.done.set() def passphrase_dialog(self): if type(self.win) is ElectrumWindow: passphrase = self.win.password_dialog(_("Please enter your KeepKey passphrase")) self.passphrase = unicodedata.normalize("NFKD", unicode(passphrase)) if passphrase else "" else: assert type(self.win) is InstallWizard from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog d = QDialog() d.setModal(1) d.setLayout(make_password_dialog(d, None, self.message, False)) confirmed, p, passphrase = run_password_dialog(d, None, None) if not confirmed: QMessageBox.critical(None, _("Error"), _("Password request canceled"), _("OK")) self.passphrase = None else: self.passphrase = unicodedata.normalize("NFKD", unicode(passphrase)) if passphrase else "" self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle("Please Check KeepKey Device") self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) if self.messsage_code in (3, 8): vbox.addLayout(Buttons(CancelButton(self.d))) self.d.connect(self.d, SIGNAL("rejected()"), self.client.cancel) self.d.show() def dialog_stop(self): self.d.hide()
class TrezorQtHandler: def __init__(self, win): self.win = win self.win.connect(win, SIGNAL('trezor_done'), self.dialog_stop) self.win.connect(win, SIGNAL('message_dialog'), self.message_dialog) self.win.connect(win, SIGNAL('pin_dialog'), self.pin_dialog) self.win.connect(win, SIGNAL('passphrase_dialog'), self.passphrase_dialog) self.done = threading.Event() def stop(self): self.win.emit(SIGNAL('trezor_done')) def show_message(self, msg): self.message = msg self.win.emit(SIGNAL('message_dialog')) def get_pin(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('pin_dialog')) self.done.wait() return self.response def get_passphrase(self, msg): self.done.clear() self.message = msg self.win.emit(SIGNAL('passphrase_dialog')) self.done.wait() return self.passphrase def pin_dialog(self): d = QDialog(None) d.setModal(1) d.setWindowTitle(_("Enter PIN")) d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) matrix = PinMatrixWidget() vbox = QVBoxLayout() vbox.addWidget(QLabel(self.message)) vbox.addWidget(matrix) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): self.response = None self.response = str(matrix.get_value()) self.done.set() def passphrase_dialog(self): from electrum_oracoin_gui.qt.password_dialog import make_password_dialog, run_password_dialog d = QDialog() d.setModal(1) d.setLayout(make_password_dialog(d, None, self.message, False)) confirmed, p, passphrase = run_password_dialog(d, None, None) if not confirmed: QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK')) self.passphrase = None else: if passphrase is None: passphrase = '' # Even blank string is valid Trezor passphrase self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) self.done.set() def message_dialog(self): self.d = QDialog() self.d.setModal(1) self.d.setWindowTitle('Please Check Trezor Device') self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(self.message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) self.d.show() def dialog_stop(self): self.d.hide()