provide easy access to browser from preview/dupes handlers

This commit is contained in:
Damien Elmes 2020-02-12 08:28:21 +10:00
parent 2c4c8d4ab0
commit 3425bee968

View File

@ -2,12 +2,15 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
import html import html
import json import json
import re import re
import sre_constants import sre_constants
import time import time
import unicodedata import unicodedata
from dataclasses import dataclass
from operator import itemgetter from operator import itemgetter
from typing import Callable, List, Optional, Union from typing import Callable, List, Optional, Union
@ -51,12 +54,16 @@ from aqt.utils import (
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
class PreviewDialog(QDialog): @dataclass
pass class PreviewDialog:
dialog: QDialog
browser: Browser
class FindDupesDialog(QDialog): @dataclass
pass class FindDupesDialog:
dialog: QDialog
browser: Browser
# Data model # Data model
@ -1547,7 +1554,7 @@ where id in %s"""
def _openPreview(self): def _openPreview(self):
self._previewState = "question" self._previewState = "question"
self._lastPreviewState = None self._lastPreviewState = None
self._previewWindow = PreviewDialog(None, Qt.Window) self._previewWindow = QDialog(None, Qt.Window)
self._previewWindow.setWindowTitle(_("Preview")) self._previewWindow.setWindowTitle(_("Preview"))
self._previewWindow.finished.connect(self._onPreviewFinished) self._previewWindow.finished.connect(self._onPreviewFinished)
@ -1653,7 +1660,8 @@ where id in %s"""
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc
) )
self._previewWeb.set_bridge_command( self._previewWeb.set_bridge_command(
self._on_preview_bridge_cmd, self._previewWindow self._on_preview_bridge_cmd,
PreviewDialog(dialog=self._previewWindow, browser=self),
) )
def _on_preview_bridge_cmd(self, cmd: str) -> Any: def _on_preview_bridge_cmd(self, cmd: str) -> Any:
@ -2139,7 +2147,7 @@ update cards set usn=?, mod=?, did=? where id in """
self.editor.saveNow(self._onFindDupes) self.editor.saveNow(self._onFindDupes)
def _onFindDupes(self): def _onFindDupes(self):
d = FindDupesDialog(self) d = QDialog(self)
self.mw.setupDialogGC(d) self.mw.setupDialogGC(d)
frm = aqt.forms.finddupes.Ui_Dialog() frm = aqt.forms.finddupes.Ui_Dialog()
frm.setupUi(d) frm.setupUi(d)
@ -2150,7 +2158,9 @@ 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.set_bridge_command(self.dupeLinkClicked, d) frm.webView.set_bridge_command(
self.dupeLinkClicked, FindDupesDialog(dialog=d, browser=self)
)
def onFin(code): def onFin(code):
saveGeom(d, "findDupes") saveGeom(d, "findDupes")