From c0d8d7f029b0d8e7749869faed8d5891cbf18029 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 4 Jul 2017 12:35:04 -0700 Subject: [PATCH] fix guiBrowse to work on anki alpha, add gitignore --- .gitignore | 1 + AnkiConnect.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/AnkiConnect.py b/AnkiConnect.py index 6931887..80c6e80 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -18,6 +18,7 @@ import anki import aqt import hashlib +import inspect import json import os.path import select @@ -444,14 +445,16 @@ class AnkiBridge: return deck['name'] - def guiBrowse(self, query): + def guiBrowse(self, query=None): browser = aqt.dialogs.open('Browser', self.window()) browser.activateWindow() - if len(query) > 0: - query = unicode('"{}"').format(query) + if query is not None: browser.form.searchEdit.lineEdit().setText(query) - browser.onSearch() + if hasattr(browser, 'onSearch'): + browser.onSearch() + else: + browser.onSearchActivated() return browser.model.cards @@ -575,11 +578,12 @@ class AnkiConnect: action = request.get('action', '') if hasattr(self, action): handler = getattr(self, action) - if hasattr(handler, 'webApi') and getattr(handler, 'webApi'): - argsAll = handler.__code__.co_varnames[1:] + if callable(handler) and hasattr(handler, 'webApi') and getattr(handler, 'webApi'): + spec = inspect.getargspec(handler) + argsAll = spec.args[1:] argsReq = argsAll - argsDef = handler.__defaults__ + argsDef = spec.defaults if argsDef is not None: argsReq = argsAll[:-len(argsDef)] @@ -591,7 +595,7 @@ class AnkiConnect: if param not in argsAll: return - handler(**params) + return handler(**params) @webApi @@ -668,7 +672,7 @@ class AnkiConnect: @webApi - def guiBrowse(self, query): + def guiBrowse(self, query=None): return self.anki.guiBrowse(query)