Exemplo n.º 1
0
    def _setup_ui(self) -> None:
        self.setWindowTitle(tr.scheduling_description())
        self.setWindowModality(Qt.ApplicationModal)
        self.mw.garbage_collect_on_dialog_finish(self)
        self.setMinimumWidth(400)
        disable_help_button(self)
        restoreGeom(self, self.TITLE)
        addCloseShortcut(self)

        box = QVBoxLayout()

        label = QLabel(tr.scheduling_description_to_show_on_overview_screen())
        box.addWidget(label)

        self.enable_markdown = QCheckBox(tr.deck_config_description_markdown())
        self.enable_markdown.setToolTip(tr.deck_config_description_markdown_hint())
        self.enable_markdown.setChecked(self.deck.normal.markdown_description)
        box.addWidget(self.enable_markdown)

        self.description = QPlainTextEdit()
        self.description.setPlainText(self.deck.normal.description)
        box.addWidget(self.description)

        button_box = QDialogButtonBox()
        ok = button_box.addButton(QDialogButtonBox.Ok)
        qconnect(ok.clicked, self.save_and_accept)
        box.addWidget(button_box)

        self.setLayout(box)
        self.show()
Exemplo n.º 2
0
 def __init__(self, mw: AnkiQt, nt: NoteType, parent=None):
     QDialog.__init__(self, parent or mw)
     self.mw = mw
     self.col = self.mw.col
     self.mm = self.mw.col.models
     self.model = nt
     self.mm._remove_from_cache(self.model["id"])
     self.mw.checkpoint(tr(TR.EDITING_FIELDS))
     self.change_tracker = ChangeTracker(self.mw)
     self.form = aqt.forms.fields.Ui_Dialog()
     self.form.setupUi(self)
     self.setWindowTitle(
         without_unicode_isolation(
             tr(TR.FIELDS_FIELDS_FOR, val=self.model["name"])))
     disable_help_button(self)
     self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
     self.form.buttonBox.button(
         QDialogButtonBox.Cancel).setAutoDefault(False)
     self.form.buttonBox.button(QDialogButtonBox.Save).setAutoDefault(False)
     self.currentIdx = None
     self.oldSortField = self.model["sortf"]
     self.fillFields()
     self.setupSignals()
     self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
     self.form.fieldList.dropEvent = self.onDrop
     self.form.fieldList.setCurrentRow(0)
     self.exec_()
Exemplo n.º 3
0
    def _initial_dialog_setup(self) -> None:
        self.form = aqt.forms.filtered_deck.Ui_Dialog()
        self.form.setupUi(self)

        order_labels = self.col.sched.filtered_deck_order_labels()

        self.form.order.addItems(order_labels)
        self.form.order_2.addItems(order_labels)

        qconnect(self.form.resched.stateChanged, self._onReschedToggled)

        qconnect(self.form.search_button.clicked, self.on_search_button)
        qconnect(self.form.search_button_2.clicked, self.on_search_button_2)
        qconnect(self.form.hint_button.clicked, self.on_hint_button)
        blue = theme_manager.color(colors.LINK)
        grey = theme_manager.color(colors.DISABLED)
        self.setStyleSheet(f"""QPushButton[label] {{ padding: 0; border: 0 }}
            QPushButton[label]:hover {{ text-decoration: underline }}
            QPushButton[label="search"] {{ color: {blue} }}
            QPushButton[label="hint"] {{ color: {grey} }}""")
        disable_help_button(self)
        self.setWindowModality(Qt.WindowModality.WindowModal)
        qconnect(self.form.buttonBox.helpRequested,
                 lambda: openHelp(HelpPage.FILTERED_DECK))

        if self.col.sched_ver() == 1:
            self.form.secondFilter.setVisible(False)
        restoreGeom(self, self.GEOMETRY_KEY)
Exemplo n.º 4
0
 def __init__(self, mw: aqt.main.AnkiQt):
     QDialog.__init__(self, mw, Qt.Window)
     mw.setupDialogGC(self)
     self.mw = mw
     self.name = "deckStats"
     self.period = 0
     self.form = aqt.forms.stats.Ui_Dialog()
     self.oldPos = None
     self.wholeCollection = False
     self.setMinimumWidth(700)
     disable_help_button(self)
     f = self.form
     f.setupUi(self)
     f.groupBox.setVisible(False)
     f.groupBox_2.setVisible(False)
     restoreGeom(self, self.name)
     b = f.buttonBox.addButton(tr(TR.STATISTICS_SAVE_PDF),
                               QDialogButtonBox.ActionRole)
     qconnect(b.clicked, self.saveImage)
     b.setAutoDefault(False)
     maybeHideClose(self.form.buttonBox)
     addCloseShortcut(self)
     gui_hooks.stats_dialog_will_show(self)
     self.show()
     self.refresh()
     self.form.web.set_bridge_command(self._on_bridge_cmd, self)
     self.activateWindow()
Exemplo n.º 5
0
 def _onHtmlEdit(self, field: int) -> None:
     d = QDialog(self.widget, Qt.WindowType.Window)
     form = aqt.forms.edithtml.Ui_Dialog()
     form.setupUi(d)
     restoreGeom(d, "htmlEditor")
     disable_help_button(d)
     qconnect(form.buttonBox.helpRequested,
              lambda: openHelp(HelpPage.EDITING_FEATURES))
     font = QFont("Courier")
     font.setStyleHint(QFont.StyleHint.TypeWriter)
     form.textEdit.setFont(font)
     form.textEdit.setPlainText(self.note.fields[field])
     d.show()
     form.textEdit.moveCursor(QTextCursor.MoveOperation.End)
     d.exec()
     html = form.textEdit.toPlainText()
     if html.find(">") > -1:
         # filter html through beautifulsoup so we can strip out things like a
         # leading </div>
         html_escaped = self.mw.col.media.escape_media_filenames(html)
         with warnings.catch_warnings():
             warnings.simplefilter("ignore", UserWarning)
             html_escaped = str(BeautifulSoup(html_escaped, "html.parser"))
             html = self.mw.col.media.escape_media_filenames(html_escaped,
                                                             unescape=True)
     self.note.fields[field] = html
     if not self.addMode:
         self._save_current_note()
     self.loadNote(focusTo=field)
     saveGeom(d, "htmlEditor")
Exemplo n.º 6
0
 def __init__(self, mw: aqt.AnkiQt, deck: dict) -> None:
     QDialog.__init__(self, mw)
     self.mw = mw
     self.deck = deck
     self.childDids = [
         d[1] for d in self.mw.col.decks.children(self.deck["id"])
     ]
     self._origNewOrder = None
     self.form = aqt.forms.dconf.Ui_Dialog()
     self.form.setupUi(self)
     gui_hooks.deck_conf_did_setup_ui_form(self)
     self.mw.checkpoint(tr.actions_options())
     self.setupCombos()
     self.setupConfs()
     self.setWindowModality(Qt.WindowModal)
     qconnect(self.form.buttonBox.helpRequested,
              lambda: openHelp(HelpPage.DECK_OPTIONS))
     qconnect(self.form.confOpts.clicked, self.confOpts)
     qconnect(
         self.form.buttonBox.button(
             QDialogButtonBox.RestoreDefaults).clicked,
         self.onRestore,
     )
     self.setWindowTitle(
         without_unicode_isolation(
             tr.actions_options_for(val=self.deck["name"])))
     disable_help_button(self)
     # qt doesn't size properly with altered fonts otherwise
     restoreGeom(self, "deckconf", adjustSize=True)
     gui_hooks.deck_conf_will_show(self)
     self.show()
     self.exec_()
     saveGeom(self, "deckconf")
Exemplo n.º 7
0
 def __init__(self, mw: AnkiQt, parent: Optional[QWidget] = None):
     self.parent_ = parent or mw
     self.mw = mw
     self.col = mw.col
     QDialog.__init__(self, self.parent_, Qt.Window)
     self.model = None
     self.dialog = aqt.forms.addmodel.Ui_Dialog()
     self.dialog.setupUi(self)
     disable_help_button(self)
     # standard models
     self.models = []
     for (name, func) in stdmodels.get_stock_notetypes(self.col):
         item = QListWidgetItem(tr(TR.NOTETYPES_ADD, val=name))
         self.dialog.models.addItem(item)
         self.models.append((True, func))
     # add copies
     for m in sorted(self.col.models.all(), key=itemgetter("name")):
         item = QListWidgetItem(tr(TR.NOTETYPES_CLONE, val=m["name"]))
         self.dialog.models.addItem(item)
         self.models.append((False, m))  # type: ignore
     self.dialog.models.setCurrentRow(0)
     # the list widget will swallow the enter key
     s = QShortcut(QKeySequence("Return"), self)
     qconnect(s.activated, self.accept)
     # help
     qconnect(self.dialog.buttonBox.helpRequested, self.onHelp)
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    def _setup_ui(self) -> None:
        self.setWindowTitle(tr.scheduling_description())
        self.setWindowModality(Qt.WindowModality.ApplicationModal)
        self.mw.garbage_collect_on_dialog_finish(self)
        self.setMinimumWidth(400)
        disable_help_button(self)
        restoreGeom(self, self.TITLE)
        addCloseShortcut(self)

        box = QVBoxLayout()

        self.enable_markdown = QCheckBox(
            tr.deck_config_description_new_handling())
        self.enable_markdown.setToolTip(
            tr.deck_config_description_new_handling_hint())
        self.enable_markdown.setChecked(self.deck.get("md", False))
        box.addWidget(self.enable_markdown)

        self.description = QPlainTextEdit()
        self.description.setPlainText(self.deck.get("desc", ""))
        box.addWidget(self.description)

        button_box = QDialogButtonBox()
        ok = button_box.addButton(QDialogButtonBox.StandardButton.Ok)
        qconnect(ok.clicked, self.save_and_accept)
        box.addWidget(button_box)

        self.setLayout(box)
        self.show()
Exemplo n.º 10
0
 def __init__(
     self,
     mw: aqt.AnkiQt,
     names: Callable = None,
     accept: str = None,
     title: str = None,
     help: HelpPageArgument = HelpPage.KEYBOARD_SHORTCUTS,
     current: Optional[str] = None,
     cancel: bool = True,
     parent: Optional[QWidget] = None,
     dyn: bool = False,
     buttons: Optional[List[Union[str, QPushButton]]] = None,
     geomKey: str = "default",
 ) -> None:
     QDialog.__init__(self, parent or mw)
     self.mw = mw
     self.form = aqt.forms.studydeck.Ui_Dialog()
     self.form.setupUi(self)
     self.form.filter.installEventFilter(self)
     self.cancel = cancel
     gui_hooks.state_did_reset.append(self.onReset)
     self.geomKey = f"studyDeck-{geomKey}"
     restoreGeom(self, self.geomKey)
     disable_help_button(self)
     if not cancel:
         self.form.buttonBox.removeButton(
             self.form.buttonBox.button(QDialogButtonBox.Cancel))
     if buttons is not None:
         for button_or_label in buttons:
             self.form.buttonBox.addButton(button_or_label,
                                           QDialogButtonBox.ActionRole)
     else:
         b = QPushButton(tr.actions_add())
         b.setShortcut(QKeySequence("Ctrl+N"))
         b.setToolTip(shortcut(tr.decks_add_new_deck_ctrlandn()))
         self.form.buttonBox.addButton(b, QDialogButtonBox.ActionRole)
         qconnect(b.clicked, self.onAddDeck)
     if title:
         self.setWindowTitle(title)
     if not names:
         names_ = [
             d.name for d in self.mw.col.decks.all_names_and_ids(
                 include_filtered=dyn, skip_empty_default=True)
         ]
         self.nameFunc = None
         self.origNames = names_
     else:
         self.nameFunc = names
         self.origNames = names()
     self.name: Optional[str] = None
     self.ok = self.form.buttonBox.addButton(accept or tr.decks_study(),
                                             QDialogButtonBox.AcceptRole)
     self.setWindowModality(Qt.WindowModal)
     qconnect(self.form.buttonBox.helpRequested, lambda: openHelp(help))
     qconnect(self.form.filter.textEdited, self.redraw)
     qconnect(self.form.list.itemDoubleClicked, self.accept)
     self.show()
     # redraw after show so position at center correct
     self.redraw("", current)
     self.exec_()
Exemplo n.º 11
0
 def __init__(self, mw: AnkiQt, parent: CustomStudy) -> None:
     QDialog.__init__(self, parent, Qt.WindowType.Window)
     self.tags: str = ""
     self.tags_list: list[str] = []
     self.mw = mw
     self.parent_: Optional[CustomStudy] = parent
     self.deck = self.parent_.deck
     self.dialog = aqt.forms.taglimit.Ui_Dialog()
     self.dialog.setupUi(self)
     disable_help_button(self)
     s = QShortcut(
         QKeySequence("ctrl+d"),
         self.dialog.activeList,
         context=Qt.ShortcutContext.WidgetShortcut,
     )
     qconnect(s.activated, self.dialog.activeList.clearSelection)
     s = QShortcut(
         QKeySequence("ctrl+d"),
         self.dialog.inactiveList,
         context=Qt.ShortcutContext.WidgetShortcut,
     )
     qconnect(s.activated, self.dialog.inactiveList.clearSelection)
     self.rebuildTagList()
     restoreGeom(self, "tagLimit")
     self.exec()
Exemplo n.º 12
0
    def __init__(self,
                 mw: aqt.main.AnkiQt,
                 syncer: MediaSyncer,
                 close_when_done: bool = False) -> None:
        super().__init__(mw)
        self.mw = mw
        self._syncer = syncer
        self._close_when_done = close_when_done
        self.form = aqt.forms.synclog.Ui_Dialog()
        self.form.setupUi(self)
        self.setWindowTitle(tr(TR.SYNC_MEDIA_LOG_TITLE))
        disable_help_button(self)
        self.abort_button = QPushButton(tr(TR.SYNC_ABORT_BUTTON))
        qconnect(self.abort_button.clicked, self._on_abort)
        self.abort_button.setAutoDefault(False)
        self.form.buttonBox.addButton(self.abort_button,
                                      QDialogButtonBox.ActionRole)
        self.abort_button.setHidden(not self._syncer.is_syncing())

        gui_hooks.media_sync_did_progress.append(self._on_log_entry)
        gui_hooks.media_sync_did_start_or_stop.append(self._on_start_stop)

        self.form.plainTextEdit.setPlainText("\n".join(
            self._entry_to_text(x) for x in syncer.entries()))
        self.form.plainTextEdit.moveCursor(QTextCursor.End)
        self.show()
Exemplo n.º 13
0
    def __init__(self, addonsManager: AddonManager) -> None:
        self.mgr = addonsManager
        self.mw = addonsManager.mw

        super().__init__(self.mw)

        f = self.form = aqt.forms.addons.Ui_Dialog()
        f.setupUi(self)
        qconnect(f.getAddons.clicked, self.onGetAddons)
        qconnect(f.installFromFile.clicked, self.onInstallFiles)
        qconnect(f.checkForUpdates.clicked, self.check_for_updates)
        qconnect(f.toggleEnabled.clicked, self.onToggleEnabled)
        qconnect(f.viewPage.clicked, self.onViewPage)
        qconnect(f.viewFiles.clicked, self.onViewFiles)
        qconnect(f.delete_2.clicked, self.onDelete)
        qconnect(f.config.clicked, self.onConfig)
        qconnect(self.form.addonList.itemDoubleClicked, self.onConfig)
        qconnect(self.form.addonList.currentRowChanged,
                 self._onAddonItemSelected)
        self.setWindowTitle(tr(TR.ADDONS_WINDOW_TITLE))
        disable_help_button(self)
        self.setAcceptDrops(True)
        self.redrawAddons()
        restoreGeom(self, "addons")
        gui_hooks.addons_dialog_will_show(self)
        self.show()
Exemplo n.º 14
0
    def onTargetDeck(self) -> None:
        from aqt.tagedit import TagEdit

        t = self.current_template()
        d = QDialog(self)
        d.setWindowTitle("Anki")
        disable_help_button(d)
        d.setMinimumWidth(400)
        l = QVBoxLayout()
        lab = QLabel(
            tr(TR.CARD_TEMPLATES_ENTER_DECK_TO_PLACE_NEW, val="%s") %
            self.current_template()["name"])
        lab.setWordWrap(True)
        l.addWidget(lab)
        te = TagEdit(d, type=1)
        te.setCol(self.col)
        l.addWidget(te)
        if t["did"]:
            te.setText(self.col.decks.get(t["did"])["name"])
            te.selectAll()
        bb = QDialogButtonBox(QDialogButtonBox.Close)
        qconnect(bb.rejected, d.close)
        l.addWidget(bb)
        d.setLayout(l)
        d.exec_()
        self.change_tracker.mark_basic()
        if not te.text().strip():
            t["did"] = None
        else:
            t["did"] = self.col.decks.id(te.text())
Exemplo n.º 15
0
 def __init__(self,
              mw: AnkiQt,
              nt: NotetypeDict,
              parent: Optional[QWidget] = None) -> None:
     QDialog.__init__(self, parent or mw)
     self.mw = mw
     self.col = self.mw.col
     self.mm = self.mw.col.models
     self.model = nt
     self.mm._remove_from_cache(self.model["id"])
     self.mw.checkpoint(tr.editing_fields())
     self.change_tracker = ChangeTracker(self.mw)
     self.form = aqt.forms.fields.Ui_Dialog()
     self.form.setupUi(self)
     self.setWindowTitle(
         without_unicode_isolation(
             tr.fields_fields_for(val=self.model["name"])))
     disable_help_button(self)
     self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
     self.form.buttonBox.button(
         QDialogButtonBox.Cancel).setAutoDefault(False)
     self.form.buttonBox.button(QDialogButtonBox.Save).setAutoDefault(False)
     self.currentIdx: Optional[int] = None
     self.fillFields()
     self.setupSignals()
     self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
     self.form.fieldList.dropEvent = self.onDrop  # type: ignore[assignment]
     self.form.fieldList.setCurrentRow(0)
     self.exec_()
Exemplo n.º 16
0
    def __init__(self, mw, first=False, search="", deck=None):
        QDialog.__init__(self, mw)
        self.mw = mw
        self.deck = deck or self.mw.col.decks.current()
        self.search = search
        self.form = aqt.forms.dyndconf.Ui_Dialog()
        self.form.setupUi(self)
        if first:
            label = tr(TR.DECKS_BUILD)
        else:
            label = tr(TR.ACTIONS_REBUILD)
        self.ok = self.form.buttonBox.addButton(label, QDialogButtonBox.AcceptRole)
        self.mw.checkpoint(tr(TR.ACTIONS_OPTIONS))
        disable_help_button(self)
        self.setWindowModality(Qt.WindowModal)
        qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("filtered-decks"))
        self.setWindowTitle(
            without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck["name"]))
        )
        restoreGeom(self, "dyndeckconf")
        self.initialSetup()
        self.loadConf()
        if search:
            self.form.search.setText(search + " is:due")
            self.form.search_2.setText(search + " is:new")
        self.form.search.selectAll()

        if self.mw.col.schedVer() == 1:
            self.form.secondFilter.setVisible(False)

        self.show()
        self.exec_()
        saveGeom(self, "dyndeckconf")
Exemplo n.º 17
0
 def __init__(self, mw: AnkiQt, importer: Any) -> None:
     QDialog.__init__(self, mw, Qt.Window)
     self.mw = mw
     self.importer = importer
     self.frm = aqt.forms.importing.Ui_ImportDialog()
     self.frm.setupUi(self)
     qconnect(
         self.frm.buttonBox.button(QDialogButtonBox.Help).clicked,
         self.helpRequested)
     disable_help_button(self)
     self.setupMappingFrame()
     self.setupOptions()
     self.modelChanged()
     self.frm.autoDetect.setVisible(self.importer.needDelimiter)
     gui_hooks.current_note_type_did_change.append(self.modelChanged)
     qconnect(self.frm.autoDetect.clicked, self.onDelimiter)
     self.updateDelimiterButtonText()
     self.frm.allowHTML.setChecked(self.mw.pm.profile.get(
         "allowHTML", True))
     qconnect(self.frm.importMode.currentIndexChanged,
              self.importModeChanged)
     self.frm.importMode.setCurrentIndex(
         self.mw.pm.profile.get("importMode", 1))
     self.frm.tagModified.setText(self.mw.pm.profile.get("tagModified", ""))
     self.frm.tagModified.setCol(self.mw.col)
     # import button
     b = QPushButton(tr.actions_import())
     self.frm.buttonBox.addButton(b, QDialogButtonBox.AcceptRole)
     self.exec_()
Exemplo n.º 18
0
 def __init__(
     self,
     parent: QWidget,
     tags: Sequence[CustomStudyDefaults.Tag],
     on_success: Callable[[list[str], list[str]], None],
 ) -> None:
     "Ask user to select tags. on_success() will be called with selected included and excluded tags."
     QDialog.__init__(self, parent, Qt.WindowType.Window)
     self.tags = tags
     self.form = aqt.forms.taglimit.Ui_Dialog()
     self.form.setupUi(self)
     self.on_success = on_success
     disable_help_button(self)
     s = QShortcut(
         QKeySequence("ctrl+d"),
         self.form.activeList,
         context=Qt.ShortcutContext.WidgetShortcut,
     )
     qconnect(s.activated, self.form.activeList.clearSelection)
     s = QShortcut(
         QKeySequence("ctrl+d"),
         self.form.inactiveList,
         context=Qt.ShortcutContext.WidgetShortcut,
     )
     qconnect(s.activated, self.form.inactiveList.clearSelection)
     self.build_tag_lists()
     restoreGeom(self, "tagLimit")
     self.open()
Exemplo n.º 19
0
 def __init__(self, mw: AnkiQt, parent: Optional[QWidget] = None) -> None:
     self.parent_ = parent or mw
     self.mw = mw
     self.col = mw.col
     QDialog.__init__(self, self.parent_, Qt.Window)
     self.model = None
     self.dialog = aqt.forms.addmodel.Ui_Dialog()
     self.dialog.setupUi(self)
     disable_help_button(self)
     # standard models
     self.notetypes: list[Union[NotetypeDict, Callable[[Collection],
                                                       NotetypeDict]]] = []
     for (name, func) in stdmodels.get_stock_notetypes(self.col):
         item = QListWidgetItem(tr.notetypes_add(val=name))
         self.dialog.models.addItem(item)
         self.notetypes.append(func)
     # add copies
     for m in sorted(self.col.models.all(), key=itemgetter("name")):
         item = QListWidgetItem(tr.notetypes_clone(val=m["name"]))
         self.dialog.models.addItem(item)
         self.notetypes.append(m)
     self.dialog.models.setCurrentRow(0)
     # the list widget will swallow the enter key
     s = QShortcut(QKeySequence("Return"), self)
     qconnect(s.activated, self.accept)
     # help
     qconnect(self.dialog.buttonBox.helpRequested, self.onHelp)
Exemplo n.º 20
0
 def _onHtmlEdit(self, field):
     d = QDialog(self.widget, Qt.Window)
     form = aqt.forms.edithtml.Ui_Dialog()
     form.setupUi(d)
     restoreGeom(d, "htmlEditor")
     disable_help_button(d)
     qconnect(form.buttonBox.helpRequested,
              lambda: openHelp("editing?id=features"))
     form.textEdit.setPlainText(self.note.fields[field])
     d.show()
     form.textEdit.moveCursor(QTextCursor.End)
     d.exec_()
     html = form.textEdit.toPlainText()
     if html.find(">") > -1:
         # filter html through beautifulsoup so we can strip out things like a
         # leading </div>
         html_escaped = self.mw.col.media.escape_media_filenames(html)
         with warnings.catch_warnings():
             warnings.simplefilter("ignore", UserWarning)
             html_escaped = str(BeautifulSoup(html_escaped, "html.parser"))
             html = self.mw.col.media.escape_media_filenames(html_escaped,
                                                             unescape=True)
     self.note.fields[field] = html
     if not self.addMode:
         self.note.flush()
     self.loadNote(focusTo=field)
     saveGeom(d, "htmlEditor")
Exemplo n.º 21
0
    def __init__(self, mw: aqt.main.AnkiQt, report: EmptyCardsReport) -> None:
        super().__init__(mw)
        self.mw = mw.weakref()
        self.report = report
        self.form = aqt.forms.emptycards.Ui_Dialog()
        self.form.setupUi(self)
        restoreGeom(self, "emptycards")
        self.setWindowTitle(tr(TR.EMPTY_CARDS_WINDOW_TITLE))
        disable_help_button(self)
        self.form.keep_notes.setText(tr(
            TR.EMPTY_CARDS_PRESERVE_NOTES_CHECKBOX))
        self.form.webview.title = "empty cards"
        self.form.webview.set_bridge_command(self._on_note_link_clicked, self)

        gui_hooks.empty_cards_will_show(self)

        # make the note ids clickable
        html = re.sub(
            r"\[anki:nid:(\d+)\]",
            "<a href=# onclick=\"pycmd('nid:\\1'); return false\">\\1</a>: ",
            report.report,
        )
        style = "<style>.allempty { color: red; }</style>"
        self.form.webview.stdHtml(style + html, context=self)

        def on_finished(code: Any) -> None:
            saveGeom(self, "emptycards")

        qconnect(self.finished, on_finished)

        self._delete_button = self.form.buttonBox.addButton(
            tr(TR.EMPTY_CARDS_DELETE_BUTTON), QDialogButtonBox.ActionRole)
        self._delete_button.setAutoDefault(False)
        self._delete_button.clicked.connect(self._on_delete)
Exemplo n.º 22
0
    def __init__(
        self,
        mw: AnkiQt,
        search: Optional[str] = None,
        search_2: Optional[str] = None,
        deck: Optional[Deck] = None,
    ) -> None:
        """If 'deck' is an existing filtered deck, load and modify its settings.
        Otherwise, build a new one and derive settings from the current deck.
        """

        QDialog.__init__(self, mw)
        self.mw = mw
        self.did: Optional[int] = None
        self.form = aqt.forms.dyndconf.Ui_Dialog()
        self.form.setupUi(self)
        self.mw.checkpoint(tr(TR.ACTIONS_OPTIONS))
        self.initialSetup()
        self.old_deck = self.mw.col.decks.current()

        if deck and deck["dyn"]:
            # modify existing dyn deck
            label = tr(TR.ACTIONS_REBUILD)
            self.deck = deck
            self.loadConf()
        elif self.old_deck["dyn"]:
            # create new dyn deck from other dyn deck
            label = tr(TR.DECKS_BUILD)
            self.loadConf(deck=self.old_deck)
            self.new_dyn_deck()
        else:
            # create new dyn deck from regular deck
            label = tr(TR.DECKS_BUILD)
            self.new_dyn_deck()
            self.loadConf()
            self.set_default_searches(self.old_deck["name"])

        self.form.name.setText(self.deck["name"])
        self.form.name.setPlaceholderText(self.deck["name"])
        self.set_custom_searches(search, search_2)
        qconnect(self.form.search_button.clicked, self.on_search_button)
        qconnect(self.form.search_button_2.clicked, self.on_search_button_2)
        color = theme_manager.color(colors.LINK)
        self.setStyleSheet(
            f"""QPushButton[flat=true] {{ text-align: left; color: {color}; padding: 0; border: 0 }}
            QPushButton[flat=true]:hover {{ text-decoration: underline }}""")
        disable_help_button(self)
        self.setWindowModality(Qt.WindowModal)
        qconnect(self.form.buttonBox.helpRequested,
                 lambda: openHelp(HelpPage.FILTERED_DECK))
        self.setWindowTitle(
            without_unicode_isolation(
                tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck["name"])))
        self.form.buttonBox.button(QDialogButtonBox.Ok).setText(label)
        if self.mw.col.schedVer() == 1:
            self.form.secondFilter.setVisible(False)
        restoreGeom(self, "dyndeckconf")

        self.show()
Exemplo n.º 23
0
 def __init__(self, parent: QWidget) -> None:
     QDialog.__init__(self, parent)
     disable_help_button(self)
     self.form = aqt.forms.progress.Ui_Dialog()
     self.form.setupUi(self)
     self._closingDown = False
     self.wantCancel = False
     # required for smooth progress bars
     self.form.progressBar.setStyleSheet("QProgressBar::chunk { width: 1px; }")
Exemplo n.º 24
0
    def _on_finished(self, future: Future) -> None:
        self._set_progress_enabled(False)
        self.mw.progress.finish()
        self.progress_dialog = None

        exc = future.exception()
        if isinstance(exc, Interrupted):
            return

        output: CheckMediaResponse = future.result()
        report = output.report

        # show report and offer to delete
        diag = QDialog(self.mw)
        diag.setWindowTitle(tr.media_check_window_title())
        disable_help_button(diag)
        layout = QVBoxLayout(diag)
        diag.setLayout(layout)
        text = QPlainTextEdit()
        text.setReadOnly(True)
        text.setPlainText(report)
        text.setWordWrapMode(QTextOption.WrapMode.NoWrap)
        layout.addWidget(text)
        box = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
        layout.addWidget(box)

        if output.unused:
            b = QPushButton(tr.media_check_delete_unused())
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.ButtonRole.RejectRole)
            qconnect(b.clicked, lambda c: self._on_trash_files(output.unused))

        if output.missing:
            if any(map(lambda x: x.startswith("latex-"), output.missing)):
                b = QPushButton(tr.media_check_render_latex())
                b.setAutoDefault(False)
                box.addButton(b, QDialogButtonBox.ButtonRole.RejectRole)
                qconnect(b.clicked, self._on_render_latex)

        if output.have_trash:
            b = QPushButton(tr.media_check_empty_trash())
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.ButtonRole.RejectRole)
            qconnect(b.clicked, lambda c: self._on_empty_trash())

            b = QPushButton(tr.media_check_restore_trash())
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.ButtonRole.RejectRole)
            qconnect(b.clicked, lambda c: self._on_restore_trash())

        qconnect(box.rejected, diag.reject)
        diag.setMinimumHeight(400)
        diag.setMinimumWidth(500)
        restoreGeom(diag, "checkmediadb")
        diag.exec()
        saveGeom(diag, "checkmediadb")
Exemplo n.º 25
0
 def __init__(self, parent: QWidget, mw: AnkiQt, on_close: Callable[[], None]):
     super().__init__(None, Qt.Window)
     self._open = True
     self._parent = parent
     self._close_callback = on_close
     self.mw = mw
     icon = QIcon()
     icon.addPixmap(QPixmap(":/icons/anki.png"), QIcon.Normal, QIcon.Off)
     disable_help_button(self)
     self.setWindowIcon(icon)
Exemplo n.º 26
0
 def __init__(self, parent: QWidget, mw: AnkiQt,
              on_close: Callable[[], None]) -> None:
     super().__init__(None, Qt.WindowType.Window)
     mw.garbage_collect_on_dialog_finish(self)
     self._open = True
     self._parent = parent
     self._close_callback = on_close
     self.mw = mw
     disable_help_button(self)
     setWindowIcon(self)
Exemplo n.º 27
0
    def _on_finished(self, future: Future) -> None:
        self._set_progress_enabled(False)
        self.mw.progress.finish()
        self.progress_dialog = None

        exc = future.exception()
        if isinstance(exc, Interrupted):
            return

        output: CheckMediaOut = future.result()
        report = output.report

        # show report and offer to delete
        diag = QDialog(self.mw)
        diag.setWindowTitle(tr(TR.MEDIA_CHECK_WINDOW_TITLE))
        disable_help_button(diag)
        layout = QVBoxLayout(diag)
        diag.setLayout(layout)
        text = QTextEdit()
        text.setReadOnly(True)
        text.setPlainText(report)
        layout.addWidget(text)
        box = QDialogButtonBox(QDialogButtonBox.Close)
        layout.addWidget(box)

        if output.unused:
            b = QPushButton(tr(TR.MEDIA_CHECK_DELETE_UNUSED))
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.RejectRole)
            qconnect(b.clicked, lambda c: self._on_trash_files(output.unused))

        if output.missing:
            if any(map(lambda x: x.startswith("latex-"), output.missing)):
                b = QPushButton(tr(TR.MEDIA_CHECK_RENDER_LATEX))
                b.setAutoDefault(False)
                box.addButton(b, QDialogButtonBox.RejectRole)
                qconnect(b.clicked, self._on_render_latex)

        if output.have_trash:
            b = QPushButton(tr(TR.MEDIA_CHECK_EMPTY_TRASH))
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.RejectRole)
            qconnect(b.clicked, lambda c: self._on_empty_trash())

            b = QPushButton(tr(TR.MEDIA_CHECK_RESTORE_TRASH))
            b.setAutoDefault(False)
            box.addButton(b, QDialogButtonBox.RejectRole)
            qconnect(b.clicked, lambda c: self._on_restore_trash())

        qconnect(box.rejected, diag.reject)
        diag.setMinimumHeight(400)
        diag.setMinimumWidth(500)
        restoreGeom(diag, "checkmediadb")
        diag.exec_()
        saveGeom(diag, "checkmediadb")
Exemplo n.º 28
0
 def __init__(self, mw: aqt.AnkiQt) -> None:
     QDialog.__init__(self, mw)
     self.mw = mw
     self.deck = self.mw.col.decks.current()
     self.conf = self.mw.col.decks.get_config(self.deck["conf"])
     self.form = f = aqt.forms.customstudy.Ui_Dialog()
     self.created_custom_study = False
     f.setupUi(self)
     disable_help_button(self)
     self.setupSignals()
     f.radioNew.click()
     self.open()
Exemplo n.º 29
0
    def __init__(
        self,
        mw: AnkiQt,
        nt: NotetypeDict,
        parent: Optional[QWidget] = None,
        open_at: int = 0,
    ) -> None:
        QDialog.__init__(self, parent or mw)
        mw.garbage_collect_on_dialog_finish(self)
        self.mw = mw
        self.col = self.mw.col
        self.mm = self.mw.col.models
        self.model = nt
        self.mm._remove_from_cache(self.model["id"])
        self.change_tracker = ChangeTracker(self.mw)

        self.setWindowTitle(
            without_unicode_isolation(
                tr.fields_fields_for(val=self.model["name"])))

        if os.getenv("ANKI_EXPERIMENTAL_FIELDS_WEB"):
            form = aqt.forms.fields_web.Ui_Dialog()
            form.setupUi(self)

            self.webview = form.webview
            self.webview.set_title("fields")

            self.show()
            self.refresh()
            self.webview.set_bridge_command(self._on_bridge_cmd, self)
            self.activateWindow()
            return

        self.form = aqt.forms.fields.Ui_Dialog()
        self.form.setupUi(self)
        self.webview = None

        disable_help_button(self)
        self.form.buttonBox.button(
            QDialogButtonBox.StandardButton.Help).setAutoDefault(False)
        self.form.buttonBox.button(
            QDialogButtonBox.StandardButton.Cancel).setAutoDefault(False)
        self.form.buttonBox.button(
            QDialogButtonBox.StandardButton.Save).setAutoDefault(False)
        self.currentIdx: Optional[int] = None
        self.fillFields()
        self.setupSignals()
        self.form.fieldList.setDragDropMode(
            QAbstractItemView.DragDropMode.InternalMove)
        self.form.fieldList.dropEvent = self.onDrop  # type: ignore[assignment]
        self.form.fieldList.setCurrentRow(open_at)
        self.exec()
Exemplo n.º 30
0
 def onBrowserDisplay(self) -> None:
     d = QDialog()
     disable_help_button(d)
     f = aqt.forms.browserdisp.Ui_Dialog()
     f.setupUi(d)
     t = self.current_template()
     f.qfmt.setText(t.get("bqfmt", ""))
     f.afmt.setText(t.get("bafmt", ""))
     if t.get("bfont"):
         f.overrideFont.setChecked(True)
     f.font.setCurrentFont(QFont(t.get("bfont", "Arial")))
     f.fontSize.setValue(t.get("bsize", 12))
     qconnect(f.buttonBox.accepted, lambda: self.onBrowserDisplayOk(f))
     d.exec_()