def set_details(self, msg): if not msg: msg = '' if Qt.mightBeRichText(msg): self.det_msg.setHtml(msg) else: self.det_msg.setPlainText(msg) self.det_msg_toggle.setText(self.show_det_msg) self.det_msg_toggle.setVisible(bool(msg)) self.det_msg.setVisible(False) self.resize_needed.emit()
def __init__(self, parent, get_option, get_help, db=None, book_id=None): # Dummy attributes to fool the Widget() option handler code. We handle # everything in our *handler methods. for i in range(1, 4): x = 'sr%d_' % i for y in ('search', 'replace'): z = x + y setattr(self, 'opt_' + z, z) self.opt_search_replace = 'search_replace' Widget.__init__(self, parent, OPTIONS['pipe']['search_and_replace']) self.db, self.book_id = db, book_id self.sr_search.set_msg(_('&Search regular expression:')) self.sr_search.set_book_id(book_id) self.sr_search.set_db(db) self.sr_search.doc_update.connect(self.update_doc) proto = QTableWidgetItem() proto.setFlags( Qt.ItemFlags(Qt.ItemFlag.ItemIsSelectable + Qt.ItemFlag.ItemIsEnabled)) self.search_replace.setItemPrototype(proto) self.search_replace.setColumnCount(2) self.search_replace.setColumnWidth(0, 320) self.search_replace.setColumnWidth(1, 320) self.search_replace.setHorizontalHeaderLabels( [_('Search regular expression'), _('Replacement text')]) self.sr_add.clicked.connect(self.sr_add_clicked) self.sr_change.clicked.connect(self.sr_change_clicked) self.sr_remove.clicked.connect(self.sr_remove_clicked) self.sr_load.clicked.connect(self.sr_load_clicked) self.sr_save.clicked.connect(self.sr_save_clicked) self.sr_up.clicked.connect(self.sr_up_clicked) self.sr_down.clicked.connect(self.sr_down_clicked) self.search_replace.currentCellChanged.connect( self.sr_currentCellChanged) self.initialize_options(get_option, get_help, db, book_id) try: self.rh_label.setText( self.rh_label.text() % localize_user_manual_link( 'https://manual.calibre-ebook.com/regexp.html')) except TypeError: pass # link already localized
def expandingDirections(self): return Qt.Orientations(0)
def __init__(self, type_, title, msg, det_msg='', q_icon=None, show_copy_button=True, parent=None, default_yes=True, yes_text=None, no_text=None, yes_icon=None, no_icon=None, add_abort_button=False, only_copy_details=False): QDialog.__init__(self, parent) self.only_copy_details = only_copy_details self.aborted = False if q_icon is None: icon = { self.ERROR: 'error', self.WARNING: 'warning', self.INFO: 'information', self.QUESTION: 'question', }[type_] icon = 'dialog_%s.png' % icon self.icon = QIcon(I(icon)) else: self.icon = q_icon if isinstance(q_icon, QIcon) else QIcon( I(q_icon)) self.setup_ui() self.setWindowTitle(title) self.setWindowIcon(self.icon) self.icon_widget.set_icon(self.icon) self.msg.setText(msg) if det_msg and Qt.mightBeRichText(det_msg): self.det_msg.setHtml(det_msg) else: self.det_msg.setPlainText(det_msg) self.det_msg.setVisible(False) self.toggle_checkbox.setVisible(False) if show_copy_button: self.ctc_button = self.bb.addButton( _('&Copy to clipboard'), QDialogButtonBox.ButtonRole.ActionRole) self.ctc_button.clicked.connect(self.copy_to_clipboard) self.show_det_msg = _('Show &details') self.hide_det_msg = _('Hide &details') self.det_msg_toggle = self.bb.addButton( self.show_det_msg, QDialogButtonBox.ButtonRole.ActionRole) self.det_msg_toggle.clicked.connect(self.toggle_det_msg) self.det_msg_toggle.setToolTip( _('Show detailed information about this error')) self.copy_action = QAction(self) self.addAction(self.copy_action) self.copy_action.setShortcuts(QKeySequence.StandardKey.Copy) self.copy_action.triggered.connect(self.copy_to_clipboard) self.is_question = type_ == self.QUESTION if self.is_question: self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes | QDialogButtonBox.StandardButton.No) self.bb.button(QDialogButtonBox.StandardButton.Yes if default_yes else QDialogButtonBox.StandardButton.No).setDefault( True) self.default_yes = default_yes if yes_text is not None: self.bb.button( QDialogButtonBox.StandardButton.Yes).setText(yes_text) if no_text is not None: self.bb.button( QDialogButtonBox.StandardButton.No).setText(no_text) if yes_icon is not None: self.bb.button(QDialogButtonBox.StandardButton.Yes).setIcon( yes_icon if isinstance(yes_icon, QIcon ) else QIcon(I(yes_icon))) if no_icon is not None: self.bb.button(QDialogButtonBox.StandardButton.No).setIcon( no_icon if isinstance(no_icon, QIcon) else QIcon(I(no_icon) )) else: self.bb.button(QDialogButtonBox.StandardButton.Ok).setDefault(True) if add_abort_button: self.bb.addButton( QDialogButtonBox.StandardButton.Abort).clicked.connect( self.on_abort) if not det_msg: self.det_msg_toggle.setVisible(False) self.resize_needed.connect(self.do_resize, type=Qt.ConnectionType.QueuedConnection) self.do_resize()