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