From 5ecb4bde49272549b2ef11eeacbf5a48864819b1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 28 Nov 2010 18:44:56 +0900 Subject: [PATCH] clear compiled plugin files; make some strings translatable --- ankiqt/ui/main.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 88e812f78..29fe8a869 100755 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -77,6 +77,17 @@ class AnkiQt(QMainWindow): # activate & raise is useful when run from the command line on osx self.activateWindow() self.raise_() + # check if we've been updated + if "version" not in self.config: + # could be new user, or upgrade from older version + # which didn't have version variable + self.appUpdated = "first" + elif self.config['version'] != ankiqt.appVersion: + self.appUpdated = self.config['version'] + else: + self.appUpdated = False + if self.appUpdated: + self.config['version'] = ankiqt.appVersion # plugins might be looking at this self.state = "noDeck" self.loadPlugins() @@ -1588,8 +1599,8 @@ later by using File>Close. def updateActives(self): labels = [ - u"Show All Due Cards", - u"Show Chosen Categories" + _("Show All Due Cards"), + _("Show Chosen Categories") ] if self.deck.getVar("newActive") or self.deck.getVar("newInactive"): new = labels[1] @@ -2569,6 +2580,8 @@ This deck already exists on your computer. Overwrite the local copy?"""), return os.path.join(dir, "plugins") def loadPlugins(self): + if self.appUpdated: + self.clearPluginCache() plugdir = self.pluginsFolder() sys.path.insert(0, plugdir) plugins = self.enabledPlugins() @@ -2584,6 +2597,15 @@ This deck already exists on your computer. Overwrite the local copy?"""), self.checkForUpdatedPlugins() self.disableCardMenuItems() + def clearPluginCache(self): + "Clear .pyc files which may cause crashes if Python version updated." + dir = self.pluginsFolder() + for curdir, dirs, files in os.walk(dir): + for f in files: + if not f.endswith(".pyc"): + continue + os.unlink(os.path.join(curdir, f)) + def rebuildPluginsMenu(self): if getattr(self, "pluginActions", None) is None: self.pluginActions = []