Use a webview to show add-on's config help (#2281)

* Use a webview to show add-on's config help

This allows add-ons to embed images for example.

* Improve initial size of splitter widgets

* Decrease font size and margin of webview
This commit is contained in:
Abdo 2022-12-21 09:55:31 +03:00 committed by GitHub
parent 9cb54ad797
commit 46c0c281f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 60 deletions

View file

@ -1550,6 +1550,7 @@ class ConfigEditor(QDialog):
self.updateHelp()
self.updateText(self.conf)
restoreGeom(self, "addonconf")
self.form.splitter.setSizes([2 * self.width() // 3, self.width() // 3])
restoreSplitter(self.form.splitter, "addonconf")
self.setWindowTitle(
without_unicode_isolation(
@ -1574,9 +1575,9 @@ class ConfigEditor(QDialog):
def updateHelp(self) -> None:
txt = self.mgr.addonConfigHelp(self.addon)
if txt:
self.form.label.setText(txt)
self.form.help.stdHtml(txt, js=[], css=["css/addonconf.css"], context=self)
else:
self.form.scrollArea.setVisible(False)
self.form.help.setVisible(False)
def updateText(self, conf: dict[str, Any]) -> None:
text = json.dumps(

View file

@ -0,0 +1,7 @@
/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
body {
margin: 5px;
font-size: 13px;
}

View file

@ -33,65 +33,12 @@
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="AnkiWebView" name="help" native="true">
<property name="url" stdset="0">
<url>
<string>about:blank</string>
</url>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>80</width>
<height>470</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
@ -107,6 +54,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AnkiWebView</class>
<extends>QWidget</extends>
<header location="global">aqt/webview</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>