anki-russian-stressmark

Anki addon to replace the selected Russian word with a version with stress marks.
git clone git://git.alex.balgavy.eu/anki-russian-stressmark.git
Log | Files | Refs | README

setup_ui.py (688B)


      1 from aqt.editor import Editor
      2 from anki.hooks import addHook
      3 import os
      4 import json
      5 from .russiangram_requests import stressmark
      6 
      7 def stressmarkSelection(editor) -> None:
      8     selected = editor.web.selectedText()
      9     if selected:
     10         editor.web.eval(""" document.execCommand("insertHTML", false, %s); """ % json.dumps(stressmark(selected)))
     11 
     12 def addButton(buttons, editor):
     13     tt = "Add Stress Marks"
     14     icon_name = "add.png"
     15     icon = os.path.join(os.path.join(os.path.dirname(__file__), "icons"), icon_name)
     16     b = editor.addButton(icon, "STRESSMARK", stressmarkSelection, tip=_("{}".format(tt)))
     17     buttons.append(b)
     18     return buttons
     19 
     20 addHook('setupEditorButtons', addButton)