From 30de24b4fc3e9fa8fbba99ee24b7657fd5c8cfe2 Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Mon, 13 Sep 2021 02:18:29 +0200 Subject: [PATCH] Buildscript for ankiaddon --- .gitignore | 1 + __init__.py | 53 ----------------------------------------------------- build.sh | 11 +++++++++++ 3 files changed, 12 insertions(+), 53 deletions(-) delete mode 100644 __init__.py create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index 638ec3c..786e282 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,4 @@ tags [._]*.un~ # End of https://www.toptal.com/developers/gitignore/api/vim,python +*.ankiaddon diff --git a/__init__.py b/__init__.py deleted file mode 100644 index b6c5123..0000000 --- a/__init__.py +++ /dev/null @@ -1,53 +0,0 @@ -from aqt.qt import * -import json -from anki import hooks -from aqt import editor -from aqt.webview import AnkiWebView -from aqt.theme import theme_manager -from aqt import gui_hooks -from aqt import mw - -class EditorPreview(object): - - def __init__(self): - gui_hooks.editor_did_init.append(self.editor_init_hook) - - def editor_init_hook(self, ed: editor.Editor): - ed.webview = AnkiWebView(title="editor_preview") - # This is taken out of clayout.py - ed.webview.stdHtml( - ed.mw.reviewer.revHtml(), - css=["css/reviewer.css"], - js=[ - "js/mathjax.js", - "js/vendor/mathjax/tex-chtml.js", - "js/reviewer.js", - ], - context=ed, - ) - layout = ed.outerLayout - # very arbitrary max size - # otherwise the browse window is not usable - ed.webview.setMaximumHeight = 400 - layout.addWidget(ed.webview, 1) - gui_hooks.editor_did_fire_typing_timer.append(lambda o: self.onedit_hook(ed, o)) - gui_hooks.editor_did_load_note.append(lambda o: None if o != ed else self.editor_note_hook(o)) - - def editor_note_hook(self, editor): - self.onedit_hook(editor, editor.note) - - - def _obtainCardText(self, note): - c = note.ephemeral_card() - a = mw.prepare_card_text_for_display(c.answer()) - a = gui_hooks.card_will_show(a, c, "clayoutAnswer") - bodyclass = theme_manager.body_classes_for_card_ord(c.ord, mw.pm.night_mode()) - - return f"_showAnswer({json.dumps(a)},'{bodyclass}');" - - def onedit_hook(self, editor, origin): - if editor.note == origin: - editor.webview.eval(self._obtainCardText(editor.note)) - - -eprev = EditorPreview() diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..57313de --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +if [ -d src/__pycache__ ]; then + rm -r src/__pycache__ +fi + +cd src +zip -r ../editor-preview.ankiaddon * +cd .. +unzip -l editor-preview.ankiaddon