From 9f6b073defb3a56cab7e8c7b0ed3b2e6fa72038f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 27 Mar 2014 16:48:26 +0900 Subject: [PATCH] allow copy context item in info view --- aqt/browser.py | 2 +- aqt/webview.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index 28ca2445b..f167a7b37 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -861,7 +861,7 @@ by clicking on one on the left.""")) d = QDialog(self) l = QVBoxLayout() l.setMargin(0) - w = AnkiWebView() + w = AnkiWebView(canCopy=True) l.addWidget(w) w.stdHtml(info + "

" + reps) bb = QDialogButtonBox(QDialogButtonBox.Close) diff --git a/aqt/webview.py b/aqt/webview.py index 3be755315..54ac42bcd 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -40,7 +40,8 @@ class AnkiWebPage(QWebPage): class AnkiWebView(QWebView): - def __init__(self, canFocus=False): + # canFocus implies canCopy + def __init__(self, canFocus=False, canCopy=False): QWebView.__init__(self) self.setRenderHints( QPainter.TextAntialiasing | @@ -60,6 +61,7 @@ class AnkiWebView(QWebView): # reset each time new html is set; used to detect if still in same state self.key = None self.setCanFocus(canFocus) + self._canCopy = canCopy or canFocus def keyPressEvent(self, evt): if evt.matches(QKeySequence.Copy): @@ -79,7 +81,7 @@ class AnkiWebView(QWebView): QWebView.keyReleaseEvent(self, evt) def contextMenuEvent(self, evt): - if not self.isCardViewer: + if not self._canCopy: return m = QMenu(self) a = m.addAction(_("Copy")) @@ -130,12 +132,9 @@ button { def setBridge(self, bridge): self._bridge.setBridge(bridge) - def setCanFocus(self, isCardViewer=False): - """Set flag to denote if this WebView should follow rules specific to - card display (e.g., allow context menu, copy/paste)""" - - self.isCardViewer = isCardViewer - if self.isCardViewer: + def setCanFocus(self, canFocus=False): + self._canFocus = canFocus + if self._canFocus: self.setFocusPolicy(Qt.WheelFocus) else: self.setFocusPolicy(Qt.NoFocus)