Last active
August 29, 2015 14:12
-
-
Save slava-sh/c5380212dc583b3e4117 to your computer and use it in GitHub Desktop.
Anki add-on
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
# -*- coding: utf-8 -*- | |
from aqt import mw | |
from aqt.qt import * | |
def openUrl(url_template): | |
def inner(): | |
url = url_template.format(**mw.reviewer.card.note()) | |
QDesktopServices.openUrl(QUrl(url)) | |
return inner | |
def createUrlAction(text, url_template, shortcut=None): | |
action = QAction(text, mw) | |
if shortcut: | |
action.setShortcut(shortcut) | |
mw.form.menuOpenUrl.addAction(action) | |
mw.connect(action, SIGNAL('triggered()'), openUrl(url_template)) | |
def createMenu(): | |
mw.form.menuOpenUrl = QMenu(u'Lookup') | |
mw.form.menuTools.addAction(mw.form.menuOpenUrl.menuAction()) | |
createUrlAction(u'Esperanto word on Wiktionary', shortcut='w', url_template=u'https://en.wiktionary.org/wiki/{Esperanto}#Etymology'); | |
createUrlAction(u'Word on Lingvo', shortcut='a', url_template=u'http://lingvo-online.ru/en/Translate/en-ru/{Word}'); | |
createMenu() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment