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,19 +38,33 @@ except ImportError as e:
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:
def __init__(self):
from aqt import addcards, browser, editcurrent, stats, about
self._dialogs = {
_dialogs = {
"AddCards": [addcards.AddCards, None],
"Browser": [browser.Browser, None],
"EditCurrent": [editcurrent.EditCurrent, None],
"DeckStats": [stats.DeckStats, None],
"About": [about.show, None],
"Preferences": [preferences.Preferences, None],
}
def open(self, name, *args):
@ -89,6 +103,10 @@ class DialogManager:
# still waiting for others to close
pass
if getattr(instance, "silentlyClose", False):
instance.close()
callback()
else:
instance.closeWithCallback(callback)
return True

View file

@ -784,8 +784,7 @@ title="%s" %s>%s</button>''' % (
aqt.dialogs.open("DeckStats", self)
def onPrefs(self):
import aqt.preferences
aqt.preferences.Preferences(self)
aqt.dialogs.open("Preferences", self)
def onNoteTypes(self):
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.Close).setAutoDefault(False)
self.form.buttonBox.helpRequested.connect(lambda: openHelp("profileprefs"))
self.silentlyClose = True
self.setupLang()
self.setupCollection()
self.setupNetwork()
@ -40,6 +41,7 @@ class Preferences(QDialog):
self.mw.pm.save()
self.mw.reset()
self.done(0)
aqt.dialogs.markClosed("Preferences")
def reject(self):
self.accept()