From 30736ddf7562e9c7f96c18aebcab13e6d3192c1e Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 19 May 2021 10:34:36 +0200 Subject: [PATCH] Use custom flag labels for browser actions --- qt/aqt/browser/browser.py | 6 ++++++ qt/aqt/browser/sidebar/tree.py | 1 + qt/aqt/utils.py | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index 95eddfd2a..3d9449842 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -42,6 +42,7 @@ from aqt.utils import ( current_top_level_widget, ensure_editor_saved, getTag, + load_flags, no_arg_trigger, openHelp, qtMenuShortcutWorkaround, @@ -176,6 +177,7 @@ class Browser(QMainWindow): qconnect( f.actionBlue_Flag.triggered, lambda: self.set_flag_of_selected_cards(4) ) + self._update_flag_labels() qconnect(f.actionExport.triggered, self._on_export_notes) # jumps qconnect(f.actionPreviousCard.triggered, self.onPreviousCard) @@ -723,6 +725,10 @@ where id in %s""" qtMenuShortcutWorkaround(self.form.menuFlag) + def _update_flag_labels(self) -> None: + for flag in load_flags(self.col): + getattr(self.form, flag[3]).setText(flag[0]) + def toggle_mark_of_selected_notes(self, checked: bool) -> None: if checked: self.add_tags_to_selected_notes(tags=MARKED_TAG) diff --git a/qt/aqt/browser/sidebar/tree.py b/qt/aqt/browser/sidebar/tree.py index 573979938..f29e3cc5e 100644 --- a/qt/aqt/browser/sidebar/tree.py +++ b/qt/aqt/browser/sidebar/tree.py @@ -875,6 +875,7 @@ class SidebarTreeView(QTreeView): labels[str(item.id)] = new_name self.col.set_config("flagLabels", labels) item.name = new_name + self.browser._update_flag_labels() self.refresh() # Decks diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 7a96d8c6c..4e1bdfc22 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -1026,7 +1026,7 @@ def no_arg_trigger(func: Callable) -> Callable: return pyqtSlot()(func) # type: ignore -def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode]]: +def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode, str]]: labels = cast(Dict[str, str], col.get_config("flagLabels", {})) icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED) @@ -1035,21 +1035,25 @@ def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode]]: labels["1"] if "1" in labels else tr.actions_red_flag(), icon.with_color(colors.FLAG1_FG), SearchNode(flag=SearchNode.FLAG_RED), + "actionRed_Flag", ), ( labels["2"] if "2" in labels else tr.actions_orange_flag(), icon.with_color(colors.FLAG2_FG), SearchNode(flag=SearchNode.FLAG_ORANGE), + "actionOrange_Flag", ), ( labels["3"] if "3" in labels else tr.actions_green_flag(), icon.with_color(colors.FLAG3_FG), SearchNode(flag=SearchNode.FLAG_GREEN), + "actionGreen_Flag", ), ( labels["4"] if "4" in labels else tr.actions_blue_flag(), icon.with_color(colors.FLAG4_FG), SearchNode(flag=SearchNode.FLAG_BLUE), + "actionBlue_Flag", ), ]