fix guiBrowse to work on anki alpha, add gitignore

This commit is contained in:
Alex Yatskov 2017-07-04 12:35:04 -07:00
parent fdeef8099a
commit c0d8d7f029
2 changed files with 14 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -18,6 +18,7 @@
import anki import anki
import aqt import aqt
import hashlib import hashlib
import inspect
import json import json
import os.path import os.path
import select import select
@ -444,14 +445,16 @@ class AnkiBridge:
return deck['name'] return deck['name']
def guiBrowse(self, query): def guiBrowse(self, query=None):
browser = aqt.dialogs.open('Browser', self.window()) browser = aqt.dialogs.open('Browser', self.window())
browser.activateWindow() browser.activateWindow()
if len(query) > 0: if query is not None:
query = unicode('"{}"').format(query)
browser.form.searchEdit.lineEdit().setText(query) browser.form.searchEdit.lineEdit().setText(query)
if hasattr(browser, 'onSearch'):
browser.onSearch() browser.onSearch()
else:
browser.onSearchActivated()
return browser.model.cards return browser.model.cards
@ -575,11 +578,12 @@ class AnkiConnect:
action = request.get('action', '') action = request.get('action', '')
if hasattr(self, action): if hasattr(self, action):
handler = getattr(self, action) handler = getattr(self, action)
if hasattr(handler, 'webApi') and getattr(handler, 'webApi'): if callable(handler) and hasattr(handler, 'webApi') and getattr(handler, 'webApi'):
argsAll = handler.__code__.co_varnames[1:] spec = inspect.getargspec(handler)
argsAll = spec.args[1:]
argsReq = argsAll argsReq = argsAll
argsDef = handler.__defaults__ argsDef = spec.defaults
if argsDef is not None: if argsDef is not None:
argsReq = argsAll[:-len(argsDef)] argsReq = argsAll[:-len(argsDef)]
@ -591,7 +595,7 @@ class AnkiConnect:
if param not in argsAll: if param not in argsAll:
return return
handler(**params) return handler(**params)
@webApi @webApi
@ -668,7 +672,7 @@ class AnkiConnect:
@webApi @webApi
def guiBrowse(self, query): def guiBrowse(self, query=None):
return self.anki.guiBrowse(query) return self.anki.guiBrowse(query)