Пример #1
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_()
Пример #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_()
Пример #3
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()
Пример #4
0
 def __init__(
     self,
     mw: AnkiQt,
     note: Note,
     ord=0,
     parent: Optional[QWidget] = None,
     fill_empty: bool = False,
 ):
     QDialog.__init__(self, parent or mw, Qt.Window)
     mw.setupDialogGC(self)
     self.mw = aqt.mw
     self.note = note
     self.ord = ord
     self.col = self.mw.col.weakref()
     self.mm = self.mw.col.models
     self.model = note.model()
     self.templates = self.model["tmpls"]
     self.fill_empty_action_toggled = fill_empty
     self.night_mode_is_enabled = self.mw.pm.night_mode()
     self.mobile_emulation_enabled = False
     self.have_autoplayed = False
     self.mm._remove_from_cache(self.model["id"])
     self.mw.checkpoint(tr(TR.CARD_TEMPLATES_CARD_TYPES))
     self.change_tracker = ChangeTracker(self.mw)
     self.setupTopArea()
     self.setupMainArea()
     self.setupButtons()
     self.setupShortcuts()
     self.setWindowTitle(
         without_unicode_isolation(
             tr(TR.CARD_TEMPLATES_CARD_TYPES_FOR, val=self.model["name"])
         )
     )
     disable_help_button(self)
     v1 = QVBoxLayout()
     v1.addWidget(self.topArea)
     v1.addWidget(self.mainArea)
     v1.addLayout(self.buttons)
     v1.setContentsMargins(12, 12, 12, 12)
     self.setLayout(v1)
     gui_hooks.card_layout_will_show(self)
     self.redraw_everything()
     restoreGeom(self, "CardLayout")
     restoreSplitter(self.mainArea, "CardLayoutMainArea")
     self.setWindowModality(Qt.ApplicationModal)
     self.show()
     # take the focus away from the first input area when starting up,
     # as users tend to accidentally type into the template
     self.setFocus()
Пример #5
0
 def __init__(
     self,
     mw: AnkiQt,
     note: Note,
     ord=0,
     parent: Optional[QWidget] = None,
     fill_empty: bool = False,
 ):
     QDialog.__init__(self, parent or mw, Qt.Window)
     mw.setupDialogGC(self)
     self.mw = aqt.mw
     self.note = note
     self.ord = ord
     self.col = self.mw.col.weakref()
     self.mm = self.mw.col.models
     self.model = note.model()
     self.templates = self.model["tmpls"]
     self._want_fill_empty_on = fill_empty
     self.have_autoplayed = False
     self.mm._remove_from_cache(self.model["id"])
     self.mw.checkpoint(_("Card Types"))
     self.change_tracker = ChangeTracker(self.mw)
     self.setupTopArea()
     self.setupMainArea()
     self.setupButtons()
     self.setupShortcuts()
     self.setWindowTitle(_("Card Types for %s") % self.model["name"])
     v1 = QVBoxLayout()
     v1.addWidget(self.topArea)
     v1.addWidget(self.mainArea)
     v1.addLayout(self.buttons)
     v1.setContentsMargins(12, 12, 12, 12)
     self.setLayout(v1)
     gui_hooks.card_layout_will_show(self)
     self.redraw_everything()
     restoreGeom(self, "CardLayout")
     restoreSplitter(self.mainArea, "CardLayoutMainArea")
     self.setWindowModality(Qt.ApplicationModal)
     self.show()
     # take the focus away from the first input area when starting up,
     # as users tend to accidentally type into the template
     self.setFocus()
Пример #6
0
    def onDelete(self) -> None:
        if len(self.models) < 2:
            showInfo(tr.notetypes_please_add_another_note_type_first(),
                     parent=self)
            return
        idx = self.form.modelsList.currentRow()
        if self.models[idx].use_count:
            msg = tr.notetypes_delete_this_note_type_and_all()
        else:
            msg = tr.notetypes_delete_this_unused_note_type()
        if not askUser(msg, parent=self):
            return

        tracker = ChangeTracker(self.mw)
        if not tracker.mark_schema():
            return

        nt = self.current_notetype()
        remove_notetype(parent=self, notetype_id=nt["id"]).success(
            lambda _: self.refresh_list()).run_in_background()
Пример #7
0
def sticky_getter_and_setter(handled, message, context: Editor):
    if message == "get_stickies":
        model = context.note.model()
        stickies = [fld["sticky"] for fld in model["flds"]]

        return (True, stickies)

    cmd = message.split(":", 1)

    if cmd[0] in ["toggle_sticky"]:
        model = context.note.model()
        idx = int(cmd[1])

        fld = model["flds"][idx]

        change_tracker = ChangeTracker(context.mw)
        change_tracker.mark_basic()

        fld["sticky"] = not fld["sticky"]

        return (True, fld["sticky"])

    return handled