def _on_transcription_button(self): """ Executed when the button on the right top of the editor is pressed. Creates popup menu with different phonetics symbols to print. """ m = QMenu(self.mw) symbols = "æɑɒɔəɜɪʊʌθðŋɹɫʃʒʍʔ" for s in symbols: a = m.addAction(_(s)) a.triggered.connect(lambda ign, _s=s: self.doPaste(_s, True)) m.popup(QCursor.pos())
def add_menu_items(menu_items, parent=None): if not parent: parent = mw.form.menubar for title, action in menu_items: if title == "SEPARATOR": parent.addSeparator() elif isinstance(action, list): menu = QMenu(_(title), parent) parent.insertMenu(mw.form.menuTools.menuAction(), menu) add_menu_items(action, menu) else: checkable = False if isinstance(action, dict): options = action action = options['action'] if 'checkable' in options: checkable = options['checkable'] # if ANKNOTES.DEVELOPER_MODE.ENABLED and ANKNOTES.DEVELOPER_MODE.AUTO_RELOAD_MODULES: action = auto_reload_wrapper(action) # noinspection PyArgumentList menu_action = QAction(_(title), mw, checkable=checkable) parent.addAction(menu_action) parent.connect(menu_action, SIGNAL("triggered()"), action) if checkable: anknotes_checkable_menu_items[title] = menu_action
def additional_menu_styled(editor): # mod of onAdvanced from editor.py config = getconfig() # QMenu(editor.mw) conflict with persistent editor, 1686259334 I get # RuntimeError: super-class __init__() of type AnkiQt was never called m = QMenu() a = m.addAction("Clear more formatting (Classes, etc.)") a.triggered.connect(lambda _: classes_addon_rangy_remove_all(editor)) m.addSeparator() for e in config['v3']: if e.get('Show_in_menu', False): m.addAction(editor.create_menu_entry(e, m)) m.exec_(QCursor.pos())
def showContextMenu(self): opts = [ [_("Mark Note"), "*", self.onMark], [_("Bury Note"), "-", self.onBuryNote], [_("Suspend Card"), "@", self.onSuspendCard], [_("Suspend Note"), "!", self.onSuspend], [_("Delete Note"), "Delete", self.onDelete], [_("Options"), "O", self.onOptions], None, [_("Replay Audio"), "R", self.replayAudio], [_("Record Own Voice"), "Shift+V", self.onRecordVoice], [_("Replay Own Voice"), "V", self.onReplayRecorded], ] m = QMenu(self.mw) for row in opts: if not row: m.addSeparator() continue label, scut, func = row a = m.addAction(label) a.setShortcut(QKeySequence(scut)) a.connect(a, SIGNAL("triggered()"), func) #Only change is the following statement runHook("Reviewer.contextMenuEvent", self, m) m.exec_(QCursor.pos())
def additional_menu_basic(editor): config = getconfig() # mod of onAdvanced from editor.py m = QMenu(editor.mw) # m.setStyleSheet(basic_stylesheet) m.setFont(QFont('Courier New', 11)) a = m.addAction("Clear more formatting (Classes, etc.)") a.triggered.connect(lambda _: classes_addon_rangy_remove_all(editor)) m.addSeparator() for e in config['v3']: if e.get('Show_in_menu', False): text = editor.my_label_text(e, False) a = m.addAction(text) cat = e["Category"] se = e.get("Setting", e.get("Category", False)) a.triggered.connect( lambda _, a=cat, b=se: my_highlight_helper(editor, a, b)) m.exec_(QCursor.pos())
def _showOptions(self, did): m = QMenu(self.mw) a = m.addAction(_("Rename")) a.triggered.connect(lambda b, did=did: self._rename(did)) a = m.addAction(_("Options")) a.triggered.connect(lambda b, did=did: self._options(did)) a = m.addAction(_("Export")) a.triggered.connect(lambda b, did=did: self._export(did)) a = m.addAction(_("Delete")) a.triggered.connect(lambda b, did=did: self._delete(did)) runHook("showDeckOptions", m, did) m.exec_(QCursor.pos())
def confOpts(self): m = QMenu(self.mw) a = m.addAction(_("Add")) a.triggered.connect(self.addGroup) a = m.addAction(_("Delete")) a.triggered.connect(self.remGroup) a = m.addAction(_("Rename")) a.triggered.connect(self.renameGroup) a = m.addAction(_("Set for all subdecks")) a.triggered.connect(self.setChildren) if not self.childDids: a.setEnabled(False) m.exec_(QCursor.pos())
def add_context_menu_action(wv: EditorWebView, m: QMenu): context_data = wv.page().contextMenuData() url = context_data.mediaUrl() image_name = url.fileName() # Using url.path() doesn't return the absolute path # Conpatibility: 2.1.0+ image_path = Path(mw.col.media.dir()) / image_name if url.isValid() and image_path.is_file(): a = m.addAction("Edit Image") a.triggered.connect( lambda _, path=image_path, nm=image_name: open_annotate_window( wv.editor, name=nm, path=path, src=url.toString()))
def contextMenuEvent(self, evt): m = QMenu(self) a = m.addAction(_("Cut")) a.triggered.connect(self.onCut) a = m.addAction(_("Copy")) a.triggered.connect(self.onCopy) a = m.addAction(_("Paste")) a.triggered.connect(self.onPaste) runHook("EditorWebView.contextMenuEvent", self, m) m.popup(QCursor.pos())
def clean_html_menu(editor): m = QMenu(editor.mw) if getUserOption("shortcut_editor_menu_wider_fields"): m.setStyleSheet(basic_stylesheet) for userconfig, text, func in template: cut = getUserOption(userconfig) if cut: text += f"({cut})" a = m.addAction(text) a.triggered.connect(lambda _, e=editor, f=func: f(e)) m.exec_(QCursor.pos())
def setup_browser_menu(browser): menu = QMenu('Kanji Extractor', browser) browser.form.menuEdit.addAction(menu.menuAction()) create_action = QAction("Extract Kanji", browser) create_action.triggered.connect( lambda: create_kanji_notes_browser(browser)) menu.addAction(create_action) update_action = QAction("Update Kanji Notes", browser) update_action.triggered.connect( lambda: update_kanji_notes_browser(browser)) menu.addAction(update_action)
def onHistory(self): m = QMenu(self) for nid in self.history: if self.mw.col.findNotes("nid:%s" % nid): fields = self.mw.col.getNote(nid).fields txt = htmlToTextLine(", ".join(fields)) if len(txt) > 30: txt = txt[:30] + "..." a = m.addAction(_("Edit \"%s\"") % txt) a.triggered.connect(lambda b, nid=nid: self.editHistory(nid)) else: a = m.addAction(_("(Note deleted)")) a.setEnabled(False) runHook("AddCards.onHistory", self, m) m.exec_(self.historyButton.mapToGlobal(QPoint(0, 0)))
def onAdvanced(self): m = QMenu(self.mw) a = m.addAction(_("MathJax inline")) a.triggered.connect(self.insertMathjaxInline) a.setShortcut(QKeySequence("Ctrl+M, M")) a = m.addAction(_("MathJax block")) a.triggered.connect(self.insertMathjaxBlock) a.setShortcut(QKeySequence("Ctrl+M, E")) a = m.addAction(_("MathJax chemistry")) a.triggered.connect(self.insertMathjaxChemistry) a.setShortcut(QKeySequence("Ctrl+M, C")) a = m.addAction(_("LaTeX")) a.triggered.connect(self.insertLatex) a.setShortcut(QKeySequence("Ctrl+T, T")) a = m.addAction(_("LaTeX equation")) a.triggered.connect(self.insertLatexEqn) a.setShortcut(QKeySequence("Ctrl+T, E")) a = m.addAction(_("LaTeX math env.")) a.triggered.connect(self.insertLatexMathEnv) a.setShortcut(QKeySequence("Ctrl+T, M")) a = m.addAction(_("Edit HTML")) a.triggered.connect(self.onHtmlEdit) a.setShortcut(QKeySequence("Ctrl+Shift+X")) qtMenuShortcutWorkaround(m) m.exec_(QCursor.pos())
def connect_menu(main_window, profile_controller, network_thread): # probably overdoing it with partial functions here... but none of these # need to be classes honestly top_menu = QMenu("&Killstreaks", main_window) game_menu = QMenu("Select Game", main_window) halo_3_action = game_menu.addAction("Halo 3") halo_3_action.setCheckable(True) halo_3_action.triggered.connect( partial( set_current_game_id, game_id="halo_3", get_settings_repo=profile_controller.get_settings_repo, on_game_changed=profile_controller.change_game, ) ) mw2_action = game_menu.addAction("Call of Duty: Modern Warfare 2") mw2_action.setCheckable(True) mw2_action.triggered.connect( partial( set_current_game_id, game_id="mw2", get_settings_repo=profile_controller.get_settings_repo, on_game_changed=profile_controller.change_game, ) ) halo_5_action = game_menu.addAction("Halo 5") halo_5_action.setCheckable(True) halo_5_action.triggered.connect( partial( set_current_game_id, game_id="halo_5", get_settings_repo=profile_controller.get_settings_repo, on_game_changed=profile_controller.change_game, ) ) ca_action = game_menu.addAction("Combat Arms") ca_action.setCheckable(True) ca_action.triggered.connect( partial( set_current_game_id, game_id="ca", get_settings_repo=profile_controller.get_settings_repo, on_game_changed=profile_controller.change_game, ) ) top_menu.addMenu(game_menu) game_menu.aboutToShow.connect( partial( check_correct_game_in_menu, menu_actions_by_game_id=dict( halo_3=halo_3_action, mw2=mw2_action, halo_5=halo_5_action, ca=ca_action, ), load_current_game_id=partial( load_current_game_id, get_settings_repo=profile_controller.get_settings_repo, ), ) ) sound_on_action = top_menu.addAction("&Enable sounds") sound_on_action.setCheckable(True) sound_on_action.triggered.connect( partial( toggle_sound_on, get_settings_repo=profile_controller.get_settings_repo, on_sound_on_toggled=profile_controller.on_sound_on_toggled, ) ) auto_switch_game_action = top_menu.addAction("&Automatically Switch Games") auto_switch_game_action.setCheckable(True) auto_switch_game_action.triggered.connect( partial( toggle_auto_switch_game, get_settings_repo=profile_controller.get_settings_repo, on_auto_switch_game_toggled=profile_controller.on_auto_switch_game_toggled, ) ) top_menu.aboutToShow.connect( partial( set_check_for_auto_switch_game, action=auto_switch_game_action, load_auto_switch_game_status=partial( load_auto_switch_game_status, get_settings_repo=profile_controller.get_settings_repo, ), ) ) leaderboard_action = top_menu.addAction("&Leaderboards") leaderboard_action.triggered.connect( lambda: webbrowser.open(networking.sra_base_url) ) profile_settings_action = top_menu.addAction("&Profile settings...") profile_settings_action.triggered.connect( lambda: profile_settings.show_dialog(main_window, network_thread, profile_controller.get_user_repo(), profile_controller.get_achievements_repo()) ) chase_mode_action = top_menu.addAction("&Chase mode") chase_mode_action.setCheckable(True) chase_mode_action.triggered.connect( partial( chase_mode.toggle_chase_mode, profile_controller=profile_controller, main_window=main_window, ) ) top_menu.aboutToShow.connect( partial( set_check_for_show_chase_mode, action=chase_mode_action, get_settings_repo=profile_controller.get_settings_repo ) ) main_window.form.menubar.addMenu(top_menu)
def popupOver(self, widget): qmenu = QMenu() self.renderTo(qmenu) qmenu.exec_(widget.mapToGlobal(QPoint(0,0)))
def setup_menu(): menu = QMenu('Kanji Exctractor', mw) mw.form.menuTools.addAction(menu.menuAction()) # mw.form.menuLookup = menu create_action = QAction('Create Kanji Notes', mw) create_action.triggered.connect(create_kanji_notes) menu.addAction(create_action) settings_action = QAction('Update Kanji Notes', mw) settings_action.triggered.connect(open_settings) menu.addAction(settings_action) settings_action = QAction('Settings', mw) settings_action.triggered.connect(open_settings) menu.addAction(settings_action) about_action = QAction('About...', mw) about_action.triggered.connect(show_about) menu.addAction(about_action)
def onMore(self): m = QMenu(self) if not self._isCloze(): a = m.addAction(_("Add Card Type...")) a.triggered.connect(self.onAddCard) a = m.addAction(_("Remove Card Type...")) a.triggered.connect(self.onRemove) a = m.addAction(_("Rename Card Type...")) a.triggered.connect(self.onRename) a = m.addAction(_("Reposition Card Type...")) a.triggered.connect(self.onReorder) m.addSeparator() t = self.card.template() if t['did']: s = _(" (on)") else: s = _(" (off)") a = m.addAction(_("Deck Override...") + s) a.triggered.connect(self.onTargetDeck) a = m.addAction(_("Browser Appearance...")) a.triggered.connect(self.onBrowserDisplay) m.exec_(self.topAreaForm.templateOptions.mapToGlobal(QPoint(0,0)))
import aqt from aqt import mw, DialogManager, dialogs from aqt.qt import QAction, QInputDialog, QMenu from .importer import AnkidownImporter DialogManager._dialogs["Ankidown-Importer"] = [AnkidownImporter, None] def open_importer(): aqt.dialogs.open("Ankidown-Importer", mw) ankidown_menu = QMenu("Ankidown", mw) a = ankidown_menu.addAction("Import") a.triggered.connect(open_importer) mw.form.menuTools.addMenu(ankidown_menu)
def create_menu(): mn = QMenu() mn.setTitle("Nachschlagen") mw.form.menuTools.addAction(mn.menuAction()) # mw.form.menu_nachschlagen = mn # add actions if show_japanese: # Maybe not show the Japanese actions. wae = QAction(mw) wae.setText("Japanisch bei Wadoku") # wae.setShortcut("Ctrl+4") mn.addAction(wae) mw.connect(wae, SIGNAL("triggered()"), on_lookup_wadoku_expression) wam = QAction(mw) wam.setText("Deutsch bei Wadoku") # wam.setShortcut("Ctrl+2") mn.addAction(wam) mw.connect(wam, SIGNAL("triggered()"), on_lookup_wadoku_meaning) was = QAction(mw) was.setText("Auswahl bei Wadoku") mn.addAction(was) mw.connect(was, SIGNAL("triggered()"), on_lookup_wadoku_selection) if show_saiga: # Personal taste: i like the Kanjilexikon better than the # Saiga look up. So i like this switched off. sae = QAction(mw) sae.setText("Kanji bei Saiga") #sae.setShortcut("Ctrl+4") mn.addAction(sae) mw.connect(sae, SIGNAL("triggered()"), on_lookup_saiga_expression) sas = QAction(mw) sas.setText("Kanjiauswahl bei Saiga") mn.addAction(sas) mw.connect(sas, SIGNAL("triggered()"), on_lookup_saiga_selection) kle = QAction(mw) kle.setText("Kanji bei Kanji-Lexikon") # kle.setShortcut("Ctrl+4") mn.addAction(kle) mw.connect(kle, SIGNAL("triggered()"), on_lookup_kl_expression) kls = QAction(mw) kls.setText("Kanjiauswahl bei Kanji-Lexikon") mn.addAction(kls) mw.connect(kls, SIGNAL("triggered()"), on_lookup_kl_selection) # Show these always. fae = QAction(mw) fae.setText("Ausdruck bei Forvo") # fae.setShortcut("Ctrl+4") mn.addAction(fae) mw.connect(fae, SIGNAL("triggered()"), on_lookup_forvo_expression) fas = QAction(mw) fas.setText("Auswahl bei Forvo") mn.addAction(fas) mw.connect(fas, SIGNAL("triggered()"), on_lookup_forvo_selection)
def create_menu(): u"""Set up the menu.""" mn = QMenu() mn.setTitle("Nachschlagen") mw.form.menuTools.addAction(mn.menuAction()) # mw.form.menu_nachschlagen = mn # add actions if show_japanese: # Maybe not show the Japanese actions. wae = QAction(mw) wae.setText("Japanisch bei Wadoku") # wae.setShortcut("Ctrl+4") mn.addAction(wae) mw.connect(wae, SIGNAL("triggered()"), on_lookup_wadoku_expression) wam = QAction(mw) wam.setText("Deutsch bei Wadoku") # wam.setShortcut("Ctrl+2") mn.addAction(wam) mw.connect(wam, SIGNAL("triggered()"), on_lookup_wadoku_meaning) was = QAction(mw) was.setText("Auswahl bei Wadoku") mn.addAction(was) mw.connect(was, SIGNAL("triggered()"), on_lookup_wadoku_selection) if show_saiga: # Personal taste: i like the Kanjilexikon better than the # Saiga look up. So i like this switched off. sae = QAction(mw) sae.setText("Kanji bei Saiga") #sae.setShortcut("Ctrl+4") mn.addAction(sae) mw.connect(sae, SIGNAL("triggered()"), on_lookup_saiga_expression) sas = QAction(mw) sas.setText("Kanjiauswahl bei Saiga") mn.addAction(sas) mw.connect(sas, SIGNAL("triggered()"), on_lookup_saiga_selection) kle = QAction(mw) kle.setText("Kanji bei Kanji-Lexikon") # kle.setShortcut("Ctrl+4") mn.addAction(kle) mw.connect(kle, SIGNAL("triggered()"), on_lookup_kl_expression) kls = QAction(mw) kls.setText("Kanjiauswahl bei Kanji-Lexikon") mn.addAction(kls) mw.connect(kls, SIGNAL("triggered()"), on_lookup_kl_selection) # Show these always. fae = QAction(mw) fae.setText("Ausdruck bei Forvo") # fae.setShortcut("Ctrl+4") mn.addAction(fae) mw.connect(fae, SIGNAL("triggered()"), on_lookup_forvo_expression) fas = QAction(mw) fas.setText("Auswahl bei Forvo") mn.addAction(fas) mw.connect(fas, SIGNAL("triggered()"), on_lookup_forvo_selection)
def setupMenu(browser): o = QMenu("Export selected ...", browser) browser.form.menuEdit.addMenu(o) s = QMenu("cards with columns shown", browser) o.addMenu(s) s_csv = QMenu(".. to csv", browser) s.addMenu(s_csv) s_xls = QMenu(".. to xlsx", browser) s.addMenu(s_xls) u = s_csv.addAction("keep html") u.triggered.connect( lambda _, b=browser: exp_brows_visi(b, ftype="csv", keephtml=True)) u = s_csv.addAction("remove html") u.triggered.connect( lambda _, b=browser: exp_brows_visi(b, ftype="csv", keephtml=False)) u = s_xls.addAction("keep html") u.triggered.connect( lambda _, b=browser: exp_brows_visi(b, ftype="xlsx", keephtml=True)) u = s_xls.addAction("remove html") u.triggered.connect( lambda _, b=browser: exp_brows_visi(b, ftype="xlsx", keephtml=False)) m = QMenu("according to add-on settings", browser) o.addMenu(m) c = QMenu("cards to ...", browser) m.addMenu(c) c_csv = QMenu(".. to csv", browser) c.addMenu(c_csv) c_xls = QMenu(".. to xlsx", browser) c.addMenu(c_xls) n = QMenu("underlying notes of selected cards to ...", browser) m.addMenu(n) ncsv = QMenu(".. to csv, one file per note type ...", browser) n.addMenu(ncsv) nxls = QMenu(".. to xlsx ", browser) n.addMenu(nxls) u = c_csv.addAction("keep html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="csv", keephtml=True, notesonly=False)) u = c_csv.addAction("remove html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="csv", keephtml=False, notesonly=False)) u = c_xls.addAction("keep html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="xlsx", keephtml=True, notesonly=False)) u = c_xls.addAction("remove html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="xlsx", keephtml=False, notesonly=False)) u = ncsv.addAction("keep html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="csv", keephtml=True, notesonly=True)) u = ncsv.addAction("remove html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="csv", keephtml=False, notesonly=True)) u = nxls.addAction("keep html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="xlsx", keephtml=True, notesonly=True)) u = nxls.addAction("remove html") u.triggered.connect(lambda _, b=browser: exp( b, ftype="xlsx", keephtml=False, notesonly=True))
# #if config: # window = gui.LinkDialogue() # setattr(mw, LINK_DLG_NAME, window) # window.exec_() # #else: # # showInfo("Unable to load config. Make sure that config.json " # # "is present and not in use by other applications") def parse_saved_wl(): mw.wl_pareser = WParseSavedWL() mw.wl_pareser.parse() mw.edit_cambridge_submenu = QMenu(u"&Cambridge Dictionary", mw) mw.form.menuEdit.addSeparator() mw.form.menuEdit.addMenu(mw.edit_cambridge_submenu) # Single word mw.create_notes_from_link_action = QAction(mw) mw.create_notes_from_link_action.setText("Create new note(s) from link") mw.create_notes_from_link_action.setToolTip("Fetch word definitions from provided link.") mw.create_notes_from_link_action.setShortcut(CREATE_NEW_NOTES_SHORTCUT) mw.create_notes_from_link_action.triggered.connect(ask_user_for_link) mw.edit_cambridge_submenu.addAction(mw.create_notes_from_link_action) # Word list - saved mw.parse_saved_wl_action = QAction(mw) mw.parse_saved_wl_action.setText("Fetch new words from user wordlists") mw.parse_saved_wl_action.setToolTip("Fetch new words from user wordlists")
def contextMenuEvent(self, evt): m = QMenu(self) a = m.addAction(_("Copy")) a.triggered.connect(self.onCopy) runHook("AnkiWebView.contextMenuEvent", self, m) m.popup(QCursor.pos())