Ejemplo n.º 1
0
    def onModelChange(self) -> None:
        from aqt.studydeck import StudyDeck

        current = self.deck.models.current()["name"]
        # edit button
        edit = QPushButton(tr(TR.QT_MISC_MANAGE),
                           clicked=self.onEdit)  # type: ignore

        def nameFunc() -> List[str]:
            return sorted(self.deck.models.allNames())

        ret = StudyDeck(
            self.mw,
            names=nameFunc,
            accept=tr(TR.ACTIONS_CHOOSE),
            title=tr(TR.QT_MISC_CHOOSE_NOTE_TYPE),
            help=HelpPage.NOTE_TYPE,
            current=current,
            parent=self.widget,
            buttons=[edit],
            cancel=True,
            geomKey="selectModel",
        )
        if not ret.name:
            return
        m = self.deck.models.byName(ret.name)
        self.deck.conf["curModel"] = m["id"]
        cdeck = self.deck.decks.current()
        cdeck["mid"] = m["id"]
        self.deck.decks.save(cdeck)
        gui_hooks.current_note_type_did_change(current)
        self.mw.reset()
Ejemplo n.º 2
0
    def onModelChange(self) -> None:
        from aqt.studydeck import StudyDeck

        current = self.deck.models.current()["name"]
        # edit button
        edit = QPushButton(_("Manage"), clicked=self.onEdit)  # type: ignore

        def nameFunc():
            return sorted(self.deck.models.allNames())

        ret = StudyDeck(
            self.mw,
            names=nameFunc,
            accept=_("Choose"),
            title=_("Choose Note Type"),
            help="_notes",
            current=current,
            parent=self.widget,
            buttons=[edit],
            cancel=True,
            geomKey="selectModel",
        )
        if not ret.name:
            return
        m = self.deck.models.byName(ret.name)
        self.deck.conf["curModel"] = m["id"]
        cdeck = self.deck.decks.current()
        cdeck["mid"] = m["id"]
        self.deck.decks.save(cdeck)
        gui_hooks.current_note_type_did_change(current)
        self.mw.reset()
Ejemplo n.º 3
0
    def onModelChange(self) -> None:
        from aqt.studydeck import StudyDeck

        current = self.deck.models.current()["name"]
        # edit button
        edit = QPushButton(tr.qt_misc_manage(),
                           clicked=self.onEdit)  # type: ignore

        def nameFunc() -> List[str]:
            return [nt.name for nt in self.deck.models.all_names_and_ids()]

        ret = StudyDeck(
            self.mw,
            names=nameFunc,
            accept=tr.actions_choose(),
            title=tr.qt_misc_choose_note_type(),
            help=HelpPage.NOTE_TYPE,
            current=current,
            parent=self._widget,
            buttons=[edit],
            cancel=True,
            geomKey="selectModel",
        )
        if not ret.name:
            return
        m = self.deck.models.by_name(ret.name)
        self.deck.conf["curModel"] = m["id"]
        cdeck = self.deck.decks.current()
        cdeck["mid"] = m["id"]
        self.deck.decks.save(cdeck)
        gui_hooks.current_note_type_did_change(current)
        self.mw.reset()
    def onDeckRadioClicked(self):
        sender: Union[QRadioButton, QShortcut] = QObject.sender(self)
        button: QRadioButton = sender
        if isinstance(sender, QShortcut):
            key = sender.key().toString()
            radio_btn_idx = int(key.split("+")[1]) - 1
            button = self.radioButtons[radio_btn_idx]

        button.setChecked(True)
        current = self.deck.models.current()["name"]

        buttonLabel = button.text()
        modelName = RE_BTN.match(buttonLabel).group(1)
        model = self.deck.models.byName(modelName)

        if model is None:
            # then we have a note type added in the config that doesn't exist
            showWarning(
                "The note type '{}' has been set in the config, but doesn't actually exist.\n"
                "Please adapt the addon config for existing note types.".
                format(modelName))
            button.setChecked(False)
            self.mw.reset()
            return

        self.deck.conf["curModel"] = model["id"]
        cdeck = self.deck.decks.current()
        cdeck["mid"] = model["id"]
        self.deck.decks.save(cdeck)
        gui_hooks.current_note_type_did_change(current)
        # Let AddCards redraw the fields of this note type
        self.parent.onModelChange()
        # Let the parent refresh text on model selector button
        self.updateModels()
Ejemplo n.º 5
0
 def callback(ret: StudyDeck) -> None:
     if not ret.name:
         return
     m = self.deck.models.by_name(ret.name)
     self.deck.conf["curModel"] = m["id"]
     cdeck = self.deck.decks.current()
     cdeck["mid"] = m["id"]
     self.deck.decks.save(cdeck)
     gui_hooks.current_note_type_did_change(current)
     self.mw.reset()
Ejemplo n.º 6
0
    def onModelChange(self):
        """Open Choose Note Type window"""
        from aqt.studydeck import StudyDeck

        current = self.deck.models.current()["name"]
        # edit button
        edit = QPushButton(tr(TR.QT_MISC_MANAGE),
                           clicked=self.onEdit)  # type: ignore

        def nameFunc() -> List[str]:
            return sorted(self.deck.models.allNames())

        ret = StudyDeck(
            self.mw,
            names=nameFunc,
            accept=tr(TR.ACTIONS_CHOOSE),
            title=tr(TR.QT_MISC_CHOOSE_NOTE_TYPE),
            help=HelpPage.NOTE_TYPE,
            current=current,
            parent=self._widget,
            buttons=[edit],
            cancel=True,
            geomKey="selectModel",
        )
        if not ret.name:
            return
        m = self.deck.models.byName(ret.name)
        self.deck.conf["curModel"] = m["id"]
        cdeck = self.deck.decks.current()
        cdeck["mid"] = m["id"]
        # New line:
        self.deck.decks.save(cdeck)
        # Following code was in original method
        gui_hooks.current_note_type_did_change(current)
        self.parent.onModelChange()
        self.updateModels()
        self.parent.setAndFocusNote(self.parent.editor.note)