mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
profile switching & refactor closing
This commit is contained in:
parent
681c8dea9f
commit
9d26496ceb
1 changed files with 32 additions and 51 deletions
83
aqt/main.py
83
aqt/main.py
|
@ -100,7 +100,7 @@ class AnkiQt(QMainWindow):
|
||||||
f = self.profileForm = aqt.forms.profiles.Ui_Dialog()
|
f = self.profileForm = aqt.forms.profiles.Ui_Dialog()
|
||||||
f.setupUi(d)
|
f.setupUi(d)
|
||||||
d.connect(f.login, SIGNAL("clicked()"), self.onOpenProfile)
|
d.connect(f.login, SIGNAL("clicked()"), self.onOpenProfile)
|
||||||
d.connect(f.quit, SIGNAL("clicked()"), self.onQuit)
|
d.connect(f.quit, SIGNAL("clicked()"), self.app.closeAllWindows)
|
||||||
d.connect(f.add, SIGNAL("clicked()"), self.onAddProfile)
|
d.connect(f.add, SIGNAL("clicked()"), self.onAddProfile)
|
||||||
d.connect(f.delete_2, SIGNAL("clicked()"), self.onRemProfile)
|
d.connect(f.delete_2, SIGNAL("clicked()"), self.onRemProfile)
|
||||||
d.connect(d, SIGNAL("rejected()"), lambda: d.close())
|
d.connect(d, SIGNAL("rejected()"), lambda: d.close())
|
||||||
|
@ -197,8 +197,15 @@ Are you sure?"""):
|
||||||
else:
|
else:
|
||||||
self.moveToState("overview")
|
self.moveToState("overview")
|
||||||
|
|
||||||
def unloadProfile(self):
|
def unloadProfile(self, browser=True):
|
||||||
self.col = None
|
runHook("unloadProfile")
|
||||||
|
self.unloadCollection()
|
||||||
|
self.pm.profile['mainWindowGeom'] = self.saveGeometry()
|
||||||
|
self.pm.profile['mainWindowState'] = self.saveState()
|
||||||
|
self.pm.save()
|
||||||
|
self.close()
|
||||||
|
if browser:
|
||||||
|
self.showProfileManager()
|
||||||
|
|
||||||
# State machine
|
# State machine
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -352,7 +359,7 @@ title="%s">%s</button>''' % (
|
||||||
signal.signal(signal.SIGINT, self.onSigInt)
|
signal.signal(signal.SIGINT, self.onSigInt)
|
||||||
|
|
||||||
def onSigInt(self, signum, frame):
|
def onSigInt(self, signum, frame):
|
||||||
self.onQuit()
|
self.onClose()
|
||||||
|
|
||||||
def setupProgress(self):
|
def setupProgress(self):
|
||||||
self.progress = aqt.progress.ProgressManager(self)
|
self.progress = aqt.progress.ProgressManager(self)
|
||||||
|
@ -424,28 +431,6 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
self.moveToState("deckLoading")
|
self.moveToState("deckLoading")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Closing
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
def onClose(self):
|
|
||||||
"Called from a shortcut key. Close current active window."
|
|
||||||
aw = self.app.activeWindow()
|
|
||||||
if not aw or aw == self:
|
|
||||||
self.close()
|
|
||||||
else:
|
|
||||||
aw.close()
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
"Close and backup collection."
|
|
||||||
if not self.col:
|
|
||||||
return
|
|
||||||
runHook("deckClosing")
|
|
||||||
#self.col.close()
|
|
||||||
self.backup()
|
|
||||||
self.closeAllCollectionWindows()
|
|
||||||
self.col.close()
|
|
||||||
self.col = None
|
|
||||||
|
|
||||||
# Syncing
|
# Syncing
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -458,12 +443,8 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
def onSync(self, auto=False, reload=True):
|
def onSync(self, auto=False, reload=True):
|
||||||
if not auto or (self.pm.profile['syncKey'] and
|
if not auto or (self.pm.profile['syncKey'] and
|
||||||
self.pm.profile['autoSync']):
|
self.pm.profile['autoSync']):
|
||||||
self.closeAllCollectionWindows()
|
|
||||||
from aqt.sync import SyncManager
|
from aqt.sync import SyncManager
|
||||||
# close collection if loaded
|
self.unloadCollection()
|
||||||
if self.col:
|
|
||||||
self.col.close()
|
|
||||||
self.col = None
|
|
||||||
self.syncer = SyncManager(self, self.pm)
|
self.syncer = SyncManager(self, self.pm)
|
||||||
self.syncer.sync()
|
self.syncer.sync()
|
||||||
if reload:
|
if reload:
|
||||||
|
@ -475,6 +456,13 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
self.progress.setupDB(self.col.db)
|
self.progress.setupDB(self.col.db)
|
||||||
self.reset(guiOnly=True)
|
self.reset(guiOnly=True)
|
||||||
|
|
||||||
|
def unloadCollection(self):
|
||||||
|
if self.col:
|
||||||
|
self.backup()
|
||||||
|
self.closeAllCollectionWindows()
|
||||||
|
self.col.close()
|
||||||
|
self.col = None
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -526,26 +514,18 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
# App exit
|
# App exit
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def onQuit(self):
|
|
||||||
self.app.closeAllWindows()
|
|
||||||
|
|
||||||
def prepareForExit(self):
|
|
||||||
"Save config and window geometry."
|
|
||||||
runHook("quit")
|
|
||||||
self.pm.profile['mainWindowGeom'] = self.saveGeometry()
|
|
||||||
self.pm.profile['mainWindowState'] = self.saveState()
|
|
||||||
self.pm.save()
|
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
"User hit the X button, etc."
|
"User hit the X button, etc."
|
||||||
self.close()
|
event.accept()
|
||||||
# if self.pm.profile['syncOnProgramOpen']:
|
self.onClose()
|
||||||
# self.showBrowser = False
|
|
||||||
# self.syncDeck(interactive=False)
|
def onClose(self):
|
||||||
self.prepareForExit()
|
"Called from a shortcut key. Close current active window."
|
||||||
if event:
|
aw = self.app.activeWindow()
|
||||||
event.accept()
|
if not aw or aw == self:
|
||||||
self.app.quit()
|
self.unloadProfile(browser=False)
|
||||||
|
else:
|
||||||
|
aw.close()
|
||||||
|
|
||||||
# Dockable widgets
|
# Dockable widgets
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -755,7 +735,8 @@ Please choose a new deck name:"""))
|
||||||
m = self.form
|
m = self.form
|
||||||
s = SIGNAL("triggered()")
|
s = SIGNAL("triggered()")
|
||||||
#self.connect(m.actionDownloadSharedPlugin, s, self.onGetSharedPlugin)
|
#self.connect(m.actionDownloadSharedPlugin, s, self.onGetSharedPlugin)
|
||||||
self.connect(m.actionExit, s, self.onQuit)
|
self.connect(m.actionSwitchProfile, s, self.unloadProfile)
|
||||||
|
self.connect(m.actionExit, s, self.onClose)
|
||||||
self.connect(m.actionPreferences, s, self.onPrefs)
|
self.connect(m.actionPreferences, s, self.onPrefs)
|
||||||
self.connect(m.actionCstats, s, self.onCardStats)
|
self.connect(m.actionCstats, s, self.onCardStats)
|
||||||
self.connect(m.actionAbout, s, self.onAbout)
|
self.connect(m.actionAbout, s, self.onAbout)
|
||||||
|
@ -800,7 +781,7 @@ This can be because the \
|
||||||
clock is slow or fast, because the date is set incorrectly, or because \
|
clock is slow or fast, because the date is set incorrectly, or because \
|
||||||
the timezone or daylight savings information is incorrect. Please correct \
|
the timezone or daylight savings information is incorrect. Please correct \
|
||||||
the problem and restart Anki.""")
|
the problem and restart Anki.""")
|
||||||
self.onQuit()
|
self.onClose()
|
||||||
|
|
||||||
# Schema modifications
|
# Schema modifications
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue