From 1603a5224eaef16f4ece3fe6db314fbf79c3e4ef Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 5 Feb 2019 14:37:07 +1000 Subject: [PATCH] fix context menu in editor, and move workaround into shared function --- aqt/browser.py | 12 +++++------- aqt/editor.py | 5 ++++- aqt/reviewer.py | 6 +++--- aqt/utils.py | 6 ++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index f2620d8e8..8a4cfa371 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -20,7 +20,7 @@ from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, \ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \ saveHeader, restoreHeader, saveState, restoreState, getTag, \ showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \ - getOnlyText, MenuList, SubMenu + getOnlyText, MenuList, SubMenu, qtMenuShortcutWorkaround from anki.hooks import runHook, addHook, remHook, runFilter from aqt.webview import AnkiWebView from anki.consts import * @@ -475,14 +475,12 @@ class Browser(QMainWindow): m = QMenu() for act in self.form.menu_Cards.actions(): m.addAction(act) - if qtminor >= 10: - act.setShortcutVisibleInContextMenu(True) m.addSeparator() for act in self.form.menu_Notes.actions(): m.addAction(act) - if qtminor >= 10: - act.setShortcutVisibleInContextMenu(True) runHook("browser.onContextMenu", self, m) + + qtMenuShortcutWorkaround(m) m.exec_(QCursor.pos()) def updateFont(self): @@ -1586,8 +1584,8 @@ update cards set usn=?, mod=?, did=? where id in """ + scids, for c, act in enumerate(flagActions): act.setChecked(flag == c+1) - if qtminor >= 10: - act.setShortcutVisibleInContextMenu(True) + + qtMenuShortcutWorkaround(self.form.menuFlag) def onMark(self, mark=None): if mark is None: diff --git a/aqt/editor.py b/aqt/editor.py index 0031e1bd4..251322847 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -21,7 +21,7 @@ from anki.hooks import runHook, runFilter, addHook from aqt.sound import getAudio from aqt.webview import AnkiWebView from aqt.utils import shortcut, showInfo, showWarning, getFile, \ - openHelp, tooltip, downArrow + openHelp, tooltip, downArrow, qtMenuShortcutWorkaround import aqt from bs4 import BeautifulSoup import requests @@ -777,6 +777,9 @@ to a cloze type first, via Edit>Change Note Type.""")) a = m.addAction(_("Edit HTML")) a.triggered.connect(self.onHtmlEdit) a.setShortcut(QKeySequence("Ctrl+Shift+X")) + + qtMenuShortcutWorkaround(m) + m.exec_(QCursor.pos()) # LaTeX diff --git a/aqt/reviewer.py b/aqt/reviewer.py index 765c3ee00..c6d0b57c9 100644 --- a/aqt/reviewer.py +++ b/aqt/reviewer.py @@ -14,7 +14,7 @@ from anki.utils import stripHTML, json, bodyClass from anki.hooks import addHook, runHook, runFilter from anki.sound import playFromText, clearAudioQueue, play from aqt.utils import mungeQA, tooltip, askUserDialog, \ - downArrow + downArrow, qtMenuShortcutWorkaround from aqt.sound import getAudio import aqt @@ -614,6 +614,7 @@ time = %(time)d; self._addMenuItems(m, opts) runHook("Reviewer.contextMenuEvent", self, m) + qtMenuShortcutWorkaround(m) m.exec_(QCursor.pos()) def _addMenuItems(self, m, rows): @@ -624,6 +625,7 @@ time = %(time)d; if len(row) == 2: subm = m.addMenu(row[0]) self._addMenuItems(subm, row[1]) + qtMenuShortcutWorkaround(subm) continue if len(row) == 4: label, scut, func, opts = row @@ -631,8 +633,6 @@ time = %(time)d; label, scut, func = row opts = {} a = m.addAction(label) - if qtminor >= 10: - a.setShortcutVisibleInContextMenu(True) if scut: a.setShortcut(QKeySequence(scut)) if opts.get("checked"): diff --git a/aqt/utils.py b/aqt/utils.py index f38f5384a..9bd49aea1 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -517,6 +517,12 @@ class MenuItem: a = qmenu.addAction(self.title) a.triggered.connect(self.func) +def qtMenuShortcutWorkaround(qmenu): + if qtminor < 10: + return + for act in qmenu.actions(): + act.setShortcutVisibleInContextMenu(True) + ###################################################################### def versionWithBuild():