Add usage in models.py

This commit is contained in:
Henrik Giesel 2020-08-23 15:52:02 +02:00
parent 0d1b90e512
commit ad27e0149a

View File

@ -2,7 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from operator import itemgetter from operator import itemgetter
from typing import Any, List, Optional, Sequence from typing import Any, List, Tuple, Callable, Optional, Sequence
import aqt.clayout import aqt.clayout
from anki import stdmodels from anki import stdmodels
@ -49,20 +49,29 @@ class Models(QDialog):
self.model = None self.model = None
f = self.form f = self.form
box = f.buttonBox box = f.buttonBox
t = QDialogButtonBox.ActionRole
b = box.addButton(_("Add"), t) default_buttons = [
qconnect(b.clicked, self.onAdd) ("Add", self.onAdd),
b = box.addButton(_("Rename"), t) ("Rename", self.onRename),
qconnect(b.clicked, self.onRename) ("Delete", self.onDelete),
b = box.addButton(_("Delete"), t) ("Fields...", self.onFields),
qconnect(b.clicked, self.onDelete) ("Cards...", self.onCards),
("Options...", self.onAdvanced),
]
if self.fromMain: if self.fromMain:
b = box.addButton(_("Fields..."), t) default_buttons.extends([
qconnect(b.clicked, self.onFields) ("Fields...", self.onFields),
b = box.addButton(_("Cards..."), t) ("Cards...", self.onCards),
qconnect(b.clicked, self.onCards) ])
b = box.addButton(_("Options..."), t)
qconnect(b.clicked, self.onAdvanced) default_buttons.append(("Options...", self.onAdvanced))
gui_hooks.models_did_init_buttons(default_buttons, self)
for label, func in buttons:
button = box.addButton(_(label), QDialogButtonBox.ActionRole)
qconnect(button.clicked, func)
qconnect(f.modelsList.itemDoubleClicked, self.onRename) qconnect(f.modelsList.itemDoubleClicked, self.onRename)
def on_done(fut) -> None: def on_done(fut) -> None:
@ -72,12 +81,6 @@ class Models(QDialog):
f.modelsList.setCurrentRow(0) f.modelsList.setCurrentRow(0)
maybeHideClose(box) maybeHideClose(box)
def add_button(self, label: str, func: Callable[Any, None]) -> None:
box = self.form.buttonBox
button = box.addButton(_(label), QDialogButtonBox.ActionRole)
qconnect(button.clicked, func)
def onRename(self) -> None: def onRename(self) -> None:
nt = self.current_notetype() nt = self.current_notetype()
txt = getText(_("New name:"), default=nt["name"]) txt = getText(_("New name:"), default=nt["name"])