prefs and dialog tweaks

- manage prefs window so it only opens once, and gets closed properly
- provide silentlyClose shortcut to dialogmanager windows
This commit is contained in:
Damien Elmes 2017-09-10 15:15:12 +10:00
parent 5f68b62450
commit d3d96222bc
3 changed files with 32 additions and 13 deletions

View file

@ -38,20 +38,34 @@ except ImportError as e:
from anki.utils import checksum from anki.utils import checksum
# Dialog manager - manages non-modal windows # Dialog manager
########################################################################## ##########################################################################
# ensures only one copy of the window is open at once, and provides
# a way for dialogs to clean up asynchronously when collection closes
# to integrate a new window:
# - add it to _dialogs
# - define close behaviour, by either:
# -- setting silentlyClose=True to have it close immediately
# -- define a closeWithCallback() method
# - have the window opened via aqt.dialogs.open(<name>, self)
#- make preferences modal? cmd+q does wrong thing
from aqt import addcards, browser, editcurrent, stats, about, \
preferences
class DialogManager: class DialogManager:
def __init__(self): _dialogs = {
from aqt import addcards, browser, editcurrent, stats, about "AddCards": [addcards.AddCards, None],
self._dialogs = { "Browser": [browser.Browser, None],
"AddCards": [addcards.AddCards, None], "EditCurrent": [editcurrent.EditCurrent, None],
"Browser": [browser.Browser, None], "DeckStats": [stats.DeckStats, None],
"EditCurrent": [editcurrent.EditCurrent, None], "About": [about.show, None],
"DeckStats": [stats.DeckStats, None], "Preferences": [preferences.Preferences, None],
"About": [about.show, None], }
}
def open(self, name, *args): def open(self, name, *args):
(creator, instance) = self._dialogs[name] (creator, instance) = self._dialogs[name]
@ -89,7 +103,11 @@ class DialogManager:
# still waiting for others to close # still waiting for others to close
pass pass
instance.closeWithCallback(callback) if getattr(instance, "silentlyClose", False):
instance.close()
callback()
else:
instance.closeWithCallback(callback)
return True return True

View file

@ -784,8 +784,7 @@ title="%s" %s>%s</button>''' % (
aqt.dialogs.open("DeckStats", self) aqt.dialogs.open("DeckStats", self)
def onPrefs(self): def onPrefs(self):
import aqt.preferences aqt.dialogs.open("Preferences", self)
aqt.preferences.Preferences(self)
def onNoteTypes(self): def onNoteTypes(self):
import aqt.models import aqt.models

View file

@ -22,6 +22,7 @@ class Preferences(QDialog):
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
self.form.buttonBox.helpRequested.connect(lambda: openHelp("profileprefs")) self.form.buttonBox.helpRequested.connect(lambda: openHelp("profileprefs"))
self.silentlyClose = True
self.setupLang() self.setupLang()
self.setupCollection() self.setupCollection()
self.setupNetwork() self.setupNetwork()
@ -40,6 +41,7 @@ class Preferences(QDialog):
self.mw.pm.save() self.mw.pm.save()
self.mw.reset() self.mw.reset()
self.done(0) self.done(0)
aqt.dialogs.markClosed("Preferences")
def reject(self): def reject(self):
self.accept() self.accept()