def __init__(self, parent=None, add_clear_action=True, as_url=None): QComboBox.__init__(self, parent) self.line_edit = SearchLineEdit(self) self.line_edit.as_url = as_url self.setLineEdit(self.line_edit) self.line_edit.clear_history.connect(self.clear_history) if add_clear_action: self.lineEdit().setClearButtonEnabled(True) ac = self.findChild(QAction, QT_HIDDEN_CLEAR_ACTION) if ac is not None: ac.triggered.connect(self.clear_clicked) c = self.line_edit.completer() c.setCompletionMode(QCompleter.CompletionMode.PopupCompletion) c.highlighted[native_string_type].connect(self.completer_used) self.line_edit.key_pressed.connect(self.key_pressed, type=Qt.ConnectionType.DirectConnection) # QueuedConnection as workaround for https://bugreports.qt-project.org/browse/QTBUG-40807 self.activated[native_string_type].connect(self.history_selected, type=Qt.ConnectionType.QueuedConnection) self.setEditable(True) self.as_you_type = True self.timer = QTimer() self.timer.setSingleShot(True) self.timer.timeout.connect(self.timer_event, type=Qt.ConnectionType.QueuedConnection) self.setInsertPolicy(QComboBox.InsertPolicy.NoInsert) self.setMaxCount(self.MAX_COUNT) self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) self.setMinimumContentsLength(25) self._in_a_search = False self.tool_tip_text = self.toolTip()
def choices_widget(self, name, choices, fallback_val, none_val, prefs=None): prefs = prefs or tprefs widget = QComboBox(self) widget.currentIndexChanged[int].connect(self.emit_changed) for key, human in sorted( iteritems(choices), key=lambda key_human: key_human[1] or key_human[0]): widget.addItem(human or key, key) def getter(w): ans = str(w.itemData(w.currentIndex()) or '') return {none_val: None}.get(ans, ans) def setter(w, val): val = {None: none_val}.get(val, val) idx = w.findData(val, flags=Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive) if idx == -1: idx = w.findData(fallback_val, flags=Qt.MatchFlag.MatchFixedString | Qt.MatchFlag.MatchCaseSensitive) w.setCurrentIndex(idx) return self(name, widget=widget, getter=getter, setter=setter, prefs=prefs)
def __init__(self, *args): QComboBox.__init__(self, *args) self.setEditable(True) self.setInsertPolicy(QComboBox.InsertPolicy.NoInsert) self.setMaxCount(10) self.setClearButtonEnabled = self.lineEdit().setClearButtonEnabled self.textChanged = self.editTextChanged
def __init__(self, parent, emphasize=False): QComboBox.__init__(self) self.addItems([ _('Current file'), _('All text files'), _('Selected files'), _('Open files') ]) self.setToolTip('<style>dd {margin-bottom: 1.5ex}</style>' + _(''' Where to search/replace: <dl> <dt><b>Current file</b></dt> <dd>Search only inside the currently opened file</dd> <dt><b>All text files</b></dt> <dd>Search in all text (HTML) files</dd> <dt><b>Selected files</b></dt> <dd>Search in the files currently selected in the File browser</dd> <dt><b>Open files</b></dt> <dd>Search in the files currently open in the editor</dd> </dl>''')) self.emphasize = emphasize self.ofont = QFont(self.font()) if emphasize: f = self.emph_font = QFont(self.ofont) f.setBold(True), f.setItalic(True) self.setFont(f)
def __init__(self, parent=None): QComboBox.__init__(self, parent) self.setEditable(True) self.setLineEdit(EnLineEdit(self)) for item in self.ENCODINGS: self.addItem(item)
def __init__(self, name, layout): QComboBox.__init__(self) self.setEditable(False) opt = options[name] self.choices = opt.choices tuple(map(self.addItem, opt.choices)) self.currentIndexChanged.connect(self.changed_signal.emit) init_opt(self, opt, layout)
def __init__(self, parent): QComboBox.__init__(self, parent) items = [ _('All'), _('Installed'), _('Update available'), _('Not installed') ] self.addItems(items)
def setup_ui(self): self.l = l = QVBoxLayout(self) self.setLayout(l) self.tl = tl = QFormLayout() self.semantic_type = QComboBox(self) for key, val in iteritems(self.all_types): self.semantic_type.addItem(val, key) tl.addRow(_('Type of &semantics:'), self.semantic_type) self.target = t = QLineEdit(self) t.setPlaceholderText(_('The destination (href) for the link')) tl.addRow(_('&Target:'), t) l.addLayout(tl) self.hline = hl = QFrame(self) hl.setFrameStyle(QFrame.Shape.HLine) l.addWidget(hl) self.h = h = QHBoxLayout() l.addLayout(h) names = [n for n, linear in self.container.spine_names] fn, f = create_filterable_names_list(names, filter_text=_('Filter files'), parent=self) self.file_names, self.file_names_filter = fn, f fn.selectionModel().selectionChanged.connect( self.selected_file_changed) self.fnl = fnl = QVBoxLayout() self.la1 = la = QLabel(_('Choose a &file:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(0, 2) fn, f = create_filterable_names_list([], filter_text=_('Filter locations'), parent=self) self.anchor_names, self.anchor_names_filter = fn, f fn.selectionModel().selectionChanged.connect(self.update_target) fn.doubleClicked.connect(self.accept, type=Qt.ConnectionType.QueuedConnection) self.anl = fnl = QVBoxLayout() self.la2 = la = QLabel(_('Choose a &location (anchor) in the file:')) la.setBuddy(fn) fnl.addWidget(la), fnl.addWidget(f), fnl.addWidget(fn) h.addLayout(fnl), h.setStretch(1, 1) self.bb.addButton(QDialogButtonBox.StandardButton.Help) self.bb.helpRequested.connect(self.help_requested) l.addWidget(self.bb) self.semantic_type_changed() self.semantic_type.currentIndexChanged.connect( self.semantic_type_changed) self.target.textChanged.connect(self.target_text_changed)
def test(): w = QWidget() l = FlowLayout(w) la = QLabel('Some text in a label') l.addWidget(la) c = QCheckBox('A checkboxy widget') l.addWidget(c) cb = QComboBox() cb.addItems(['Item one']) l.addWidget(cb) return w
def __init__(self, parent): QComboBox.__init__(self, parent) self.addItems([_('Normal'), _('Regex')]) self.setToolTip('<style>dd {margin-bottom: 1.5ex}</style>' + _('''Select how the search expression is interpreted <dl> <dt><b>Normal</b></dt> <dd>The search expression is treated as normal text, calibre will look for the exact text.</dd> <dt><b>Regex</b></dt> <dd>The search expression is interpreted as a regular expression. See the User Manual for more help on using regular expressions.</dd> </dl>'''))
def keyPressEvent(self, event): k = event.key() if k in (Qt.Key.Key_Enter, Qt.Key.Key_Return): return self.do_search() if k not in (Qt.Key.Key_Up, Qt.Key.Key_Down): return QComboBox.keyPressEvent(self, event) self.blockSignals(True) self.normalize_state() if k == Qt.Key.Key_Down and self.currentIndex() == 0 and not self.lineEdit().text(): self.setCurrentIndex(1), self.setCurrentIndex(0) event.accept() else: QComboBox.keyPressEvent(self, event) self.blockSignals(False)
def make_color_combobox(self, row, dex): c = QComboBox(self) c.addItem('') c.addItems(QColor.colorNames()) self.table.setCellWidget(row, 1, c) if dex >= 0: c.setCurrentIndex(dex) return c
def create_widgets(self, opt): val = self.plugin.prefs[opt.name] if opt.type == 'number': c = QSpinBox if isinstance(opt.default, numbers.Integral) else QDoubleSpinBox widget = c(self) widget.setValue(val) elif opt.type == 'string': widget = QLineEdit(self) widget.setText(val if val else '') elif opt.type == 'bool': widget = QCheckBox(opt.label, self) widget.setChecked(bool(val)) elif opt.type == 'choices': widget = QComboBox(self) items = list(iteritems(opt.choices)) items.sort(key=lambda k_v: sort_key(k_v[1])) for key, label in items: widget.addItem(label, (key)) idx = widget.findData(val) widget.setCurrentIndex(idx) widget.opt = opt widget.setToolTip(textwrap.fill(opt.desc)) self.widgets.append(widget) r = self.l.rowCount() if opt.type == 'bool': self.l.addWidget(widget, r, 0, 1, self.l.columnCount()) else: l = QLabel(opt.label) l.setToolTip(widget.toolTip()) self.memory.append(l) l.setBuddy(widget) self.l.addWidget(l, r, 0, 1, 1) self.l.addWidget(widget, r, 1, 1, 1)
def __init__(self, parent): QWidget.__init__(self, parent) l = QVBoxLayout(parent) l.addWidget(self) l.setContentsMargins(0, 0, 0, 0) l = QFormLayout(self) l.setContentsMargins(0, 0, 0, 0) l.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow) self.choices = c = QComboBox() c.setMinimumContentsLength(30) for text, data in [ (_('Search for the author on Goodreads'), 'search-goodreads'), (_('Search for the author on Amazon'), 'search-amzn'), (_('Search for the author in your calibre library'), 'search-calibre'), (_('Search for the author on Wikipedia'), 'search-wikipedia'), (_('Search for the author on Google Books'), 'search-google'), (_('Search for the book on Goodreads'), 'search-goodreads-book'), (_('Search for the book on Amazon'), 'search-amzn-book'), (_('Search for the book on Google Books'), 'search-google-book'), (_('Use a custom search URL'), 'url'), ]: c.addItem(text, data) l.addRow(_('Clicking on &author names should:'), c) self.custom_url = u = QLineEdit(self) u.setToolTip(_( 'Enter the URL to search. It should contain the string {0}' '\nwhich will be replaced by the author name. For example,' '\n{1}').format('{author}', 'https://en.wikipedia.org/w/index.php?search={author}')) u.textChanged.connect(self.changed_signal) u.setPlaceholderText(_('Enter the URL')) c.currentIndexChanged.connect(self.current_changed) l.addRow(u) self.current_changed() c.currentIndexChanged.connect(self.changed_signal)
def setupUi(self, *a): self.l = l = QFormLayout(self) self.opt_docx_page_size = QComboBox(self) l.addRow(_('Paper si&ze:'), self.opt_docx_page_size) self.opt_docx_custom_page_size = w = QLineEdit(self) w.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) l.addRow(_('&Custom size:'), w) for i, text in enumerate( (_('Page &left margin'), _('Page &top margin'), _('Page &right margin'), _('Page &bottom margin'))): m = 'left top right bottom'.split()[i] w = QDoubleSpinBox(self) w.setRange(-100, 500), w.setSuffix(' pt'), w.setDecimals(1) setattr(self, 'opt_docx_page_margin_' + m, w) l.addRow(text + ':', w) self.opt_docx_no_toc = QCheckBox( _('Do not insert the &Table of Contents as a page at the start of the document' )) l.addRow(self.opt_docx_no_toc) self.opt_docx_no_cover = QCheckBox( _('Do not insert &cover as image at start of document')) l.addRow(self.opt_docx_no_cover) self.opt_preserve_cover_aspect_ratio = QCheckBox( _('Preserve the aspect ratio of the image inserted as cover')) l.addRow(self.opt_preserve_cover_aspect_ratio)
def extra_bottom_widget(self): self.scope_cb = cb = QComboBox() cb.addItem(_('Current HTML file'), 'current') cb.addItem(_('All HTML files'), 'all') cb.addItem(_('Open HTML files'), 'open') cb.addItem(_('Selected HTML files'), 'selected') return cb
def __init__(self, parent=None, is_half_star=False): QComboBox.__init__(self, parent) self.addItem(_('Not rated')) if is_half_star: [self.addItem(stars(x, True)) for x in range(1, 11)] else: [self.addItem(stars(x)) for x in (2, 4, 6, 8, 10)] self.rating_font = QFont(rating_font()) self.undo_stack = QUndoStack(self) self.undo, self.redo = self.undo_stack.undo, self.undo_stack.redo self.allow_undo = False self.is_half_star = is_half_star self.delegate = RatingItemDelegate(self) self.view().setItemDelegate(self.delegate) self.view().setStyleSheet('QListView { background: palette(window) }\nQListView::item { padding: 6px }') self.setMaxVisibleItems(self.count()) self.currentIndexChanged.connect(self.update_font)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QVBoxLayout(self) self.h = h = QHBoxLayout() self.la = la = QLabel(self.MSG) la.setWordWrap(True) l.addWidget(la) l.addLayout(h) self.action = a = QComboBox(self) h.addWidget(a) for action, text in iteritems(self.ACTION_MAP): a.addItem(text, action) a.currentIndexChanged.connect(self.update_state) self.la1 = la = QLabel('\xa0' + self.SUBJECT + '\xa0') h.addWidget(la) self.match_type = q = QComboBox(self) h.addWidget(q) for action, text in iteritems(self.MATCH_TYPE_MAP): q.addItem(text, action) q.currentIndexChanged.connect(self.update_state) self.la2 = la = QLabel(':\xa0') h.addWidget(la) self.query = q = QueryEdit(self) h.addWidget(q) self.tag_editor_button = b = QToolButton(self) b.setIcon(QIcon(I('chapters.png'))) b.setToolTip(_('Edit the list of tags with the Tag editor')) h.addWidget(b), b.clicked.connect(self.edit_tags) b.setVisible(self.can_use_tag_editor) self.h2 = h = QHBoxLayout() l.addLayout(h) self.la3 = la = QLabel(self.REPLACE_TEXT + '\xa0') h.addWidget(la) self.replace = r = QLineEdit(self) h.addWidget(r) self.regex_help = la = QLabel( '<p>' + self.REGEXP_HELP_TEXT % localize_user_manual_link( 'https://manual.calibre-ebook.com/regexp.html')) la.setOpenExternalLinks(True) la.setWordWrap(True) l.addWidget(la) la.setVisible(False) l.addStretch(10) self.la3.setVisible(False), self.replace.setVisible(False) self.update_state()
def setup_ui(self): self.block_show = False self.properties = [] self.l = l = QVBoxLayout(self) self.setLayout(l) h = QHBoxLayout() l.addLayout(h) self.la = la = QLabel(_('&Edit theme:')) h.addWidget(la) self.theme = t = QComboBox(self) la.setBuddy(t) t.addItems(sorted(custom_theme_names())) t.setMinimumWidth(200) if t.count() > 0: t.setCurrentIndex(0) t.currentIndexChanged[int].connect(self.show_theme) h.addWidget(t) self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add &new theme'), self) b.clicked.connect(self.create_new_theme) h.addWidget(b) self.remove_button = b = QPushButton(QIcon(I('minus.png')), _('&Remove theme'), self) b.clicked.connect(self.remove_theme) h.addWidget(b) h.addStretch(1) self.scroll = s = QScrollArea(self) self.w = w = QWidget(self) s.setWidget(w), s.setWidgetResizable(True) self.cl = cl = QVBoxLayout() w.setLayout(cl) from calibre.gui2.tweak_book.editor.text import TextEdit self.preview = p = TextEdit(self, expected_geometry=(73, 50)) p.load_text( HELP_TEXT.format(*[ '<b>%s</b>' % x for x in ('Normal', 'Visual', 'CursorLine', 'LineNr', 'MatchParen', 'Function', 'Type', 'Statement', 'Constant', 'SpecialCharacter', 'Error', 'SpellError', 'Comment') ])) p.setMaximumWidth(p.size_hint.width() + 5) s.setMinimumWidth(600) self.splitter = sp = QSplitter(self) l.addWidget(sp) sp.addWidget(s), sp.addWidget(p) self.bb.clear() self.bb.addButton(QDialogButtonBox.StandardButton.Close) l.addWidget(self.bb) if self.theme.count() > 0: self.show_theme()
def __init__(self, parent): self.restrict_to_book_ids = frozenset() QWidget.__init__(self, parent) v = QVBoxLayout(self) v.setContentsMargins(0, 0, 0, 0) h = QHBoxLayout() h.setContentsMargins(0, 0, 0, 0) v.addLayout(h) self.rla = QLabel(_('Restrict to') + ': ') h.addWidget(self.rla) la = QLabel(_('Type:')) h.addWidget(la) self.types_box = tb = QComboBox(self) tb.la = la tb.currentIndexChanged.connect(self.restrictions_changed) connect_lambda( tb.currentIndexChanged, tb, lambda tb: gprefs.set( 'browse_annots_restrict_to_type', tb.currentData())) la.setBuddy(tb) tb.setToolTip(_('Show only annotations of the specified type')) h.addWidget(tb) la = QLabel(_('User:'******'browse_annots_restrict_to_user', ub.currentData())) la.setBuddy(ub) ub.setToolTip(_('Show only annotations created by the specified user')) h.addWidget(ub) h.addStretch(10) h = QHBoxLayout() self.restrict_to_books_cb = cb = QCheckBox('') self.update_book_restrictions_text() cb.setToolTip( _('Only show annotations from books that have been selected in the calibre library' )) cb.setChecked( bool(gprefs.get('show_annots_from_selected_books_only', False))) cb.stateChanged.connect(self.show_only_selected_changed) h.addWidget(cb) v.addLayout(h)
def __init__(self, parent=None): QComboBox.__init__(self, parent) self.line_edit = SearchLineEdit(self) self.setLineEdit(self.line_edit) self.line_edit.key_pressed.connect(self.key_pressed, type=Qt.ConnectionType.DirectConnection) self.activated[native_string_type].connect(self.saved_search_selected) # Turn off auto-completion so that it doesn't interfere with typing # names of new searches. completer = QCompleter(self) self.setCompleter(completer) self.setEditable(True) self.setMaxVisibleItems(25) self.setInsertPolicy(QComboBox.InsertPolicy.NoInsert) self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) self.setMinimumContentsLength(25) self.tool_tip_text = self.toolTip()
def __init__(self, parent): QWidget.__init__(self, parent) self.is_visible = False self.selected_text = '' self.current_query = '' self.current_source = '' self.l = l = QVBoxLayout(self) self.h = h = QHBoxLayout() l.addLayout(h) self.debounce_timer = t = QTimer(self) t.setInterval(150), t.timeout.connect(self.update_query) self.source_box = sb = QComboBox(self) self.label = la = QLabel(_('Lookup &in:')) h.addWidget(la), h.addWidget(sb), la.setBuddy(sb) self.view = View(self) self.view.inspect_element.connect(self.show_devtools) self._page = Page(create_profile(), self.view) apply_font_settings(self._page) secure_webengine(self._page, for_viewer=True) self.view.setPage(self._page) l.addWidget(self.view) self.populate_sources() self.source_box.currentIndexChanged.connect(self.source_changed) self.view.setHtml('<p>' + _('Double click on a word in the book\'s text' ' to look it up.')) self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add sources')) b.setToolTip(_('Add more sources at which to lookup words')) b.clicked.connect(self.add_sources) self.refresh_button = rb = QPushButton(QIcon(I('view-refresh.png')), _('Refresh')) rb.setToolTip( _('Refresh the result to match the currently selected text')) rb.clicked.connect(self.update_query) h = QHBoxLayout() l.addLayout(h) h.addWidget(b), h.addWidget(rb) self.auto_update_query = a = QCheckBox(_('Update on selection change'), self) self.disallow_auto_update = False a.setToolTip( textwrap.fill( _('Automatically update the displayed result when selected text in the book changes. With this disabled' ' the lookup is changed only when clicking the Refresh button.' ))) a.setChecked(vprefs['auto_update_lookup']) a.stateChanged.connect(self.auto_update_state_changed) l.addWidget(a) self.update_refresh_button_status() set_sync_override.instance = self
def keyPressEvent(self, ev): if ev == QKeySequence.StandardKey.Undo: self.undo() return ev.accept() if ev == QKeySequence.StandardKey.Redo: self.redo() return ev.accept() k = ev.key() num = {getattr(Qt, 'Key_%d' % i): i for i in range(6)}.get(k) if num is None: return QComboBox.keyPressEvent(self, ev) ev.accept() if self.is_half_star: num *= 2 self.setCurrentIndex(num)
def setup_ui(self): self.l = l = QFormLayout(self) self.setLayout(l) self._name = n = QLineEdit(self) l.addRow(_('&Name of custom theme:'), n) self.base = b = QComboBox(self) b.addItems(sorted(builtin_theme_names())) l.addRow(_('&Builtin theme to base on:'), b) idx = b.findText(tprefs['editor_theme'] or default_theme()) if idx == -1: idx = b.findText(default_theme()) b.setCurrentIndex(idx) l.addRow(self.bb)
def ins_button_clicked(self): row = self.table.currentRow() if row < 0: error_dialog(self, _('Select a cell'), _('Select a cell before clicking the button'), show=True) return self.table.insertRow(row) self.table.setItem(row, 0, QTableWidgetItem()) c = QComboBox(self) c.addItem('') c.addItems(QColor.colorNames()) self.table.setCellWidget(row, 1, c)
def __init__(self, tts_client, initial_backend_settings=None, parent=None): QWidget.__init__(self, parent) self.l = l = QFormLayout(self) self.tts_client = tts_client with BusyCursor(): self.voice_data = self.tts_client.get_voice_data() self.default_system_rate = self.tts_client.default_system_rate self.all_sound_outputs = self.tts_client.get_sound_outputs() self.speed = s = QSlider(Qt.Orientation.Horizontal, self) s.setMinimumWidth(200) l.addRow(_('&Speed of speech (words per minute):'), s) s.setRange(self.tts_client.min_rate, self.tts_client.max_rate) s.setSingleStep(1) s.setPageStep(2) self.voices = v = QTableView(self) self.voices_model = VoicesModel(self.voice_data, parent=v) self.proxy_model = p = QSortFilterProxyModel(self) p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) p.setSourceModel(self.voices_model) v.setModel(p) v.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) v.setSortingEnabled(True) v.horizontalHeader().resizeSection( 0, QFontMetrics(self.font()).averageCharWidth() * 25) v.horizontalHeader().resizeSection( 1, QFontMetrics(self.font()).averageCharWidth() * 30) v.verticalHeader().close() v.verticalHeader().close() v.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) v.sortByColumn(0, Qt.SortOrder.AscendingOrder) l.addRow(v) self.sound_outputs = so = QComboBox(self) so.addItem(_('System default'), '') for x in self.all_sound_outputs: so.addItem(x.get('description') or x['id'], x['id']) l.addRow(_('Sound output:'), so) self.backend_settings = initial_backend_settings or {}
def setup_ui(self): from calibre.gui2.tweak_book.templates import DEFAULT_TEMPLATES from calibre.gui2.tweak_book.editor.text import TextEdit # Cannot use QFormLayout as it does not play nice with TextEdit on windows self.l = l = QVBoxLayout(self) self.syntaxes = s = QComboBox(self) s.addItems(sorted(DEFAULT_TEMPLATES)) s.setCurrentIndex(s.findText('html')) h = QHBoxLayout() l.addLayout(h) la = QLabel(_('Choose the &type of template to edit:')) la.setBuddy(s) h.addWidget(la), h.addWidget(s), h.addStretch(10) s.currentIndexChanged.connect(self.show_template) self.helpl = la = QLabel( _('The variables {0} and {1} will be replaced with the title and author of the book. {2}' ' is where the cursor will be positioned. If you want to include braces in your template,' ' for example for CSS rules, you have to escape them, like this: {3}' ).format(*[ '<code>%s</code>' % x for x in ['{TITLE}', '{AUTHOR}', '%CURSOR%', 'body {{ color: red }}'] ])) la.setWordWrap(True) l.addWidget(la) self.save_timer = t = QTimer(self) t.setSingleShot(True), t.setInterval(100) t.timeout.connect(self._save_syntax) self.editor = e = TextEdit(self) l.addWidget(e) e.textChanged.connect(self.save_syntax) self.show_template() self.bb.clear() self.bb.addButton(QDialogButtonBox.StandardButton.Close) self.rd = b = self.bb.addButton( QDialogButtonBox.StandardButton.RestoreDefaults) b.clicked.connect(self.restore_defaults) l.addWidget(self.bb)
def setup_ui(self): self.l = l = QFormLayout(self) self.export_format = ef = QComboBox(self) ef.addItem(_('Plain text'), 'txt') ef.addItem(_('Markdown'), 'md') ef.addItem(*self.file_type_data()) idx = ef.findData(self.prefs[self.pref_name]) if idx > -1: ef.setCurrentIndex(idx) ef.currentIndexChanged.connect(self.save_format_pref) l.addRow(_('Format to export in:'), ef) l.addRow(self.bb) self.bb.clear() self.bb.addButton(QDialogButtonBox.StandardButton.Cancel) b = self.bb.addButton(_('Copy to clipboard'), QDialogButtonBox.ButtonRole.ActionRole) b.clicked.connect(self.copy_to_clipboard) b.setIcon(QIcon(I('edit-copy.png'))) b = self.bb.addButton(_('Save to file'), QDialogButtonBox.ButtonRole.ActionRole) b.clicked.connect(self.save_to_file) b.setIcon(QIcon(I('save.png')))
def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QVBoxLayout(self) self.h = h = QHBoxLayout() self.la = la = QLabel(self.MSG) la.setWordWrap(True) l.addWidget(la) l.addLayout(h) english_sentence = '{preamble} {match_type}' sentence = _('{preamble} {match_type}') if set(sentence.split()) != set(english_sentence.split()): sentence = english_sentence parts = sentence.split() for clause in parts: if clause == '{preamble}': self.preamble = w = QLabel(_('If the tag')) elif clause == '{match_type}': self.match_type = w = QComboBox(self) for action, m in MATCH_TYPE_MAP.items(): w.addItem(m.text, action) w.currentIndexChanged.connect(self.update_state) h.addWidget(w) if clause is not parts[-1]: h.addWidget(QLabel('\xa0')) h.addStretch(1) self.generic_query = gq = GenericEdit(self) self.css_query = cq = CSSEdit(self) self.xpath_query = xq = XPathEdit( self, object_name='html_transform_rules_xpath', show_msg=False) l.addWidget(gq), l.addWidget(cq), l.addWidget(xq) self.thenl = QLabel(_('Then:')) l.addWidget(self.thenl) self.actions = a = ActionsContainer(self) l.addWidget(a) self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add another action')) b.clicked.connect(self.actions.new_action) l.addWidget(b) self.update_state()
def __init__(self, name, data, parent=None): QWidget.__init__(self, parent) self.l = l = QHBoxLayout(self) self.setLayout(l) self.label = QLabel(name) l.addWidget(self.label) self.data = data def create_color_button(key, text): b = ColorButton(data, key, text, self) b.changed.connect(self.changed), l.addWidget(b) bc = QToolButton(self) bc.setIcon(QIcon(I('clear_left.png'))) bc.setToolTip(_('Remove color')) bc.clicked.connect(b.clear) h = QHBoxLayout() h.addWidget(b), h.addWidget(bc) return h for k, text in (('fg', _('&Foreground')), ('bg', _('&Background'))): h = create_color_button(k, text) l.addLayout(h) for k, text in (('bold', _('B&old')), ('italic', _('&Italic'))): w = Bool(data, k, text, self) w.changed.connect(self.changed) l.addWidget(w) self.underline = us = QComboBox(self) us.addItems(sorted(tuple(underline_styles) + ('', ))) idx = us.findText(data.get('underline', '') or '') us.setCurrentIndex(max(idx, 0)) us.currentIndexChanged.connect(self.us_changed) self.la = la = QLabel(_('&Underline:')) la.setBuddy(us) h = QHBoxLayout() h.addWidget(la), h.addWidget(us), l.addLayout(h) h = create_color_button('underline_color', _('Color')) l.addLayout(h) l.addStretch(1)