mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
allow all ankiwebview instances to take focus
the canFocus/canCopy separate variables was silly, as we ended up with text that could be copied from the context menu but not with a shortcut key. also we default to allowing focus now, since that's the more sensible default. fixes copy issues with card info dialog and some addons
This commit is contained in:
parent
70db1035b1
commit
ece78a7d11
5 changed files with 8 additions and 12 deletions
|
@ -875,7 +875,7 @@ by clicking on one on the left."""))
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
l = QVBoxLayout()
|
l = QVBoxLayout()
|
||||||
l.setMargin(0)
|
l.setMargin(0)
|
||||||
w = AnkiWebView(canCopy=True)
|
w = AnkiWebView()
|
||||||
l.addWidget(w)
|
l.addWidget(w)
|
||||||
w.stdHtml(info + "<p>" + reps)
|
w.stdHtml(info + "<p>" + reps)
|
||||||
bb = QDialogButtonBox(QDialogButtonBox.Close)
|
bb = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
|
@ -1010,7 +1010,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(True)
|
self._previewWeb = AnkiWebView()
|
||||||
vbox.addWidget(self._previewWeb)
|
vbox.addWidget(self._previewWeb)
|
||||||
bbox = QDialogButtonBox()
|
bbox = QDialogButtonBox()
|
||||||
self._previewReplay = bbox.addButton(_("Replay Audio"), QDialogButtonBox.ActionRole)
|
self._previewReplay = bbox.addButton(_("Replay Audio"), 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(True)
|
pform.frontWeb = AnkiWebView()
|
||||||
pform.frontPrevBox.addWidget(pform.frontWeb)
|
pform.frontPrevBox.addWidget(pform.frontWeb)
|
||||||
pform.backWeb = AnkiWebView(True)
|
pform.backWeb = AnkiWebView()
|
||||||
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(
|
||||||
|
|
|
@ -987,7 +987,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, canFocus=True)
|
AnkiWebView.__init__(self)
|
||||||
self.editor = editor
|
self.editor = editor
|
||||||
self.strip = self.editor.mw.pm.profile['stripHTML']
|
self.strip = self.editor.mw.pm.profile['stripHTML']
|
||||||
|
|
||||||
|
|
|
@ -417,12 +417,10 @@ 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.setCanFocus(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.setCanFocus(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)."
|
||||||
|
@ -518,7 +516,7 @@ title="%s">%s</button>''' % (
|
||||||
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(canFocus=True)
|
self.web = aqt.webview.AnkiWebView()
|
||||||
self.web.setObjectName("mainText")
|
self.web.setObjectName("mainText")
|
||||||
self.web.setFocusPolicy(Qt.WheelFocus)
|
self.web.setFocusPolicy(Qt.WheelFocus)
|
||||||
self.web.setMinimumWidth(400)
|
self.web.setMinimumWidth(400)
|
||||||
|
|
|
@ -40,8 +40,7 @@ class AnkiWebPage(QWebPage):
|
||||||
|
|
||||||
class AnkiWebView(QWebView):
|
class AnkiWebView(QWebView):
|
||||||
|
|
||||||
# canFocus implies canCopy
|
def __init__(self, canFocus=True):
|
||||||
def __init__(self, canFocus=False, canCopy=False):
|
|
||||||
QWebView.__init__(self)
|
QWebView.__init__(self)
|
||||||
self.setRenderHints(
|
self.setRenderHints(
|
||||||
QPainter.TextAntialiasing |
|
QPainter.TextAntialiasing |
|
||||||
|
@ -61,7 +60,6 @@ class AnkiWebView(QWebView):
|
||||||
# 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.setCanFocus(canFocus)
|
self.setCanFocus(canFocus)
|
||||||
self._canCopy = canCopy or canFocus
|
|
||||||
|
|
||||||
def keyPressEvent(self, evt):
|
def keyPressEvent(self, evt):
|
||||||
if evt.matches(QKeySequence.Copy):
|
if evt.matches(QKeySequence.Copy):
|
||||||
|
@ -81,7 +79,7 @@ class AnkiWebView(QWebView):
|
||||||
QWebView.keyReleaseEvent(self, evt)
|
QWebView.keyReleaseEvent(self, evt)
|
||||||
|
|
||||||
def contextMenuEvent(self, evt):
|
def contextMenuEvent(self, evt):
|
||||||
if not self._canCopy:
|
if not self._canFocus:
|
||||||
return
|
return
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
a = m.addAction(_("Copy"))
|
a = m.addAction(_("Copy"))
|
||||||
|
|
Loading…
Reference in a new issue