From ef413c20eea80e6d9d3937692a4564b38b423e5c Mon Sep 17 00:00:00 2001 From: Kevin Johansson Date: Sun, 9 Oct 2022 17:19:37 +0200 Subject: [PATCH] Implemented: config file, default open/close state, default split ratio, toolbar icon --- src/__init__.py | 15 +++++++++++---- src/config.json | 1 + src/config.md | 6 ++++++ src/icons/.DS_Store | Bin 0 -> 6148 bytes src/icons/file.svg | 19 +++++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/config.json create mode 100644 src/config.md create mode 100644 src/icons/.DS_Store create mode 100644 src/icons/file.svg diff --git a/src/__init__.py b/src/__init__.py index 48dfa84..76f84e0 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6,6 +6,7 @@ from aqt.utils import * from aqt.theme import theme_manager from aqt.webview import AnkiWebView +config = mw.addonManager.getConfig(__name__) class EditorPreview(object): js=[ @@ -37,6 +38,9 @@ class EditorPreview(object): context=ed, ) + if not config['showPreviewAutomatically']: + ed.webview.hide() + self._inject_splitter(ed) 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)) @@ -49,9 +53,10 @@ class EditorPreview(object): layout.removeWidget(editor.web) split.addWidget(editor.web) split.addWidget(editor.webview) - split.setStretchFactor(0, 0) - split.setStretchFactor(1, 1) - split.setStretchFactor(2, 1) + splitRatio = config['splitRatio'] + upperR, lowerR = [int(r) for r in splitRatio.split(":")] + split.setStretchFactor(0, upperR) + split.setStretchFactor(1, lowerR) layout.insertWidget(web_index, split) @@ -59,7 +64,9 @@ class EditorPreview(object): self.onedit_hook(editor, editor.note) def editor_init_button_hook(self, buttons, editor): - b = editor.addButton(icon=None, cmd="_editor_toggle_preview", label='P', tip='Toggle Live Preview', + addon_path = os.path.dirname(__file__) + icons_dir = os.path.join(addon_path, 'icons') + b = editor.addButton(icon=os.path.join(icons_dir, 'file.svg'), cmd="_editor_toggle_preview", tip='Toggle Live Preview', func=lambda o=editor: self.onEditorPreviewButton(o), disables=False ) buttons.append(b) diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..f9a193d --- /dev/null +++ b/src/config.json @@ -0,0 +1 @@ +{"showPreviewAutomatically": true, "splitRatio": "4:1"} \ No newline at end of file diff --git a/src/config.md b/src/config.md new file mode 100644 index 0000000..d9471b1 --- /dev/null +++ b/src/config.md @@ -0,0 +1,6 @@ +### Config +\- `showPreviewAutomatically` [boolean (true | false)]:
+   Defines if the preview window should show up automatically as you enter the Editor (default: true)

+\- `splitRatio` [int:int]:
+   Defines the default split ratio of the main view and preview view (default: 4:1) +
diff --git a/src/icons/.DS_Store b/src/icons/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + + + + +