def _show(self, field_names: Sequence[str]) -> None: # add "all fields" and "tags" to the top of the list self.field_names = [ tr(TR.BROWSING_ALL_FIELDS), tr(TR.EDITING_TAGS), ] + list(field_names) disable_help_button(self) self.form = aqt.forms.findreplace.Ui_Dialog() self.form.setupUi(self) self.setWindowModality(Qt.WindowModal) self._find_history = restore_combo_history( self.form.find, self.COMBO_NAME + "Find" ) self.form.find.completer().setCaseSensitivity(True) self._replace_history = restore_combo_history( self.form.replace, self.COMBO_NAME + "Replace" ) self.form.replace.completer().setCaseSensitivity(True) restore_is_checked(self.form.re, self.COMBO_NAME + "Regex") restore_is_checked(self.form.ignoreCase, self.COMBO_NAME + "ignoreCase") self.form.field.addItems(self.field_names) restore_combo_index_for_session( self.form.field, self.field_names, self.COMBO_NAME + "Field" ) qconnect(self.form.buttonBox.helpRequested, self.show_help) restoreGeom(self, "findreplace") self.show() self.form.find.setFocus()
def setup(self) -> None: # maps self.flayout = QHBoxLayout() self.flayout.setContentsMargins(0, 0, 0, 0) self.fwidg = None self.form.fieldMap.setLayout(self.flayout) self.tlayout = QHBoxLayout() self.tlayout.setContentsMargins(0, 0, 0, 0) self.twidg = None self.form.templateMap.setLayout(self.tlayout) if self.style().objectName() == "gtk+": # gtk+ requires margins in inner layout self.form.verticalLayout_2.setContentsMargins(0, 11, 0, 0) self.form.verticalLayout_3.setContentsMargins(0, 11, 0, 0) # model chooser import aqt.modelchooser self.oldModel = self.browser.col.models.get( self.browser.col.db.scalar("select mid from notes where id = ?", self.nids[0])) self.form.oldModelLabel.setText(self.oldModel["name"]) self.modelChooser = aqt.modelchooser.ModelChooser( self.browser.mw, self.form.modelChooserWidget, label=False) self.modelChooser.models.setFocus() qconnect(self.form.buttonBox.helpRequested, self.onHelp) self.modelChanged(self.browser.mw.col.models.current()) self.pauseUpdate = False
def _setupFastRepositionActions(self): """Add actions to the browser menu to move the cards up and down """ # Set the actions active only if the cards are sorted by due date. This is necessary because the reposition # is done considering the current ordering in the browser mvtotopAction = QAction("Move to top", self.browser) mvtotopAction.setShortcut( shortcut(gc("shortcut: Move to top", "Alt+0"))) mvtotopAction.triggered.connect(self.moveCardToTop) self.actions.append(mvtotopAction) mvuponeAction = QAction("Move one up", self.browser) mvuponeAction.setShortcut( shortcut(gc("shortcut: Move one up", "Alt+Up"))) mvuponeAction.triggered.connect(self.moveCardUp) self.actions.append(mvuponeAction) mvdownoneAction = QAction("Move one down", self.browser) mvdownoneAction.setShortcut( shortcut(gc("shortcut: Move one down", "Alt+Down"))) mvdownoneAction.triggered.connect(self.moveCardDown) self.actions.append(mvdownoneAction) self.browser.form.menu_Cards.addSeparator() self.browser.form.menu_Cards.addAction(mvtotopAction) self.browser.form.menu_Cards.addAction(mvuponeAction) self.browser.form.menu_Cards.addAction(mvdownoneAction) browse_mode_switch = self.browser.findChild(Switch) qconnect(browse_mode_switch.toggled, self._onBrowserModeToggled) isDueSort = self.browser.col.conf['sortType'] == 'cardDue' self.setActionsEnabled(isDueSort and not browse_mode_switch.isChecked())
def _show(self, field_names: Sequence[str]) -> None: # add "all fields" and "tags" to the top of the list self.field_names = [ tr.browsing_all_fields(), tr.editing_tags(), ] + list(field_names) disable_help_button(self) self.form = aqt.forms.findreplace.Ui_Dialog() self.form.setupUi(self) self.setWindowModality(Qt.WindowModality.WindowModal) self._find_history = restore_combo_history(self.form.find, self.COMBO_NAME + "Find") self.form.find.completer().setCaseSensitivity( Qt.CaseSensitivity.CaseSensitive) self._replace_history = restore_combo_history( self.form.replace, self.COMBO_NAME + "Replace") self.form.replace.completer().setCaseSensitivity( Qt.CaseSensitivity.CaseSensitive) if not self.note_ids: # no selected notes to affect self.form.selected_notes.setChecked(False) self.form.selected_notes.setEnabled(False) elif self._field: self.form.selected_notes.setChecked(False) restore_is_checked(self.form.re, self.COMBO_NAME + "Regex") restore_is_checked(self.form.ignoreCase, self.COMBO_NAME + "ignoreCase") self.form.field.addItems(self.field_names) if self._field: self.form.field.setCurrentIndex(self.field_names.index( self._field)) else: restore_combo_index_for_session(self.form.field, self.field_names, self.COMBO_NAME + "Field") qconnect(self.form.buttonBox.helpRequested, self.show_help) restoreGeom(self, "findreplace") self.show() self.form.find.setFocus()
def _setup_ui(self, card_id: CardId | None) -> None: self.mw.garbage_collect_on_dialog_finish(self) disable_help_button(self) restoreGeom(self, self.GEOMETRY_KEY) addCloseShortcut(self) setWindowIcon(self) self.web = AnkiWebView(title=self.TITLE) self.web.setVisible(False) self.web.load_ts_page("card-info") layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.web) buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) buttons.setContentsMargins(10, 0, 10, 10) layout.addWidget(buttons) qconnect(buttons.rejected, self.reject) self.setLayout(layout) self.update_card(card_id)
def __init__(self, parent: QWidget, mw: aqt.AnkiQt, card: Card) -> None: super().__init__(parent) disable_help_button(self) cs = CardStats(mw.col, card) info = cs.report(include_revlog=True) l = QVBoxLayout() l.setContentsMargins(0, 0, 0, 0) w = AnkiWebView(title="browser card info") l.addWidget(w) w.stdHtml(info + "<p>", context=self) bb = QDialogButtonBox(QDialogButtonBox.Close) l.addWidget(bb) qconnect(bb.rejected, self.reject) self.setLayout(l) self.setWindowModality(Qt.WindowModal) self.resize(500, 400) restoreGeom(self, "revlog") self.show()
def init(): # init error dialog global err err = aqt.QErrorMessage(window) # menu items menu = aqt.QMenu(window.form.menuTools) menu.setTitle("Import / Export templates") window.form.menuTools.addAction(menu.menuAction()) actions = [(qt.QAction("Export to ...", menu), templates.export_tmpls), (qt.QAction("Import from ...", menu), templates.import_tmpls), (qt.QAction("Configure", menu), _edit_config), (qt.QAction("Help / Guide", menu), _help)] for action, func in actions: utils.qconnect(action.triggered, func) menu.addAction(action) # editor setup for _edit_config window.mgr = window.addonManager
def rebuildTemplateMap(self, key: Optional[str] = None, attr: Optional[str] = None) -> None: if not key: key = "t" attr = "tmpls" map = getattr(self, key + "widg") lay = getattr(self, key + "layout") src = self.oldModel[attr] dst = self.targetModel[attr] if map: lay.removeWidget(map) map.deleteLater() setattr(self, key + "MapWidget", None) map = QWidget() l = QGridLayout() combos = [] targets = [x["name"] for x in dst] + [tr.browsing_nothing()] indices = {} for i, x in enumerate(src): l.addWidget(QLabel(tr.browsing_change_to(val=x["name"])), i, 0) cb = QComboBox() cb.addItems(targets) idx = min(i, len(targets) - 1) cb.setCurrentIndex(idx) indices[cb] = idx qconnect( cb.currentIndexChanged, lambda i, cb=cb, key=key: self.onComboChanged(i, cb, key), ) combos.append(cb) l.addWidget(cb, i, 1) map.setLayout(l) lay.addWidget(map) setattr(self, key + "widg", map) setattr(self, key + "layout", lay) setattr(self, key + "combos", combos) setattr(self, key + "indices", indices)
note['Name'] = widget['name'] note['Description'] = widget['description'] note['URL'] = widget['link'] col.add_note(note, deck['id']) def importWidgets(col: Collection) -> Optional[Deck]: # Abort import if deck already exists. if widgetsDeckExists(col): return deck = setupWidgetsDeck(col) model = setupWidgetModel(col) catalog = downloadWidgetsCatalog() createWidgetNotes(col, deck, model, catalog) return deck def importWidgetsActionFn() -> None: deck = importWidgets(mw.col) if deck is None: return mw.reset() importWidgetsAction = QAction('Import Flutter Widgets', mw) qconnect(importWidgetsAction.triggered, importWidgetsActionFn) mw.form.menuTools.addAction(importWidgetsAction)
lineOfText += imageText # Add image metadata at end of line once if len(imageConfig) > 0: lineOfText += imageConfig imageConfig = "" itemText.append(lineOfText) indentation += 1 orgStars = (orgStar * indentation) for line in itemText: if (_closeLineBreak(line)): orgFormattedFile.append(line) else: formattedListItem = "{} {}".format(orgStars, line) orgFormattedFile.append(formattedListItem) else: pass # print("Unknown line type: {}".format(item.name)) return {"deckName": deckName, "data": orgFormattedFile} # create a new menu item, "test" action = QAction("testing", mw) # set it to call testFunction when it's clicked qconnect(action.triggered, testFunction) # and add it to the tools menu mw.form.menuTools.addAction(action)