update mac build scripts, fix display problems on sync open/close

This commit is contained in:
Damien Elmes 2008-11-21 00:33:18 +09:00
parent d855c5c35e
commit ac6abd61c0
2 changed files with 21 additions and 22 deletions

View file

@ -35,6 +35,7 @@ class AnkiQt(QMainWindow):
self.config = config self.config = config
self.deck = None self.deck = None
self.state = "initial" self.state = "initial"
self.hideWelcome = False
self.views = [] self.views = []
self.setLang() self.setLang()
self.setupFonts() self.setupFonts()
@ -63,11 +64,8 @@ class AnkiQt(QMainWindow):
self.setUnifiedTitleAndToolBarOnMac(True) self.setUnifiedTitleAndToolBarOnMac(True)
pass pass
# load deck # load deck
try: if not self.maybeLoadLastDeck(args):
self.maybeLoadLastDeck(args)
finally:
self.setEnabled(True) self.setEnabled(True)
# the focus is not set while disabled, so fetch card again
self.moveToState("auto") self.moveToState("auto")
# run after-init hook # run after-init hook
try: try:
@ -399,28 +397,29 @@ class AnkiQt(QMainWindow):
def loadDeck(self, deckPath, sync=True): def loadDeck(self, deckPath, sync=True):
"Load a deck and update the user interface. Maybe sync." "Load a deck and update the user interface. Maybe sync."
# return None if error should be reported # return None if error should be reported
# return 0 to fail with no error
# return True on success # return True on success
try: try:
self.pauseViews() self.pauseViews()
if not self.saveAndClose(): if not self.saveAndClose(hideWelcome=True):
return 0 return 0
finally: finally:
self.restoreViews() self.restoreViews()
if not os.path.exists(deckPath): if not os.path.exists(deckPath):
self.moveToState("nodeck")
return return
error = False
try: try:
self.deck = DeckStorage.Deck(deckPath) self.deck = DeckStorage.Deck(deckPath)
except (IOError, ImportError): except (IOError, ImportError):
return error = True
except DeckWrongFormatError, e: except DeckWrongFormatError, e:
ui.utils.showInfo(_( ui.utils.showInfo(_(
"Please open this deck with Anki < 0.9.8.7 to upgrade.")) "Please open this deck with Anki < 0.9.8.7 to upgrade."))
return error = True
except DeckAccessError, e: except DeckAccessError, e:
if e.data.get('type') == 'inuse': error = True
ui.utils.showWarning(_("Unable to load the same deck twice.")) if error:
return 0 self.moveToState("nodeck")
return return
self.updateRecentFiles(self.deck.path) self.updateRecentFiles(self.deck.path)
if sync and self.config['syncOnLoad']: if sync and self.config['syncOnLoad']:
@ -445,6 +444,7 @@ class AnkiQt(QMainWindow):
else: else:
self.deck = None self.deck = None
return 0 return 0
self.moveToState("nodeck")
return True return True
def maybeLoadLastDeck(self, args): def maybeLoadLastDeck(self, args):
@ -461,9 +461,6 @@ class AnkiQt(QMainWindow):
for path in self.config['recentDeckPaths']: for path in self.config['recentDeckPaths']:
try: try:
r = self.loadDeck(path) r = self.loadDeck(path)
if r == 0:
# in use
continue
return r return r
except: except:
sys.stderr.write("Error loading last deck.\n") sys.stderr.write("Error loading last deck.\n")
@ -564,12 +561,13 @@ class AnkiQt(QMainWindow):
def onClose(self): def onClose(self):
cramming = self.deck is not None and self.deck.name() == "cram" cramming = self.deck is not None and self.deck.name() == "cram"
self.saveAndClose(exit=cramming) self.saveAndClose(hideWelcome=cramming)
if cramming: if cramming:
self.loadRecent(0) self.loadRecent(0)
def saveAndClose(self, exit=False): def saveAndClose(self, hideWelcome=False):
"(Auto)save and close. Prompt if necessary. True if okay to proceed." "(Auto)save and close. Prompt if necessary. True if okay to proceed."
self.hideWelcome = hideWelcome
if self.deck is not None: if self.deck is not None:
# sync (saving automatically) # sync (saving automatically)
if self.config['syncOnClose'] and self.deck.syncName: if self.config['syncOnClose'] and self.deck.syncName:
@ -593,12 +591,12 @@ class AnkiQt(QMainWindow):
# close # close
self.deck.rollback() self.deck.rollback()
self.deck = None self.deck = None
if not exit: if not hideWelcome:
self.moveToState("noDeck") self.moveToState("noDeck")
return True return True
def onNew(self): def onNew(self):
if not self.saveAndClose(exit=True): return if not self.saveAndClose(hideWelcome=True): return
self.deck = DeckStorage.Deck() self.deck = DeckStorage.Deck()
self.deck.addModel(BasicModel()) self.deck.addModel(BasicModel())
self.saveDeck() self.saveDeck()
@ -636,7 +634,7 @@ class AnkiQt(QMainWindow):
def onOpenOnline(self): def onOpenOnline(self):
self.ensureSyncParams() self.ensureSyncParams()
if not self.saveAndClose(exit=True): return if not self.saveAndClose(hideWelcome=True): return
self.deck = DeckStorage.Deck() self.deck = DeckStorage.Deck()
# ensure all changes come to us # ensure all changes come to us
self.deck.modified = 0 self.deck.modified = 0
@ -730,7 +728,7 @@ class AnkiQt(QMainWindow):
def closeEvent(self, event): def closeEvent(self, event):
"User hit the X button, etc." "User hit the X button, etc."
if not self.saveAndClose(exit=True): if not self.saveAndClose(hideWelcome=True):
event.ignore() event.ignore()
else: else:
self.prepareForExit() self.prepareForExit()
@ -1116,7 +1114,7 @@ class AnkiQt(QMainWindow):
self.deck.syncName = self.syncName self.deck.syncName = self.syncName
self.deck.s.flush() self.deck.s.flush()
self.deck.s.commit() self.deck.s.commit()
else: elif not self.hideWelcome:
self.moveToState("noDeck") self.moveToState("noDeck")
self.deckPath = None self.deckPath = None

View file

@ -58,7 +58,8 @@ OPTIONS = {
'plist': PLIST, 'plist': PLIST,
'iconfile': 'ankiqt/mac/anki.icns', 'iconfile': 'ankiqt/mac/anki.icns',
"includes": ["sip", "cgi", "encodings", "encodings.utf_8", "includes": ["sip", "cgi", "encodings", "encodings.utf_8",
"encodings.shift_jis", "_multibytecodec"], "encodings.shift_jis", "_multibytecodec",
"PyQt4.QtNetwork"],
'packages': ["sqlalchemy", "pysqlite2", "simplejson"], 'packages': ["sqlalchemy", "pysqlite2", "simplejson"],
'excludes': ['_gtkagg', '_tkagg', "_wxagg", 'excludes': ['_gtkagg', '_tkagg', "_wxagg",
"wx", "_wx", "wx", "_wx",