Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def __init__(self, mw: aqt.main.AnkiQt, report: EmptyCardsReport) -> None:
        super().__init__(mw)
        self.mw = mw.weakref()
        self.mw.garbage_collect_on_dialog_finish(self)
        self.report = report
        self.form = aqt.forms.emptycards.Ui_Dialog()
        self.form.setupUi(self)
        restoreGeom(self, "emptycards")
        self.setWindowTitle(tr.empty_cards_window_title())
        disable_help_button(self)
        self.form.keep_notes.setText(tr.empty_cards_preserve_notes_checkbox())
        self.form.webview.set_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:
            self.form.webview.cleanup()
            self.form.webview = None
            saveGeom(self, "emptycards")

        qconnect(self.finished, on_finished)

        self._delete_button = self.form.buttonBox.addButton(
            tr.empty_cards_delete_button(), QDialogButtonBox.ButtonRole.ActionRole
        )
        self._delete_button.setAutoDefault(False)
        qconnect(self._delete_button.clicked, self._on_delete)