use os check shortcuts

This commit is contained in:
Damien Elmes 2011-04-17 01:00:09 +09:00
parent 03092ab486
commit f245c7651c
9 changed files with 28 additions and 28 deletions

View file

@ -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']

View file

@ -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)"))

View file

@ -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")

View file

@ -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

View file

@ -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")

View file

@ -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]

View file

@ -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")

View file

@ -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")

View file

@ -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 href="%s">' % 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")