Permalink
Browse files

port majority of code to qt5.5+

- a few issues to work out still, and editor changes not done yet
- for communication between webengine and python code, we set window
.location to 'http://anki/<something>' - the leading http is
necessary for qt to call the link handler, which was introduced
in qt5.5
- the designer files now use a promoted qobject to create instances
of AnkiWebView
- we use the css zoom property to alter webengine font size based on
system dpi
- prefs and addons folder stored in new location (at least for now)
  • Loading branch information...
1 parent 4d88b62 commit de7e40537d1d532252c7e2839bc8782eaa1bd22a @dae committed May 31, 2016
View
@@ -1,7 +1,6 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import getpass
-import os
import sys
import optparse
import tempfile
@@ -118,6 +117,8 @@ class AnkiApp(QApplication):
# Single instance support on Win32/Linux
##################################################
+ appMsg = pyqtSignal(str)
+
KEY = "anki"+checksum(getpass.getuser())
TMOUT = 5000
@@ -140,7 +141,7 @@ def secondInstance(self):
# previous instance died
QLocalServer.removeServer(self.KEY)
self._srv = QLocalServer(self)
- self.connect(self._srv, SIGNAL("newConnection()"), self.onRecv)
+ self._srv.newConnection.connect(self.onRecv)
self._srv.listen(self.KEY)
return False
@@ -150,7 +151,7 @@ def sendMsg(self, txt):
if not sock.waitForConnected(self.TMOUT):
# first instance or previous instance dead
return False
- sock.write(txt)
+ sock.write(txt.encode("utf8"))
if not sock.waitForBytesWritten(self.TMOUT):
# existing instance running but hung
return False
@@ -162,17 +163,16 @@ def onRecv(self):
if not sock.waitForReadyRead(self.TMOUT):
sys.stderr.write(sock.errorString())
return
- buf = sock.readAll()
- buf = str(buf, sys.getfilesystemencoding(), "ignore")
- self.emit(SIGNAL("appMsg"), buf)
+ path = bytes(sock.readAll()).decode("utf8")
+ self.appMsg.emit(path)
sock.disconnectFromServer()
# OS X file/url handler
##################################################
def event(self, evt):
if evt.type() == QEvent.FileOpen:
- self.emit(SIGNAL("appMsg"), evt.file() or "raise")
+ self.appMsg.emit(evt.file() or "raise")
return True
return QApplication.event(self, evt)
@@ -207,12 +207,9 @@ def _run():
# on osx we'll need to add the qt plugins to the search path
if isMac and getattr(sys, 'frozen', None):
- rd = os.path.abspath(moduleDir + "/../../..")
+ rd = os.path.abspath(moduleDir + "/../../../plugins")
QCoreApplication.setLibraryPaths([rd])
- if isMac:
- QFont.insertSubstitution(".Lucida Grande UI", "Lucida Grande")
-
# create the app
app = AnkiApp(sys.argv)
QCoreApplication.setApplicationName("Anki")
@@ -234,13 +231,6 @@ def _run():
environment points to a valid, writable folder.""")
return
- # qt version must be up to date
- if qtmajor <= 4 and qtminor <= 6:
- QMessageBox.warning(
- None, "Error", "Your Qt version is known to be buggy. Until you "
- "upgrade to a newer Qt, you may experience issues such as images "
- "failing to show up during review.")
-
# profile manager
from aqt.profiles import ProfileManager
pm = ProfileManager(opts.base, opts.profile)
View
@@ -11,12 +11,6 @@ def show(parent):
dialog = QDialog(parent)
abt = aqt.forms.about.Ui_About()
abt.setupUi(dialog)
- abt.label.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
- def onLink(url):
- openLink(url.toString())
- parent.connect(abt.label,
- SIGNAL("linkClicked(QUrl)"),
- onLink)
abouttext = "<center><img src='qrc:/icons/anki-logo-thin.png'></center>"
abouttext += '<p>' + _("Anki is a friendly, intelligent spaced learning \
system. It's free and open source.")
View
@@ -53,20 +53,18 @@ def setupButtons(self):
ar = QDialogButtonBox.ActionRole
# add
self.addButton = bb.addButton(_("Add"), ar)
+ self.addButton.clicked.connect(self.addCards)
self.addButton.setShortcut(QKeySequence("Ctrl+Return"))
self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)")))
- self.connect(self.addButton, SIGNAL("clicked()"), self.addCards)
# close
self.closeButton = QPushButton(_("Close"))
self.closeButton.setAutoDefault(False)
- bb.addButton(self.closeButton,
- QDialogButtonBox.RejectRole)
+ bb.addButton(self.closeButton, QDialogButtonBox.RejectRole)
# help
- self.helpButton = QPushButton(_("Help"))
+ self.helpButton = QPushButton(_("Help"), clicked=self.helpRequested)
self.helpButton.setAutoDefault(False)
bb.addButton(self.helpButton,
QDialogButtonBox.HelpRole)
- self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
# history
b = bb.addButton(
_("History")+ " "+downArrow(), ar)
@@ -76,7 +74,7 @@ def setupButtons(self):
sc = "Ctrl+H"
b.setShortcut(QKeySequence(sc))
b.setToolTip(_("Shortcut: %s") % shortcut(sc))
- self.connect(b, SIGNAL("clicked()"), self.onHistory)
+ b.clicked.connect(self.onHistory)
b.setEnabled(False)
self.historyButton = b
@@ -145,8 +143,7 @@ def onHistory(self):
m = QMenu(self)
for nid, txt in self.history:
a = m.addAction(_("Edit %s") % txt)
- a.connect(a, SIGNAL("triggered()"),
- lambda nid=nid: self.editHistory(nid))
+ a.triggered.connect(lambda b, nid=nid: self.editHistory(nid))
runHook("AddCards.onHistory", self, m)
m.exec_(self.historyButton.mapToGlobal(QPoint(0,0)))
View
@@ -21,9 +21,9 @@ class AddonManager(object):
def __init__(self, mw):
self.mw = mw
- f = self.mw.form; s = SIGNAL("triggered()")
- self.mw.connect(f.actionOpenPluginFolder, s, self.onOpenAddonFolder)
- self.mw.connect(f.actionDownloadSharedPlugin, s, self.onGetAddons)
+ f = self.mw.form
+ f.actionOpenPluginFolder.triggered.connect(self.onOpenAddonFolder)
+ f.actionDownloadSharedPlugin.triggered.connect(self.onGetAddons)
self._menus = []
if isWin:
self.clearAddonCache()
@@ -46,7 +46,7 @@ def loadAddons(self):
# Menus
######################################################################
- def onOpenAddonFolder(self, path=None):
+ def onOpenAddonFolder(self, checked, path=None):
if path is None:
path = self.addonsFolder()
openFolder(path)
@@ -58,14 +58,11 @@ def rebuildAddonsMenu(self):
m = self.mw.form.menuPlugins.addMenu(
os.path.splitext(file)[0])
self._menus.append(m)
- a = QAction(_("Edit..."), self.mw)
+ a = QAction(_("Edit..."), self.mw, triggered=self.onEdit)
p = os.path.join(self.addonsFolder(), file)
- self.mw.connect(a, SIGNAL("triggered()"),
- lambda p=p: self.onEdit(p))
+
m.addAction(a)
- a = QAction(_("Delete..."), self.mw)
- self.mw.connect(a, SIGNAL("triggered()"),
- lambda p=p: self.onRem(p))
+ a = QAction(_("Delete..."), self.mw, triggered=self.onRem)
m.addAction(a)
def onEdit(self, path):
@@ -74,8 +71,7 @@ def onEdit(self, path):
frm.setupUi(d)
d.setWindowTitle(os.path.basename(path))
frm.text.setPlainText(open(path).read())
- d.connect(frm.buttonBox, SIGNAL("accepted()"),
- lambda: self.onAcceptEdit(path, frm))
+ frm.buttonBox.accepted.connect(lambda: self.onAcceptEdit(path, frm))
d.exec_()
def onAcceptEdit(self, path, frm):
@@ -94,8 +90,6 @@ def onRem(self, path):
def addonsFolder(self):
dir = self.mw.pm.addonFolder()
- if isWin:
- dir = dir.encode(sys.getfilesystemencoding())
return dir
def clearAddonCache(self):
@@ -115,7 +109,9 @@ def registerAddon(self, name, updateId):
######################################################################
def onGetAddons(self):
- GetAddons(self.mw)
+ showInfo("Currently disabled, as add-ons built for 2.0.x will need updating")
+
+ # GetAddons(self.mw)
def install(self, data, fname):
if fname.endswith(".py"):
@@ -146,7 +142,7 @@ def __init__(self, mw):
self.form.setupUi(self)
b = self.form.buttonBox.addButton(
_("Browse"), QDialogButtonBox.ActionRole)
- self.connect(b, SIGNAL("clicked()"), self.onBrowse)
+ b.clicked.connect(self.onBrowse)
restoreGeom(self, "getaddons", adjustSize=True)
self.exec_()
saveGeom(self, "getaddons")
Oops, something went wrong.

0 comments on commit de7e405

Please sign in to comment.