From d711e343fb936debe91c58a3ca5eea369bcb2f04 Mon Sep 17 00:00:00 2001 From: goszpeti Date: Thu, 3 Oct 2024 16:42:19 +0200 Subject: [PATCH] Speed up dark mode change * Remove context menu from app link --- .../ui/views/app_grid/__init__.py | 4 +- .../ui/views/app_grid/app_link.py | 60 +++---------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/src/conan_explorer/ui/views/app_grid/__init__.py b/src/conan_explorer/ui/views/app_grid/__init__.py index 393d54d5..d260e144 100644 --- a/src/conan_explorer/ui/views/app_grid/__init__.py +++ b/src/conan_explorer/ui/views/app_grid/__init__.py @@ -110,7 +110,9 @@ def _init_right_menu(self): ) def reload_themed_icons(self): - self.re_init(self.model) + for tab in self.get_tabs(): + for app_link in tab.app_links: + app_link.reload_themed_icons() T = TypeVar("T") diff --git a/src/conan_explorer/ui/views/app_grid/app_link.py b/src/conan_explorer/ui/views/app_grid/app_link.py index 6f2fe939..ca3ccc59 100644 --- a/src/conan_explorer/ui/views/app_grid/app_link.py +++ b/src/conan_explorer/ui/views/app_grid/app_link.py @@ -1,15 +1,13 @@ from pathlib import Path from typing import TYPE_CHECKING, Optional -from PySide6.QtCore import Qt -from PySide6.QtGui import QAction, QIcon -from PySide6.QtWidgets import QDialog, QFrame, QMenu, QMessageBox, QWidget +from PySide6.QtWidgets import QDialog, QFrame, QMessageBox, QWidget from typing_extensions import override from conan_explorer import ICON_SIZE, INVALID_PATH from conan_explorer.app.logger import Logger -from conan_explorer.app.system import open_in_file_manager, run_file -from conan_explorer.ui.common import get_themed_asset_icon, measure_font_width +from conan_explorer.app.system import run_file +from conan_explorer.ui.common import ThemedWidget, measure_font_width from conan_explorer.ui.dialogs.reorder import ReorderDialog from .dialogs import AppEditDialog @@ -24,7 +22,7 @@ current_dir = Path(__file__).parent -class ListAppLink(QFrame): +class ListAppLink(QFrame, ThemedWidget): """Represents a clickable button + info for an executable in a conan package. Rightclick context menu has the following elements: - Show in File Manager @@ -43,7 +41,9 @@ def __init__( model: UiAppLinkModel, icon_size=ICON_SIZE, ): - super().__init__(parent) + QFrame.__init__(self, parent) + ThemedWidget.__init__(self) + self.setObjectName(repr(self)) self.icon_size = icon_size self.model = model @@ -54,49 +54,13 @@ def __init__( self._ui = Ui_Form() self._ui.setupUi(self) - self._ui.edit_button.setIcon(QIcon(get_themed_asset_icon("icons/edit.svg"))) - self._ui.remove_button.setIcon(QIcon(get_themed_asset_icon("icons/delete.svg"))) - self._ui.app_button.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - self._ui.app_button.customContextMenuRequested.connect(self.on_context_menu_requested) + self.set_themed_icon(self._ui.edit_button, "icons/edit.svg") + self.set_themed_icon(self._ui.remove_button, "icons/delete.svg") # connect signals self._ui.app_button.clicked.connect(self.on_click) self._ui.edit_button.clicked.connect(self.open_edit_dialog) self._ui.remove_button.clicked.connect(self.remove) - self._init_context_menu() - - def _init_context_menu(self): - """Setup context menu.""" - self.menu = QMenu() - self.open_fm_action = QAction("Show in File Manager", self) - self.open_fm_action.setIcon(QIcon(get_themed_asset_icon("icons/file_explorer.svg"))) - self.menu.addAction(self.open_fm_action) - self.open_fm_action.triggered.connect(self.on_open_in_file_manager) - - self.menu.addSeparator() - - self.add_action = QAction("Add new App Link", self) - self.add_action.setIcon(QIcon(get_themed_asset_icon("icons/add_link.svg"))) - self.menu.addAction(self.add_action) - self.add_action.triggered.connect(self.open_app_link_add_dialog) - - self.edit_action = QAction("Edit", self) - self.edit_action.setIcon(QIcon(get_themed_asset_icon("icons/edit.svg"))) - self.menu.addAction(self.edit_action) - self.edit_action.triggered.connect(self.open_edit_dialog) - - self.remove_action = QAction("Remove App Link", self) - self.remove_action.setIcon(QIcon(get_themed_asset_icon("icons/delete.svg"))) - self.menu.addAction(self.remove_action) - self.remove_action.triggered.connect(self.remove) - - self.menu.addSeparator() - - self.reorder_action = QAction("Reorder App Links", self) - self.reorder_action.setIcon(QIcon(get_themed_asset_icon("icons/rearrange.svg"))) - self.reorder_action.triggered.connect(self.on_move) - - self.menu.addAction(self.reorder_action) def load(self): self.model.register_update_callback(self.apply_conan_info) @@ -187,12 +151,6 @@ def word_wrap(text: str, max_length: int) -> str: name += " " + new_word if name else new_word return name - def on_context_menu_requested(self, position): - self.menu.exec(self._ui.app_button.mapToGlobal(position)) - - def on_open_in_file_manager(self): - open_in_file_manager(self.model.get_executable_path().parent) - def _apply_new_config(self): self._ui.app_name_label.setText(self.model.name) self._ui.conan_ref_value_label.setText(self.model.conan_ref)