From 6fa907f19876d685fed658a8a94aa7304d1daeab Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 4 Apr 2009 13:45:38 +0900 Subject: [PATCH] catch apple odoc load events --- ankiqt/__init__.py | 11 ++++++++++- ankiqt/ui/main.py | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ankiqt/__init__.py b/ankiqt/__init__.py index d96158a15..0acff358e 100644 --- a/ankiqt/__init__.py +++ b/ankiqt/__init__.py @@ -4,6 +4,7 @@ import os, sys, shutil from PyQt4.QtCore import * from PyQt4.QtGui import * +from anki.hooks import runHook appName="Anki" appVersion="0.9.9.7.1" @@ -64,6 +65,14 @@ color: #13486c; def finish(self, obj): self.splash.finish(obj) +class AnkiApp(QApplication): + + def event(self, evt): + if evt.type() == QEvent.FileOpen: + runHook("macLoadEvent", unicode(evt.file())) + return True + return QApplication.event(self, evt) + def run(): import config @@ -93,7 +102,7 @@ def run(): "config.db.old")) except: pass - app = QApplication(sys.argv) + app = AnkiApp(sys.argv) import forms import ui diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 425fed1b2..d36866eeb 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -2219,6 +2219,10 @@ Consider backing up your media directory first.""")) def setupSystemHacks(self): self.setupDocumentDir() self.changeLayoutSpacing() + addHook("macLoadEvent", self.onMacLoad) + + def onMacLoad(self, fname): + self.loadDeck(fname) def setupDocumentDir(self): if sys.platform.startswith("win32"):