Refactor web view title setting and add titles to all web views

Simplifies debugging web views
This commit is contained in:
Glutanimate 2020-02-12 21:03:11 +01:00
parent d0284f759d
commit df2a7b06ef
6 changed files with 14 additions and 14 deletions

View file

@ -1392,7 +1392,7 @@ by clicking on one on the left."""
d = CardInfoDialog(self) d = CardInfoDialog(self)
l = QVBoxLayout() l = QVBoxLayout()
l.setContentsMargins(0, 0, 0, 0) l.setContentsMargins(0, 0, 0, 0)
w = AnkiWebView() w = AnkiWebView(title="browser card info")
l.addWidget(w) l.addWidget(w)
w.stdHtml(info + "<p>" + reps) w.stdHtml(info + "<p>" + reps)
bb = QDialogButtonBox(QDialogButtonBox.Close) bb = QDialogButtonBox(QDialogButtonBox.Close)
@ -1561,7 +1561,7 @@ where id in %s"""
self._previewWindow.silentlyClose = True self._previewWindow.silentlyClose = True
vbox = QVBoxLayout() vbox = QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0) vbox.setContentsMargins(0, 0, 0, 0)
self._previewWeb = AnkiWebView() self._previewWeb = AnkiWebView(title="previewer")
vbox.addWidget(self._previewWeb) vbox.addWidget(self._previewWeb)
bbox = QDialogButtonBox() bbox = QDialogButtonBox()
@ -2158,6 +2158,7 @@ update cards set usn=?, mod=?, did=? where id in """
frm.fields.addItems(fields) frm.fields.addItems(fields)
self._dupesButton = None self._dupesButton = None
# links # links
frm.webView.title = "find duplicates"
frm.webView.set_bridge_command( frm.webView.set_bridge_command(
self.dupeLinkClicked, FindDupesDialog(dialog=d, browser=self) self.dupeLinkClicked, FindDupesDialog(dialog=d, browser=self)
) )

View file

@ -203,9 +203,9 @@ class CardLayout(QDialog):
def setupWebviews(self): def setupWebviews(self):
pform = self.pform pform = self.pform
pform.frontWeb = AnkiWebView() pform.frontWeb = AnkiWebView(title="card layout front")
pform.frontPrevBox.addWidget(pform.frontWeb) pform.frontPrevBox.addWidget(pform.frontWeb)
pform.backWeb = AnkiWebView() pform.backWeb = AnkiWebView(title="card layout back")
pform.backPrevBox.addWidget(pform.backWeb) pform.backPrevBox.addWidget(pform.backWeb)
jsinc = [ jsinc = [
"jquery.js", "jquery.js",

View file

@ -95,7 +95,6 @@ class Editor:
def setupWeb(self) -> None: def setupWeb(self) -> None:
self.web = EditorWebView(self.widget, self) self.web = EditorWebView(self.widget, self)
self.web.title = "editor"
self.web.allowDrops = True self.web.allowDrops = True
self.web.set_bridge_command(self.onBridgeCmd, self) self.web.set_bridge_command(self.onBridgeCmd, self)
self.outerLayout.addWidget(self.web, 1) self.outerLayout.addWidget(self.web, 1)
@ -937,7 +936,7 @@ to a cloze type first, via Edit>Change Note Type."""
class EditorWebView(AnkiWebView): class EditorWebView(AnkiWebView):
def __init__(self, parent, editor): def __init__(self, parent, editor):
AnkiWebView.__init__(self) AnkiWebView.__init__(self, title="editor")
self.editor = editor self.editor = editor
self.strip = self.editor.mw.pm.profile["stripHTML"] self.strip = self.editor.mw.pm.profile["stripHTML"]
self.setAcceptDrops(True) self.setAcceptDrops(True)

View file

@ -717,19 +717,16 @@ title="%s" %s>%s</button>""" % (
self.form = aqt.forms.main.Ui_MainWindow() self.form = aqt.forms.main.Ui_MainWindow()
self.form.setupUi(self) self.form.setupUi(self)
# toolbar # toolbar
tweb = self.toolbarWeb = aqt.webview.AnkiWebView() tweb = self.toolbarWeb = aqt.webview.AnkiWebView(title="top toolbar")
tweb.title = "top toolbar"
tweb.setFocusPolicy(Qt.WheelFocus) tweb.setFocusPolicy(Qt.WheelFocus)
self.toolbar = aqt.toolbar.Toolbar(self, tweb) self.toolbar = aqt.toolbar.Toolbar(self, tweb)
self.toolbar.draw() self.toolbar.draw()
# main area # main area
self.web = aqt.webview.AnkiWebView() self.web = aqt.webview.AnkiWebView(title="main webview")
self.web.title = "main webview"
self.web.setFocusPolicy(Qt.WheelFocus) self.web.setFocusPolicy(Qt.WheelFocus)
self.web.setMinimumWidth(400) self.web.setMinimumWidth(400)
# bottom area # bottom area
sweb = self.bottomWeb = aqt.webview.AnkiWebView() sweb = self.bottomWeb = aqt.webview.AnkiWebView(title="bottom toolbar")
sweb.title = "bottom toolbar"
sweb.setFocusPolicy(Qt.WheelFocus) sweb.setFocusPolicy(Qt.WheelFocus)
# add in a layout # add in a layout
self.mainLayout = QVBoxLayout() self.mainLayout = QVBoxLayout()

View file

@ -95,6 +95,7 @@ class DeckStats(QDialog):
stats = self.mw.col.stats() stats = self.mw.col.stats()
stats.wholeCollection = self.wholeCollection stats.wholeCollection = self.wholeCollection
self.report = stats.report(type=self.period) self.report = stats.report(type=self.period)
self.form.web.title = "deck stats"
self.form.web.stdHtml( self.form.web.stdHtml(
"<html><body>" + self.report + "</body></html>", js=["jquery.js", "plot.js"] "<html><body>" + self.report + "</body></html>", js=["jquery.js", "plot.js"]
) )

View file

@ -101,9 +101,11 @@ class AnkiWebPage(QWebEnginePage): # type: ignore
class AnkiWebView(QWebEngineView): # type: ignore class AnkiWebView(QWebEngineView): # type: ignore
def __init__(self, parent: Optional[QWidget] = None) -> None: def __init__(
self, parent: Optional[QWidget] = None, title: str = "default"
) -> None:
QWebEngineView.__init__(self, parent=parent) # type: ignore QWebEngineView.__init__(self, parent=parent) # type: ignore
self.title = "default" self.title = title
self._page = AnkiWebPage(self._onBridgeCmd) self._page = AnkiWebPage(self._onBridgeCmd)
self._page.setBackgroundColor(self._getWindowColor()) # reduce flicker self._page.setBackgroundColor(self._getWindowColor()) # reduce flicker