-
-
Save ijgnd/da9f4e12b80a82f1c972b8e91d247aab to your computer and use it in GitHub Desktop.
open the browser or add window from the debug console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isbrowser= False # else Add | |
from anki import version as anki_version | |
old_anki = tuple(int(i) for i in anki_version.split(".")) < (2, 1, 24) | |
# add-on "Opening the same window multiple time" | |
try: | |
aqt.dialogs._openDialogs | |
except: | |
addon = False | |
else: | |
addon = True | |
my_inst = None | |
if addon: | |
if isbrowser: | |
A = __import__("874215009").advancedbrowser.core.AdvancedBrowser | |
else: | |
if old_anki: | |
A = __import__("424778276").keepModelInAddCards.AddCards | |
else: | |
from aqt.addcards import AddCards | |
A = AddCards | |
dialogs = aqt.dialogs._openDialogs | |
relevant_instances = [] | |
for d in dialogs: | |
if isinstance(d, A): | |
relevant_instances.append(d) | |
if not relevant_instances: | |
pp('no instance of relevant class opened. Aborting ...') | |
else: | |
if len(relevant_instances) > 1: | |
pp("relevant window opened multiple times. Selecting first one") | |
my_inst = relevant_instances[0] | |
else: | |
win = "Browser" if isbrowser else "AddCards" | |
d = aqt.dialogs._dialogs[win] | |
if d[1]: | |
my_inst = d[1] | |
mytext = "hello" | |
if my_inst and isbrowser: | |
my_inst.form.searchEdit.lineEdit().setText(mytext) | |
my_inst.onSearchActivated() | |
elif my_inst: # Add window | |
import json | |
editor = my_inst.editor | |
if not editor.currentField: | |
editor.currentField = 0 | |
editor.web.eval("document.execCommand('inserthtml', false, %s);" | |
% json.dumps(mytext)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment