def _setupUi(self): flabel = QLabel("In this field:") self.fsel = QComboBox() fields = self._getFields() self.fsel.addItems(fields) self.cb = QCheckBox() self.cb.setText("transform to plain text") f_hbox = QHBoxLayout() f_hbox.addWidget(flabel) f_hbox.addWidget(self.fsel) f_hbox.addWidget(self.cb) f_hbox.setAlignment(Qt.AlignLeft) button_box = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, orientation=Qt.Horizontal, parent=self, ) bottom_hbox = QHBoxLayout() bottom_hbox.addWidget(button_box) vbox_main = QVBoxLayout() vbox_main.addLayout(f_hbox) vbox_main.addLayout(bottom_hbox) self.setLayout(vbox_main) self.setWindowTitle("Batch Clean Selected Notes") button_box.rejected.connect(self.reject) button_box.accepted.connect(self.accept) self.rejected.connect(self.reject) self.accepted.connect(self.accept) self.fsel.setFocus()
def _create_gui(self): self.setWindowTitle(tr(TR.ACTIONS_PREVIEW)) qconnect(self.finished, self._on_finished) self.silentlyClose = True self.vbox = QVBoxLayout() self.vbox.setContentsMargins(0, 0, 0, 0) self._web = AnkiWebView(title="previewer") self.vbox.addWidget(self._web) self.bbox = QDialogButtonBox() self._replay = self.bbox.addButton(tr(TR.ACTIONS_REPLAY_AUDIO), QDialogButtonBox.ActionRole) self._replay.setAutoDefault(False) self._replay.setShortcut(QKeySequence("R")) self._replay.setToolTip(tr(TR.ACTIONS_SHORTCUT_KEY, val="R")) qconnect(self._replay.clicked, self._on_replay_audio) both_sides_button = QCheckBox(tr(TR.QT_MISC_BACK_SIDE_ONLY)) both_sides_button.setShortcut(QKeySequence("B")) both_sides_button.setToolTip(tr(TR.ACTIONS_SHORTCUT_KEY, val="B")) self.bbox.addButton(both_sides_button, QDialogButtonBox.ActionRole) self._show_both_sides = self.mw.col.conf.get("previewBothSides", False) both_sides_button.setChecked(self._show_both_sides) qconnect(both_sides_button.toggled, self._on_show_both_sides) self.vbox.addWidget(self.bbox) self.setLayout(self.vbox) restoreGeom(self, "preview")
def _create_gui(self) -> None: self.setWindowTitle(tr.actions_preview()) self.close_shortcut = QShortcut(QKeySequence("Ctrl+Shift+P"), self) qconnect(self.close_shortcut.activated, self.close) qconnect(self.finished, self._on_finished) self.silentlyClose = True self.vbox = QVBoxLayout() self.vbox.setContentsMargins(0, 0, 0, 0) self._web = AnkiWebView(title="previewer") self.vbox.addWidget(self._web) self.bbox = QDialogButtonBox() self._replay = self.bbox.addButton( tr.actions_replay_audio(), QDialogButtonBox.ButtonRole.ActionRole) self._replay.setAutoDefault(False) self._replay.setShortcut(QKeySequence("R")) self._replay.setToolTip(tr.actions_shortcut_key(val="R")) qconnect(self._replay.clicked, self._on_replay_audio) both_sides_button = QCheckBox(tr.qt_misc_back_side_only()) both_sides_button.setShortcut(QKeySequence("B")) both_sides_button.setToolTip(tr.actions_shortcut_key(val="B")) self.bbox.addButton(both_sides_button, QDialogButtonBox.ButtonRole.ActionRole) self._show_both_sides = self.mw.col.get_config_bool( Config.Bool.PREVIEW_BOTH_SIDES) both_sides_button.setChecked(self._show_both_sides) qconnect(both_sides_button.toggled, self._on_show_both_sides) self.vbox.addWidget(self.bbox) self.setLayout(self.vbox) restoreGeom(self, "preview")
def _create_gui(self): self.setWindowTitle(_("Preview")) qconnect(self.finished, self._on_finished) self.silentlyClose = True self.vbox = QVBoxLayout() self.vbox.setContentsMargins(0, 0, 0, 0) self._web = AnkiWebView(title="previewer") self.vbox.addWidget(self._web) self.bbox = QDialogButtonBox() self._replay = self.bbox.addButton(_("Replay Audio"), QDialogButtonBox.ActionRole) self._replay.setAutoDefault(False) self._replay.setShortcut(QKeySequence("R")) self._replay.setToolTip(_("Shortcut key: %s" % "R")) qconnect(self._replay.clicked, self._on_replay_audio) both_sides_button = QCheckBox(_("Show Both Sides")) both_sides_button.setShortcut(QKeySequence("B")) both_sides_button.setToolTip(_("Shortcut key: %s" % "B")) self.bbox.addButton(both_sides_button, QDialogButtonBox.ActionRole) self._show_both_sides = self.mw.col.conf.get("previewBothSides", False) both_sides_button.setChecked(self._show_both_sides) qconnect(both_sides_button.toggled, self._on_show_both_sides) self.vbox.addWidget(self.bbox) self.setLayout(self.vbox) restoreGeom(self, "preview")
def setup_evernote(self): global evernote_default_deck global evernote_default_tag global evernote_tags_to_import global keep_evernote_tags global update_existing_notes widget = QWidget() layout = QVBoxLayout() # Default Deck evernote_default_deck_label = QLabel("Default Deck for imported Cards:") evernote_default_deck = QLineEdit() evernote_default_deck.setText(mw.col.conf.get(SETTING_DEFAULT_DECK, "")) layout.insertWidget(int(layout.count()) + 1, evernote_default_deck_label) layout.insertWidget(int(layout.count()) + 2, evernote_default_deck) evernote_default_deck.connect(evernote_default_deck, SIGNAL("editingFinished()"), update_evernote_default_deck) # Default Tag evernote_default_tag_label = QLabel("Default Tag for imported Cards:") evernote_default_tag = QLineEdit() evernote_default_tag.setText(mw.col.conf.get(SETTING_DEFAULT_TAG, "")) layout.insertWidget(int(layout.count()) + 1, evernote_default_tag_label) layout.insertWidget(int(layout.count()) + 2, evernote_default_tag) evernote_default_tag.connect(evernote_default_tag, SIGNAL("editingFinished()"), update_evernote_default_tag) # Tags to Import evernote_tags_to_import_label = QLabel("Evernote Tags to Import:") evernote_tags_to_import = QLineEdit() evernote_tags_to_import.setText(mw.col.conf.get(SETTING_TAGS_TO_IMPORT, "")) layout.insertWidget(int(layout.count()) + 1, evernote_tags_to_import_label) layout.insertWidget(int(layout.count()) + 2, evernote_tags_to_import) evernote_tags_to_import.connect(evernote_tags_to_import, SIGNAL("editingFinished()"), update_evernote_tags_to_import) # Keep Evernote Tags keep_evernote_tags = QCheckBox("Keep Evernote Tags", self) keep_evernote_tags.setChecked(mw.col.conf.get(SETTING_KEEP_TAGS, False)) keep_evernote_tags.stateChanged.connect(update_evernote_keep_tags) layout.insertWidget(int(layout.count()) + 1, keep_evernote_tags) # Update Existing Notes update_existing_notes = QComboBox() update_existing_notes.addItems(["Ignore Existing Notes", "Update Existing Notes In-Place", "Delete and Re-Add Existing Notes"]) update_existing_notes.setCurrentIndex(mw.col.conf.get(SETTING_UPDATE_EXISTING_NOTES, UpdateExistingNotes.UpdateNotesInPlace)) update_existing_notes.activated.connect(update_evernote_update_existing_notes) layout.insertWidget(int(layout.count()) + 1, update_existing_notes) # Vertical Spacer vertical_spacer = QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(vertical_spacer) # Parent Widget widget.setLayout(layout) # New Tab self.form.tabWidget.addTab(widget, "Evernote2AnkiMac")
def setup_options(pref: Preferences): f = pref.form ##### ENABLE STRAIGHT REWARD f.straightRewardEnabled = QCheckBox("Disable straight reward on sync") f.straightRewardEnabled.setChecked(syncDisabled.value) tabLayout = f.tab_2.findChildren(QVBoxLayout)[1] positionAfterForceSync = 4 tabLayout.insertWidget(positionAfterForceSync, f.straightRewardEnabled)
def adjust_dialog(dialog): global apply_to_all apply_to_all = QCheckBox("Apply these settings to all models?") # TODO use something nicer for c in dialog.children(): if isinstance(c, QTabWidget): for d in c.children(): if isinstance(d, QStackedWidget): for e in d.children(): if isinstance(e, QWidget): for f in e.children(): if isinstance(f, QVBoxLayout): f.addWidget(apply_to_all)
def create_checkbox(setting, label=" ", default_value=False, is_fixed_size=False, fixed_width=None): if isinstance(label, bool): default_value = label label = " " checkbox = QCheckBox(label, self) sval = setting.fetch() if not isinstance(sval, bool): sval = default_value checkbox.setChecked(sval) # noinspection PyUnresolvedReferences checkbox.stateChanged.connect(lambda: update_checkbox(setting)) if is_fixed_size or fixed_width: checkbox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) if fixed_width: checkbox.setFixedWidth(fixed_width) elements[setting] = checkbox return checkbox
def setup_reward_tab(dconf: DeckConf) -> None: """Add an option tab for Straight Reward at Review section on Deckconf dialog.""" w = QWidget() form = dconf.form form.horizontalLayout_straight = QVBoxLayout() ##### GRID LAYOUT form.gridLayout_straight = get_grid_layout(form) form.horizontalLayout_straight.addWidget(form.gridLayout_straight) ##### ENABLE NOTIFICATIONS form.straightEnableNotificationsCheckBox = QCheckBox( "Enable Notifications", w) form.horizontalLayout_straight.addWidget( form.straightEnableNotificationsCheckBox) ##### STRETCH form.horizontalLayout_straight.addStretch() ##### FINISH UP w.setLayout(form.horizontalLayout_straight) positionBetweenReviewsAndLapses = 2 form.tabWidget.insertTab(positionBetweenReviewsAndLapses, w, "Rewards")
def setup(self): addonconfig = mw.addonManager.getConfig(__name__) config = types.SimpleNamespace(**addonconfig['defaults']) if addonconfig.get("_debug_time", False): self.timepoint = lambda c: print("%s: %0.3f" % (c, time.time() - self.time)) else: self.timepoint = lambda _: None config.did = mw.col.conf['curDeck'] swin = QDialog(mw) vl = QVBoxLayout() fl = QHBoxLayout() deckcb = QComboBox() deckcb.addItems(sorted(mw.col.decks.allNames())) deckcb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) fl.addWidget(QLabel("Deck: ")) deckcb.setCurrentText(mw.col.decks.get(config.did)['name']) def change_did(deckname): config.did = mw.col.decks.byName(deckname)['id'] deckcb.currentTextChanged.connect(change_did) fl.addWidget(deckcb) vl.addLayout(fl) frm = QGroupBox("Settings") vl.addWidget(frm) il = QVBoxLayout() fl = QHBoxLayout() field = QLineEdit() field.setPlaceholderText( "e.g. \"kanji\", \"hanzi\" or \"sentence-kanji\" (default: \"%s\")" % config.pattern) il.addWidget( QLabel("Pattern or Field names to search for (case insensitive):")) fl.addWidget(field) liter = QCheckBox("Match exactly") liter.setChecked(config.literal) fl.addWidget(liter) il.addLayout(fl) stint = QSpinBox() stint.setRange(1, 65536) stint.setValue(config.interval) il.addWidget(QLabel("Card interval considered strong:")) il.addWidget(stint) ttcol = QSpinBox() ttcol.setRange(1, 99) ttcol.setValue(config.thin) il.addWidget(QLabel("Number of Columns in the in-app table:")) il.addWidget(ttcol) wtcol = QSpinBox() wtcol.setRange(1, 99) wtcol.setValue(config.wide) il.addWidget(QLabel("Number of Columns in the exported table:")) il.addWidget(wtcol) groupby = QComboBox() groupby.addItems([ *("None, sorted by " + x.pretty_value() for x in SortOrder), *(x.name for x in data.groups), ]) groupby.setCurrentIndex(config.groupby) il.addWidget(QLabel("Group by:")) il.addWidget(groupby) shnew = QCheckBox("Show units not yet seen") shnew.setChecked(config.unseen) il.addWidget(shnew) toolt = QCheckBox("Show informational tooltips") toolt.setChecked(config.tooltips) il.addWidget(toolt) frm.setLayout(il) hl = QHBoxLayout() vl.addLayout(hl) gen = QPushButton("Generate", clicked=swin.accept) hl.addWidget(gen) cls = QPushButton("Close", clicked=swin.reject) hl.addWidget(cls) swin.setLayout(vl) swin.setTabOrder(gen, cls) swin.setTabOrder(cls, field) swin.setTabOrder(field, liter) swin.setTabOrder(liter, stint) swin.setTabOrder(stint, ttcol) swin.setTabOrder(ttcol, wtcol) swin.setTabOrder(wtcol, groupby) swin.setTabOrder(groupby, shnew) swin.setTabOrder(shnew, toolt) swin.resize(500, 400) if swin.exec_(): mw.progress.start(immediate=True) if len(field.text().strip()) != 0: config.pattern = field.text().lower() config.pattern = config.pattern.split() config.literal = liter.isChecked() config.interval = stint.value() config.thin = ttcol.value() config.wide = wtcol.value() config.groupby = groupby.currentIndex() config.unseen = shnew.isChecked() config.tooltips = toolt.isChecked() self.makegrid(config) mw.progress.finish() self.win.show()
def setupUI(self): mainLayout = QVBoxLayout() self.setLayout(mainLayout) # add widgets to set height and width widthLabel = QLabel('width') heightLabel = QLabel('height') self.widthEdit = QLineEdit(self) self.widthValidate = self.validate_label() self.heightValidate = self.validate_label() self.widthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.heightEdit = QLineEdit(self) self.heightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["width"] = self.widthEdit self.attr2qt["height"] = self.heightEdit wLayout = QHBoxLayout() wLayout.addWidget(widthLabel) wLayout.addWidget(self.widthEdit) hLayout = QHBoxLayout() hLayout.addWidget(heightLabel) hLayout.addWidget(self.heightEdit) sizeInputLayout = QHBoxLayout() sizeInputLayout.addLayout(wLayout) sizeInputLayout.addLayout(hLayout) labelLayout = QHBoxLayout() labelLayout.addWidget(self.widthValidate) labelLayout.addWidget(self.heightValidate) sizeLayout = QVBoxLayout() sizeLayout.addLayout(sizeInputLayout) sizeLayout.addLayout(labelLayout) # add final layout to main layout mainLayout.addLayout(sizeLayout) mainLayout.addWidget(self.hLine()) # add min- sizes and max- sizes if self.config["min-size"]: minWidthLabel = QLabel("min-width") minHeightLabel = QLabel("min-height") self.minWidthEdit = QLineEdit(self) self.minHeightEdit = QLineEdit(self) minLayout = QHBoxLayout() minLayout.addWidget(minWidthLabel) minLayout.addWidget(self.minWidthEdit) minLayout.addWidget(minHeightLabel) minLayout.addWidget(self.minHeightEdit) self.minWidthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.minHeightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["min-width"] = self.minWidthEdit self.attr2qt["min-height"] = self.minHeightEdit mainLayout.addLayout(minLayout) mainLayout.addWidget(self.hLine()) if self.config["max-size"]: maxWidthLabel = QLabel("max-width") maxHeightLabel = QLabel("max-height") self.maxWidthEdit = QLineEdit(self) self.maxHeightEdit = QLineEdit(self) maxLayout = QHBoxLayout() maxLayout.addWidget(maxWidthLabel) maxLayout.addWidget(self.maxWidthEdit) maxLayout.addWidget(maxHeightLabel) maxLayout.addWidget(self.maxHeightEdit) self.maxWidthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.maxHeightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["max-width"] = self.maxWidthEdit self.attr2qt["max-height"] = self.maxHeightEdit mainLayout.addLayout(maxLayout) mainLayout.addWidget(self.hLine()) # add widgets to show original width, height owidthLabel = QLabel('original width') oheightLabel = QLabel('original height') self.originalWidth = QLineEdit(self) self.originalHeight = QLineEdit(self) self.disableLineEdit(self.originalWidth) self.disableLineEdit(self.originalHeight) sizeLayout2 = QHBoxLayout() sizeLayout2.addWidget(owidthLabel) sizeLayout2.addWidget(self.originalWidth) sizeLayout2.addWidget(oheightLabel) sizeLayout2.addWidget(self.originalHeight) mainLayout.addLayout(sizeLayout2) # add Image Occlusion related buttons if self.is_occl: mainLayout.addWidget(self.hLine()) occlLabel = QLabel("Image Occlusion") occlLabel.setStyleSheet("QLabel {font-weight : bold;}") mainLayout.addWidget(occlLabel) occlAllNote = QCheckBox("Apply to all notes") self.occlAllNote = occlAllNote occlLayout = QHBoxLayout() occlLayout.addWidget(occlAllNote) self.attr2qt["Apply to all notes"] = self.occlAllNote if self.curr_fld in self.main.all_occl_flds: occlAllFld = QCheckBox("Apply to all fields") self.occlAllFld = occlAllFld occlLayout.addWidget(occlAllFld) self.attr2qt["Apply to all fields"] = self.occlAllFld mainLayout.addLayout(occlLayout) # add buttons okButton = QPushButton("OK") okButton.clicked.connect(self.clicked_ok) okButton.setDefault(True) okButton.setShortcut("Ctrl+Return") cancelButton = QPushButton("Cancel") cancelButton.clicked.connect(self.clicked_cancel) resetButton = QPushButton("Default") resetButton.clicked.connect(self.clicked_defaults) btnLayout = QHBoxLayout() btnLayout.addStretch(1) btnLayout.addWidget(okButton) btnLayout.addWidget(cancelButton) btnLayout.addWidget(resetButton) mainLayout.addLayout(btnLayout) self.setWindowTitle('Style Editor') self.show()