Example #1
0
    def setupWeb(self) -> None:
        self.web = EditorWebView(self.widget, self)
        self.web.allowDrops = True
        self.web.set_bridge_command(self.onBridgeCmd, self)
        self.outerLayout.addWidget(self.web, 1)

        bgcol = self.mw.app.palette().window().color().name()  # type: ignore
        # then load page
        self.web.stdHtml(
            _html % (bgcol, tr.editing_show_duplicates()),
            css=[
                "css/editor.css",
                "css/editor-toolbar.css",
            ],
            js=[
                "js/vendor/jquery.min.js",
                "js/vendor/protobuf.min.js",
                "js/editor.js",
                "js/editor-toolbar.js",
            ],
            context=self,
            default_css=False,
        )

        lefttopbtns: List[str] = []
        gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)

        lefttopbtns_defs = [
            f"$editorToolbar.addButton({{ component: editorToolbar.RawButton, html: `{button}` }}, 'notetype');"
            for button in lefttopbtns
        ]
        lefttopbtns_js = "\n".join(lefttopbtns_defs)

        righttopbtns: List[str] = []
        gui_hooks.editor_did_init_buttons(righttopbtns, self)
        # legacy filter
        righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)

        righttopbtns_defs = "\n".join([
            f"{{ component: editorToolbar.RawButton, html: `{button}` }},"
            for button in righttopbtns
        ])
        righttopbtns_js = (f"""
$editorToolbar.addButtonGroup({{
  id: "addons",
  buttons: [ {righttopbtns_defs} ]
}});
""" if righttopbtns_defs else "")

        self.web.eval(f"""
$editorToolbar = document.getElementById("editorToolbar");
{lefttopbtns_js}
{righttopbtns_js}
""")
Example #2
0
    def setupWeb(self) -> None:
        self.web = EditorWebView(self.widget, self)
        self.web.allowDrops = True
        self.web.set_bridge_command(self.onBridgeCmd, self)
        self.outerLayout.addWidget(self.web, 1)

        # then load page
        self.web.stdHtml(
            _html % tr.editing_show_duplicates(),
            css=[
                "css/editor.css",
            ],
            js=[
                "js/vendor/jquery.min.js",
                "js/vendor/protobuf.min.js",
                "js/editor.js",
            ],
            context=self,
            default_css=True,
        )

        lefttopbtns: List[str] = []
        gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)

        lefttopbtns_defs = [
            f"$editorToolbar.then(({{ notetypeButtons }}) => notetypeButtons.appendButton({{ component: editorToolbar.Raw, props: {{ html: {json.dumps(button)} }} }}, -1));"
            for button in lefttopbtns
        ]
        lefttopbtns_js = "\n".join(lefttopbtns_defs)

        righttopbtns: List[str] = []
        gui_hooks.editor_did_init_buttons(righttopbtns, self)
        # legacy filter
        righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)

        righttopbtns_defs = ", ".join([json.dumps(button) for button in righttopbtns])
        righttopbtns_js = (
            f"""
$editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
    component: editorToolbar.AddonButtons,
    id: "addons",
    props: {{ buttons: [ {righttopbtns_defs} ] }},
}}));
"""
            if len(righttopbtns) > 0
            else ""
        )

        self.web.eval(f"{lefttopbtns_js} {righttopbtns_js}")
Example #3
0
File: editor.py Project: qwcbw/anki
    def setupWeb(self) -> None:
        self.web = EditorWebView(self.widget, self)
        self.web.allowDrops = True
        self.web.set_bridge_command(self.onBridgeCmd, self)
        self.outerLayout.addWidget(self.web, 1)

        lefttopbtns: List[str] = [
            self._addButton(
                None,
                "fields",
                tr.editing_customize_fields(),
                f"{tr.editing_fields()}...",
                disables=False,
                rightside=False,
            ),
            self._addButton(
                None,
                "cards",
                tr.editing_customize_card_templates_ctrlandl(),
                f"{tr.editing_cards()}...",
                disables=False,
                rightside=False,
            ),
        ]

        gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)

        righttopbtns: List[str] = [
            self._addButton("text_bold",
                            "bold",
                            tr.editing_bold_text_ctrlandb(),
                            id="bold"),
            self._addButton(
                "text_italic",
                "italic",
                tr.editing_italic_text_ctrlandi(),
                id="italic",
            ),
            self._addButton(
                "text_under",
                "underline",
                tr.editing_underline_text_ctrlandu(),
                id="underline",
            ),
            self._addButton(
                "text_super",
                "super",
                tr.editing_superscript_ctrlandand(),
                id="superscript",
            ),
            self._addButton("text_sub",
                            "sub",
                            tr.editing_subscript_ctrland(),
                            id="subscript"),
            self._addButton("text_clear", "clear",
                            tr.editing_remove_formatting_ctrlandr()),
            self._addButton(
                None,
                "colour",
                tr.editing_set_foreground_colour_f7(),
                """
<span id="forecolor" class="topbut rounded" style="background: #000"></span>
""",
            ),
            self._addButton(
                None,
                "changeCol",
                tr.editing_change_colour_f8(),
                """
<span class="topbut rounded rainbow"></span>
""",
            ),
            self._addButton("text_cloze", "cloze",
                            tr.editing_cloze_deletion_ctrlandshiftandc()),
            self._addButton("paperclip", "attach",
                            tr.editing_attach_picturesaudiovideo_f3()),
            self._addButton("media-record", "record",
                            tr.editing_record_audio_f5()),
            self._addButton("more", "more"),
        ]

        gui_hooks.editor_did_init_buttons(righttopbtns, self)
        # legacy filter
        righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)

        topbuts = """
            <div id="topbutsleft" class="topbuts">
                %(leftbts)s
            </div>
            <div id="topbutsright" class="topbuts">
                %(rightbts)s
            </div>
        """ % dict(
            leftbts="".join(lefttopbtns),
            rightbts="".join(righttopbtns),
        )
        bgcol = self.mw.app.palette().window().color().name()  # type: ignore
        # then load page
        self.web.stdHtml(
            _html % (bgcol, topbuts, tr.editing_show_duplicates()),
            css=[
                "css/vendor/bootstrap.min.css",
                "css/editor.css",
            ],
            js=[
                "js/vendor/jquery.min.js",
                "js/vendor/bootstrap.bundle.min.js",
                "js/editor.js",
            ],
            context=self,
        )
        self.web.eval("preventButtonFocus();")