def _flags_tree(self, root: SidebarItem) -> None: icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED) root = self._section_root( root=root, name=tr.browsing_sidebar_flags(), icon=icon, collapse_key=Config.Bool.COLLAPSE_FLAGS, type=SidebarItemType.FLAG_ROOT, ) root.search_node = SearchNode(flag=SearchNode.FLAG_ANY) for flag in load_flags(self.col): root.add_child( SidebarItem( name=flag.label, icon=flag.icon, search_node=flag.search_node, item_type=SidebarItemType.FLAG, id=flag.index, )) root.add_simple( tr.browsing_no_flag(), icon=icon, type=SidebarItemType.FLAG, search_node=SearchNode(flag=SearchNode.FLAG_NONE), )
def _contextMenu(self) -> List[Any]: currentFlag = self.card and self.card.user_flag() opts = [ [ tr.studying_flag_card(), [[ flag.label, f"Ctrl+{flag.index}", self.set_flag_func(flag.index), dict(checked=currentFlag == flag.index), ] for flag in load_flags(self.mw.col)], ], [tr.studying_bury_card(), "-", self.bury_current_card], [tr.actions_set_due_date(), "Ctrl+Shift+D", self.on_set_due], [tr.actions_suspend_card(), "@", self.suspend_current_card], [tr.actions_options(), "O", self.onOptions], [tr.actions_card_info(), "I", self.on_card_info], None, [tr.studying_mark_note(), "*", self.toggle_mark_on_current_note], [tr.studying_bury_note(), "=", self.bury_current_note], [tr.studying_suspend_note(), "!", self.suspend_current_note], [ tr.studying_delete_note(), "Ctrl+Delete", self.delete_current_note ], None, [tr.actions_replay_audio(), "R", self.replayAudio], [tr.studying_pause_audio(), "5", self.on_pause_audio], [tr.studying_audio_5s(), "6", self.on_seek_backward], [tr.studying_audio_and5s(), "7", self.on_seek_forward], [tr.studying_record_own_voice(), "Shift+V", self.onRecordVoice], [tr.studying_replay_own_voice(), "V", self.onReplayRecorded], ] return opts
def _shortcutKeys( self, ) -> Sequence[Union[Tuple[str, Callable], Tuple[Qt.Key, Callable]]]: return [ ("e", self.mw.onEditCurrent), (" ", self.onEnterKey), (Qt.Key_Return, self.onEnterKey), (Qt.Key_Enter, self.onEnterKey), ("m", self.showContextMenu), ("r", self.replayAudio), (Qt.Key_F5, self.replayAudio), *((f"Ctrl+{flag.index}", self.set_flag_func(flag.index)) for flag in load_flags(self.mw.col)), ("*", self.toggle_mark_on_current_note), ("=", self.bury_current_note), ("-", self.bury_current_card), ("!", self.suspend_current_note), ("@", self.suspend_current_card), ("Ctrl+Delete", self.delete_current_note), ("Ctrl+Shift+D", self.on_set_due), ("v", self.onReplayRecorded), ("Shift+v", self.onRecordVoice), ("o", self.onOptions), ("i", self.on_card_info), ("1", lambda: self._answerCard(1)), ("2", lambda: self._answerCard(2)), ("3", lambda: self._answerCard(3)), ("4", lambda: self._answerCard(4)), ("5", self.on_pause_audio), ("6", self.on_seek_backward), ("7", self.on_seek_forward), ]
def _update_flags_menu(self) -> None: flag = self.card and self.card.user_flag() flag = flag or 0 for f in load_flags(self.col): getattr(self.form, f.action).setChecked(flag == f.index) qtMenuShortcutWorkaround(self.form.menuFlag)
def _update_flag_labels(self) -> None: for flag in load_flags(self.col): getattr(self.form, flag.action).setText(flag.label)
def setupMenus(self) -> None: # actions f = self.form # edit qconnect(f.actionUndo.triggered, self.undo) qconnect(f.actionRedo.triggered, self.redo) qconnect(f.actionInvertSelection.triggered, self.table.invert_selection) qconnect(f.actionSelectNotes.triggered, self.selectNotes) if not isMac: f.actionClose.setVisible(False) qconnect(f.actionCreateFilteredDeck.triggered, self.createFilteredDeck) f.actionCreateFilteredDeck.setShortcuts(["Ctrl+G", "Ctrl+Alt+G"]) # notes qconnect(f.actionAdd.triggered, self.mw.onAddCard) qconnect(f.actionAdd_Tags.triggered, self.add_tags_to_selected_notes) qconnect(f.actionRemove_Tags.triggered, self.remove_tags_from_selected_notes) qconnect(f.actionClear_Unused_Tags.triggered, self.clear_unused_tags) qconnect(f.actionToggle_Mark.triggered, self.toggle_mark_of_selected_notes) qconnect(f.actionChangeModel.triggered, self.onChangeModel) qconnect(f.actionFindDuplicates.triggered, self.onFindDupes) qconnect(f.actionFindReplace.triggered, self.onFindReplace) qconnect(f.actionManage_Note_Types.triggered, self.mw.onNoteTypes) qconnect(f.actionDelete.triggered, self.delete_selected_notes) # cards qconnect(f.actionChange_Deck.triggered, self.set_deck_of_selected_cards) qconnect(f.action_Info.triggered, self.showCardInfo) qconnect(f.actionReposition.triggered, self.reposition) qconnect(f.action_set_due_date.triggered, self.set_due_date) qconnect(f.action_forget.triggered, self.forget_cards) qconnect(f.actionToggle_Suspend.triggered, self.suspend_selected_cards) def set_flag_func(desired_flag: int) -> Callable: return lambda: self.set_flag_of_selected_cards(desired_flag) for flag in load_flags(self.col): qconnect( getattr(self.form, flag.action).triggered, set_flag_func(flag.index)) self._update_flag_labels() qconnect(f.actionExport.triggered, self._on_export_notes) # jumps qconnect(f.actionPreviousCard.triggered, self.onPreviousCard) qconnect(f.actionNextCard.triggered, self.onNextCard) qconnect(f.actionFirstCard.triggered, self.onFirstCard) qconnect(f.actionLastCard.triggered, self.onLastCard) qconnect(f.actionFind.triggered, self.onFind) qconnect(f.actionNote.triggered, self.onNote) qconnect(f.actionSidebar.triggered, self.focusSidebar) qconnect(f.actionCardList.triggered, self.onCardList) # help qconnect(f.actionGuide.triggered, self.onHelp) # keyboard shortcut for shift+home/end self.pgUpCut = QShortcut(QKeySequence("Shift+Home"), self) qconnect(self.pgUpCut.activated, self.onFirstCard) self.pgDownCut = QShortcut(QKeySequence("Shift+End"), self) qconnect(self.pgDownCut.activated, self.onLastCard) # add-on hook gui_hooks.browser_menus_did_init(self) self.mw.maybeHideAccelerators(self)