mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Issue #998: Allow copy/paste and context menu in all card windows.
This commit is contained in:
parent
3b20de173f
commit
a12e6f6b65
4 changed files with 18 additions and 8 deletions
|
@ -986,8 +986,7 @@ where id in %s""" % ids2str(sf))
|
||||||
c(self._previewWindow, SIGNAL("finished(int)"), self._onPreviewFinished)
|
c(self._previewWindow, SIGNAL("finished(int)"), self._onPreviewFinished)
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
vbox.setMargin(0)
|
vbox.setMargin(0)
|
||||||
self._previewWeb = AnkiWebView()
|
self._previewWeb = AnkiWebView(True)
|
||||||
self._previewWeb.setFocusPolicy(Qt.NoFocus)
|
|
||||||
vbox.addWidget(self._previewWeb)
|
vbox.addWidget(self._previewWeb)
|
||||||
bbox = QDialogButtonBox()
|
bbox = QDialogButtonBox()
|
||||||
self._previewPrev = bbox.addButton("<", QDialogButtonBox.ActionRole)
|
self._previewPrev = bbox.addButton("<", QDialogButtonBox.ActionRole)
|
||||||
|
|
|
@ -120,9 +120,9 @@ class CardLayout(QDialog):
|
||||||
self.model, joinFields(self.note.fields)))
|
self.model, joinFields(self.note.fields)))
|
||||||
for g in pform.groupBox, pform.groupBox_2:
|
for g in pform.groupBox, pform.groupBox_2:
|
||||||
g.setTitle(g.title() + _(" (1 of %d)") % max(cnt, 1))
|
g.setTitle(g.title() + _(" (1 of %d)") % max(cnt, 1))
|
||||||
pform.frontWeb = AnkiWebView()
|
pform.frontWeb = AnkiWebView(True)
|
||||||
pform.frontPrevBox.addWidget(pform.frontWeb)
|
pform.frontPrevBox.addWidget(pform.frontWeb)
|
||||||
pform.backWeb = AnkiWebView()
|
pform.backWeb = AnkiWebView(True)
|
||||||
pform.backPrevBox.addWidget(pform.backWeb)
|
pform.backPrevBox.addWidget(pform.backWeb)
|
||||||
for wig in pform.frontWeb, pform.backWeb:
|
for wig in pform.frontWeb, pform.backWeb:
|
||||||
wig.page().setLinkDelegationPolicy(
|
wig.page().setLinkDelegationPolicy(
|
||||||
|
|
|
@ -409,10 +409,12 @@ the manual for information on how to restore from an automatic backup."))
|
||||||
|
|
||||||
def _reviewState(self, oldState):
|
def _reviewState(self, oldState):
|
||||||
self.reviewer.show()
|
self.reviewer.show()
|
||||||
|
self.web.setCardViewer(True)
|
||||||
|
|
||||||
def _reviewCleanup(self, newState):
|
def _reviewCleanup(self, newState):
|
||||||
if newState != "resetRequired" and newState != "review":
|
if newState != "resetRequired" and newState != "review":
|
||||||
self.reviewer.cleanup()
|
self.reviewer.cleanup()
|
||||||
|
self.web.setCardViewer(False)
|
||||||
|
|
||||||
def noteChanged(self, nid):
|
def noteChanged(self, nid):
|
||||||
"Called when a card or note is edited (but not deleted)."
|
"Called when a card or note is edited (but not deleted)."
|
||||||
|
|
|
@ -40,7 +40,7 @@ class AnkiWebPage(QWebPage):
|
||||||
|
|
||||||
class AnkiWebView(QWebView):
|
class AnkiWebView(QWebView):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, isCardViewer=False):
|
||||||
QWebView.__init__(self)
|
QWebView.__init__(self)
|
||||||
self.setRenderHints(
|
self.setRenderHints(
|
||||||
QPainter.TextAntialiasing |
|
QPainter.TextAntialiasing |
|
||||||
|
@ -59,6 +59,7 @@ class AnkiWebView(QWebView):
|
||||||
self.allowDrops = False
|
self.allowDrops = False
|
||||||
# reset each time new html is set; used to detect if still in same state
|
# reset each time new html is set; used to detect if still in same state
|
||||||
self.key = None
|
self.key = None
|
||||||
|
self.setCardViewer(isCardViewer)
|
||||||
|
|
||||||
def keyPressEvent(self, evt):
|
def keyPressEvent(self, evt):
|
||||||
if evt.matches(QKeySequence.Copy):
|
if evt.matches(QKeySequence.Copy):
|
||||||
|
@ -78,9 +79,7 @@ class AnkiWebView(QWebView):
|
||||||
QWebView.keyReleaseEvent(self, evt)
|
QWebView.keyReleaseEvent(self, evt)
|
||||||
|
|
||||||
def contextMenuEvent(self, evt):
|
def contextMenuEvent(self, evt):
|
||||||
# lazy: only run in reviewer
|
if not self.isCardViewer:
|
||||||
import aqt
|
|
||||||
if aqt.mw.state != "review":
|
|
||||||
return
|
return
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
a = m.addAction(_("Copy"))
|
a = m.addAction(_("Copy"))
|
||||||
|
@ -131,6 +130,16 @@ button {
|
||||||
def setBridge(self, bridge):
|
def setBridge(self, bridge):
|
||||||
self._bridge.setBridge(bridge)
|
self._bridge.setBridge(bridge)
|
||||||
|
|
||||||
|
def setCardViewer(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:
|
||||||
|
self.setFocusPolicy(Qt.WheelFocus)
|
||||||
|
else:
|
||||||
|
self.setFocusPolicy(Qt.NoFocus)
|
||||||
|
|
||||||
def eval(self, js):
|
def eval(self, js):
|
||||||
self.page().mainFrame().evaluateJavaScript(js)
|
self.page().mainFrame().evaluateJavaScript(js)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue