mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
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:
parent
5f68b62450
commit
d3d96222bc
3 changed files with 32 additions and 13 deletions
|
@ -38,19 +38,33 @@ 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
|
|
||||||
self._dialogs = {
|
|
||||||
"AddCards": [addcards.AddCards, None],
|
"AddCards": [addcards.AddCards, None],
|
||||||
"Browser": [browser.Browser, None],
|
"Browser": [browser.Browser, None],
|
||||||
"EditCurrent": [editcurrent.EditCurrent, None],
|
"EditCurrent": [editcurrent.EditCurrent, None],
|
||||||
"DeckStats": [stats.DeckStats, None],
|
"DeckStats": [stats.DeckStats, None],
|
||||||
"About": [about.show, None],
|
"About": [about.show, None],
|
||||||
|
"Preferences": [preferences.Preferences, None],
|
||||||
}
|
}
|
||||||
|
|
||||||
def open(self, name, *args):
|
def open(self, name, *args):
|
||||||
|
@ -89,6 +103,10 @@ class DialogManager:
|
||||||
# still waiting for others to close
|
# still waiting for others to close
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if getattr(instance, "silentlyClose", False):
|
||||||
|
instance.close()
|
||||||
|
callback()
|
||||||
|
else:
|
||||||
instance.closeWithCallback(callback)
|
instance.closeWithCallback(callback)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue