diff --git a/aqt/__init__.py b/aqt/__init__.py index ae0016414..1805d6d94 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -115,10 +115,11 @@ class AnkiApp(QApplication): def run(): global mw + from anki.utils import isWin, isMac # home on win32 is broken mustQuit = False - if sys.platform == "win32": + if isWin: # use appdata if available if 'APPDATA' in os.environ: os.environ['HOME'] = os.environ['APPDATA'] @@ -136,7 +137,7 @@ def run(): # on osx we'll need to add the qt plugins to the search path rd = runningDir - if sys.platform.startswith("darwin") and getattr(sys, 'frozen', None): + if isMac and getattr(sys, 'frozen', None): rd = os.path.abspath(runningDir + "/../../..") QCoreApplication.setLibraryPaths(QStringList([rd])) @@ -165,7 +166,7 @@ def run(): # qt translations translationPath = '' - if 'linux' in sys.platform or 'unix' in sys.platform: + if not isWin and not isMac: translationPath = "/usr/share/qt4/translations/" if translationPath: long = conf['interfaceLang'] diff --git a/aqt/addcards.py b/aqt/addcards.py index 3217d59da..56e8cdc39 100644 --- a/aqt/addcards.py +++ b/aqt/addcards.py @@ -13,7 +13,7 @@ from anki.utils import stripHTML, parseTags from aqt.utils import saveGeom, restoreGeom, showWarning, askUser from anki.sound import clearAudioQueue from anki.hooks import addHook, removeHook -from anki.utils import stripHTMLMedia +from anki.utils import stripHTMLMedia, isMac import aqt.editor, aqt.modelchooser class AddCards(QDialog): @@ -58,7 +58,7 @@ class AddCards(QDialog): self.form.buttonBox.addButton(self.addButton, QDialogButtonBox.ActionRole) self.addButton.setShortcut(_("Ctrl+Return")) - if sys.platform.startswith("darwin"): + if isMac: self.addButton.setToolTip(_("Add (shortcut: command+return)")) else: self.addButton.setToolTip(_("Add (shortcut: ctrl+return)")) diff --git a/aqt/browser.py b/aqt/browser.py index 9987a65fa..a0fcfdbbe 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -10,7 +10,7 @@ import time, types, sys, re from operator import attrgetter, itemgetter import anki, anki.utils, aqt.forms from anki.utils import fmtTimeSpan, parseTags, hasTag, addTags, delTags, \ - ids2str, stripHTMLMedia + ids2str, stripHTMLMedia, isWin from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \ saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \ showInfo, askUser @@ -481,7 +481,7 @@ class Browser(QMainWindow): def setupHeaders(self): vh = self.form.tableView.verticalHeader() hh = self.form.tableView.horizontalHeader() - if not sys.platform.startswith("win32"): + if not isWin: vh.hide() hh.show() restoreHeader(hh, "editor") diff --git a/aqt/clayout.py b/aqt/clayout.py index 1ef54efcf..bc6904d7d 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -9,8 +9,8 @@ from anki.consts import * import aqt from anki.sound import playFromText, clearAudioQueue from aqt.utils import saveGeom, restoreGeom, getBase, mungeQA, \ - saveSplitter, restoreSplitter, showInfo, isMac, isWin, askUser, \ - getText + saveSplitter, restoreSplitter, showInfo, askUser, getText +from anki.utils import isMac, isWin import aqt.templates # fixme: replace font substitutions with native comma list diff --git a/aqt/config.py b/aqt/config.py index c268c0eea..d704225b5 100644 --- a/aqt/config.py +++ b/aqt/config.py @@ -9,6 +9,7 @@ import os, sys, time, random, cPickle from anki.db import DB +from anki.utils import isMac defaultConf = { 'confVer': 3, @@ -70,7 +71,7 @@ class Config(object): def __init__(self, confDir): self.confDir = confDir self._conf = {} - if sys.platform.startswith("darwin") and ( + if isMac and ( self.confDir == os.path.expanduser("~/.anki")): self.confDir = os.path.expanduser( "~/Library/Application Support/Anki") diff --git a/aqt/editor.py b/aqt/editor.py index 8c828547f..a5b059c80 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -6,7 +6,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import QWebView import re, os, sys, tempfile, urllib2, ctypes, simplejson, traceback -from anki.utils import stripHTML, parseTags +from anki.utils import stripHTML, parseTags, isWin from anki.sound import play from anki.hooks import runHook from aqt.sound import getAudio @@ -693,7 +693,7 @@ class Editor(object): ###################################################################### def setupKeyboard(self): - if sys.platform.startswith("win32") and self.mw.config['preserveKeyboard']: + if isWin and self.mw.config['preserveKeyboard']: a = ctypes.windll.user32.ActivateKeyboardLayout a.restype = ctypes.c_void_p a.argtypes = [ctypes.c_void_p, ctypes.c_uint] diff --git a/aqt/main.py b/aqt/main.py index 0d20f2c63..e9bfa9b80 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -13,7 +13,8 @@ QtConfig = pyqtconfig.Configuration() from anki import Deck from anki.sound import hasSound, playFromText, clearAudioQueue, stripSounds -from anki.utils import addTags, parseTags, canonifyTags, stripHTML, checksum +from anki.utils import addTags, parseTags, canonifyTags, stripHTML, \ + checksum, isWin, isMac from anki.hooks import runHook, addHook, removeHook import anki.consts @@ -1011,7 +1012,7 @@ sync will overwrite any remote changes. Continue?""")) import aqt.dropbox as db p = db.getPath() except: - if sys.platform.startswith("win32"): + if isWin: s = QSettings(QSettings.UserScope, "Microsoft", "Windows") s.beginGroup("CurrentVersion/Explorer/Shell Folders") p = os.path.join(unicode(s.value("Personal").toString()), @@ -1154,7 +1155,7 @@ It can take a long time. Proceed?""")): def setupSystemSpecific(self): self.setupDocumentDir() addHook("macLoadEvent", self.onMacLoad) - if sys.platform.startswith("darwin"): + if isMac: qt_mac_set_menubar_icons(False) self.setUnifiedTitleAndToolBarOnMac(True) # mac users expect a minimize option @@ -1163,7 +1164,7 @@ It can take a long time. Proceed?""")): self.onMacMinimize) self.hideAccelerators() self.hideStatusTips() - elif sys.platform.startswith("win32"): + elif isWin: # make sure ctypes is bundled from ctypes import windll, wintypes @@ -1187,7 +1188,7 @@ It can take a long time. Proceed?""")): def setupDocumentDir(self): if self.config['documentDir']: return - if sys.platform.startswith("win32"): + if isWin: s = QSettings(QSettings.UserScope, "Microsoft", "Windows") s.beginGroup("CurrentVersion/Explorer/Shell Folders") d = unicode(s.value("Personal").toString()) @@ -1195,7 +1196,7 @@ It can take a long time. Proceed?""")): d = os.path.join(d, "Anki") else: d = os.path.expanduser("~/.anki/decks") - elif sys.platform.startswith("darwin"): + elif isMac: d = os.path.expanduser("~/Documents/Anki") else: d = os.path.expanduser("~/.anki/decks") diff --git a/aqt/plugins.py b/aqt/plugins.py index e49f930fc..a9564b1b0 100644 --- a/aqt/plugins.py +++ b/aqt/plugins.py @@ -5,7 +5,7 @@ import sys, os, re, traceback from PyQt4.QtCore import * from PyQt4.QtGui import * -from aqt.utils import showInfo, showWarning, openFolder +from aqt.utils import showInfo, showWarning, openFolder, isWin from anki.hooks import runHook class PluginManager(object): @@ -16,7 +16,7 @@ class PluginManager(object): self.mw.connect(f.actionOpenPluginFolder, s, self.onOpenPluginFolder) self.mw.connect(f.actionEnableAllPlugins, s, self.onEnableAllPlugins) self.mw.connect(f.actionDisableAllPlugins, s, self.onDisableAllPlugins) - if sys.platform.startswith("win32"): + if isWin: self.clearPluginCache() self.disableObsoletePlugins() plugdir = self.pluginsFolder() @@ -43,7 +43,7 @@ class PluginManager(object): def pluginsFolder(self): dir = self.mw.config.confDir - if sys.platform.startswith("win32"): + if isWin: dir = dir.encode(sys.getfilesystemencoding()) return os.path.join(dir, "plugins") diff --git a/aqt/utils.py b/aqt/utils.py index 0965b68d0..c67ed3177 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -6,7 +6,7 @@ from PyQt4.QtCore import * import re, os, sys, urllib, time import aqt from anki.sound import playFromText, stripSounds -from anki.utils import call +from anki.utils import call, isWin, isMac def openLink(link): QDesktopServices.openUrl(QUrl(link)) @@ -260,7 +260,7 @@ def restoreGeom(widget, key, offset=None): key += "Geom" if aqt.mw.config.get(key): widget.restoreGeometry(aqt.mw.config[key]) - if sys.platform.startswith("darwin") and offset: + if isMac and offset: from aqt.main import QtConfig as q minor = (q.qt_version & 0x00ff00) >> 8 if minor > 6: @@ -322,7 +322,7 @@ def getBase(deck): return '' % base def openFolder(path): - if sys.platform == "win32": + if isWin: if isinstance(path, unicode): path = path.encode(sys.getfilesystemencoding()) call(["explorer", path], wait=False) @@ -330,7 +330,7 @@ def openFolder(path): QDesktopServices.openUrl(QUrl("file://" + path)) def shortcut(key): - if sys.platform == "darwin": + if Mac: return re.sub("(?i)ctrl", "Command", key) return key @@ -344,6 +344,3 @@ def limitedCount(count): if count >= 1000: return "1000+" return str(count) - -isMac = sys.platform.startswith("darwin") -isWin = sys.platform.startswith("win32")