diff --git a/aqt/__init__.py b/aqt/__init__.py index a54b841c8..be49c7d56 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -38,20 +38,34 @@ 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(, 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 = { - "AddCards": [addcards.AddCards, None], - "Browser": [browser.Browser, None], - "EditCurrent": [editcurrent.EditCurrent, None], - "DeckStats": [stats.DeckStats, None], - "About": [about.show, None], - } + _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): (creator, instance) = self._dialogs[name] @@ -89,7 +103,11 @@ class DialogManager: # still waiting for others to close pass - instance.closeWithCallback(callback) + if getattr(instance, "silentlyClose", False): + instance.close() + callback() + else: + instance.closeWithCallback(callback) return True diff --git a/aqt/main.py b/aqt/main.py index c79fafd61..cef5d47df 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -784,8 +784,7 @@ title="%s" %s>%s''' % ( 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 diff --git a/aqt/preferences.py b/aqt/preferences.py index ba3342fdb..b08f37058 100644 --- a/aqt/preferences.py +++ b/aqt/preferences.py @@ -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()