From 320b6062ca3c7e931820fe86d3ffaeaae80c270a Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 25 Feb 2022 11:50:28 -0300 Subject: [PATCH] [view] improvement: displaying tips for some custom actions (on mouse hover) --- CHANGELOG.md | 1 + bauh/api/abstract/model.py | 19 ++++++++++++++----- bauh/view/qt/apps_table.py | 2 ++ bauh/view/qt/window.py | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aed5e426..b5df2f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - UI - upgrade summary dialog size + - displaying tips for some custom actions (on mouse hover) - screenshots: displaying the current image index as a label in the button bar (e.g: 1/3) ## [0.9.28] 2022-02-14 diff --git a/bauh/api/abstract/model.py b/bauh/api/abstract/model.py index c9e8cce6..d33bfc06 100644 --- a/bauh/api/abstract/model.py +++ b/bauh/api/abstract/model.py @@ -12,7 +12,8 @@ class CustomSoftwareAction: backup: bool = False, refresh: bool = True, i18n_confirm_key: str = None, requires_internet: bool = False, - requires_confirmation: bool = True): + requires_confirmation: bool = True, + i18n_description_key: Optional[str] = None): """ :param i18n_label_key: the i18n key that will be used to display the action name :param i18n_status_key: the i18n key that will be used to display the action name being executed @@ -21,10 +22,11 @@ class CustomSoftwareAction: :param manager: the instance that will execute the action ( optional ) :param backup: if a system backup should be performed before executing the action :param requires_root: - :param refresh: if the a full app refresh should be done if the action succeeds + :param refresh: if all displayed apps on the view should be refreshed if the action succeeds :param i18n_confirm_key: action confirmation message :param requires_internet: if the action requires internet connection to be executed :param requires_confirmation: if a confirmation popup should be displayed to the user before calling the action + :param i18n_description_key: the i18n key for the action description """ self.i18n_label_key = i18n_label_key self.i18n_status_key = i18n_status_key @@ -37,12 +39,19 @@ class CustomSoftwareAction: self.i18n_confirm_key = i18n_confirm_key self.requires_internet = requires_internet self.requires_confirmation = requires_confirmation + self.i18n_description_key = i18n_description_key - def __hash__(self): - return self.i18n_label_key.__hash__() + self.i18n_status_key.__hash__() + self.manager_method.__hash__() + def __hash__(self) -> int: + return sum(hash(val) for val in self.__dict__.values()) + + def __eq__(self, other) -> bool: + if isinstance(other, CustomSoftwareAction): + return self.__dict__ == other.__dict__ + + return False def __repr__(self): - return "CustomAction (label={}, method={})".format(self.i18n_label_key, self.manager_method) + return f"{self.__class__.__name__} (label={self.i18n_label_key}, method={self.manager_method})" class PackageStatus(Enum): diff --git a/bauh/view/qt/apps_table.py b/bauh/view/qt/apps_table.py index 92afff82..744615f9 100644 --- a/bauh/view/qt/apps_table.py +++ b/bauh/view/qt/apps_table.py @@ -176,9 +176,11 @@ class PackagesTable(QTableWidget): i18n=self.i18n).ask(): self.window.begin_execute_custom_action(pkg, action) + tip = self.i18n[action.i18n_description_key] if action.i18n_description_key else None return QCustomMenuAction(parent=parent, label=self.i18n[action.i18n_label_key], icon=QIcon(action.icon_path) if action.icon_path else None, + tooltip=tip, action=custom_action) def refresh(self, pkg: PackageView): diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 233f7eb0..d7780285 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -1508,9 +1508,11 @@ class ManageWindow(QWidget): else: icon = None + tip = self.i18n[action.i18n_description_key] if action.i18n_description_key else None return QCustomMenuAction(parent=parent, label=self.i18n[action.i18n_label_key], action=lambda: self.begin_execute_custom_action(None, action), + tooltip=tip, icon=icon) def show_custom_actions(self):