From d62b367b478a8d4248d0755e4d45e076afb747f7 Mon Sep 17 00:00:00 2001 From: bartool Date: Tue, 14 Oct 2025 08:33:08 +0200 Subject: [PATCH] refactor: Centralize resource path management Create a new `settings.py` file to define and manage global application paths. Modify UI components (`split_view_widget.py`, `view_settings_dialog.py`) to use the centralized `ICONS_DIR` path constant instead of hardcoded relative paths for icons. This improves maintainability and makes the application independent of the working directory. --- settings.py | 13 ++++++++ ui/view_settings_dialog.py | 6 ++-- ui/widgets/split_view_widget.py | 56 ++++++++++++++++----------------- 3 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 settings.py diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..53bb9d1 --- /dev/null +++ b/settings.py @@ -0,0 +1,13 @@ +from pathlib import Path + +# Absolutna ścieżka do głównego katalogu projektu +ROOT_DIR = Path(__file__).parent.resolve() + +# Ścieżka do katalogu UI +UI_DIR = ROOT_DIR / "ui" + +# Ścieżka do katalogu z ikonami +ICONS_DIR = UI_DIR / "icons" + +# Ścieżka do katalogu z mediami +MEDIA_DIR = ROOT_DIR / "media" diff --git a/ui/view_settings_dialog.py b/ui/view_settings_dialog.py index c61dafd..383ea6f 100644 --- a/ui/view_settings_dialog.py +++ b/ui/view_settings_dialog.py @@ -2,6 +2,8 @@ from PySide6.QtWidgets import QDialog, QHBoxLayout ,QVBoxLayout, QPushButton, QG from PySide6.QtGui import QIcon from PySide6.QtCore import Qt, QSize, Signal +from settings import ICONS_DIR + ISO_ARR = ["AUTO","100", "200", "400", "800", "1600", "3200"] SPEED_ARR = ["30", "25", "20", "15", "13", "10.3", "8", "6.3", "5", "4", "3.2", "2.5", "2", "1.6", "1.3", "1", "0.8", "0.6", "0.5", "0.4", "0.3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400", "1/500", "1/640", "1/800", "1/1000", "1/1250", "1/1600", "1/2000", "1/2500", "1/3200", "1/4000"] @@ -19,13 +21,13 @@ class LabeledSpinSelector(QWidget): self.title_label = QLabel(title) decrement_button = QToolButton() - decrement_button.setIcon(QIcon("ui/icons/arrow-left-335-svgrepo-com.svg")) + decrement_button.setIcon(QIcon(str(ICONS_DIR / "arrow-left-335-svgrepo-com.svg"))) decrement_button.setFixedSize(button_size, button_size) decrement_button.setIconSize(QSize(icon_size, icon_size)) decrement_button.clicked.connect(self._decrement) increment_button = QToolButton() - increment_button.setIcon(QIcon("ui/icons/arrow-right-336-svgrepo-com.svg")) + increment_button.setIcon(QIcon(str(ICONS_DIR / "arrow-right-336-svgrepo-com.svg"))) increment_button.setFixedSize(button_size, button_size) increment_button.setIconSize(QSize(icon_size, icon_size)) increment_button.clicked.connect(self._increment) diff --git a/ui/widgets/split_view_widget.py b/ui/widgets/split_view_widget.py index 0769801..efeb9e1 100644 --- a/ui/widgets/split_view_widget.py +++ b/ui/widgets/split_view_widget.py @@ -3,6 +3,7 @@ from PySide6.QtGui import QEnterEvent, QPixmap, QWheelEvent, QPainter, QBrush, Q from PySide6.QtCore import Qt, QSize, Signal, QEvent import sys from ui.widgets.placeholder_widget import PlaceholderWidget +from settings import ICONS_DIR class ZoomableImageView(QGraphicsView): @@ -178,16 +179,15 @@ class ViewWithOverlay(QWidget): return btn def _create_top_right_buttons(self): - self.cw_btn = self._create_tool_button( - icon_path="ui/icons/rotate-cw-svgrepo-com.svg", - callback=self.rotateCW, - ) - - self.ccw_btn = self._create_tool_button( - icon_path="ui/icons/rotate-ccw-svgrepo-com.svg", - callback=self.rotateCCW, - ) - + self.cw_btn = self._create_tool_button( + icon_path=str(ICONS_DIR / "rotate-cw-svgrepo-com.svg"), + callback=self.rotateCW, + ) + + self.ccw_btn = self._create_tool_button( + icon_path=str(ICONS_DIR / "rotate-ccw-svgrepo-com.svg"), + callback=self.rotateCCW, + ) self.flip_btn = self._create_tool_button( icon_path=None, callback=self.swapViews, @@ -198,17 +198,16 @@ class ViewWithOverlay(QWidget): callback=self.toggleOrientation, ) - def _create_top_left_buttons(self): - self.camera_btn = self._create_tool_button( - icon_path="ui/icons/settings-svgrepo-com.svg", - callback=self.cameraConnection - ) - - self.settings_btn = self._create_tool_button( - icon_path="ui/icons/error-16-svgrepo-com.svg", - callback=self.cameraSettings - ) - + def _create_top_left_buttons(self): + self.camera_btn = self._create_tool_button( + icon_path=str(ICONS_DIR / "settings-svgrepo-com.svg"), + callback=self.cameraConnection + ) + + self.settings_btn = self._create_tool_button( + icon_path=str(ICONS_DIR / "error-16-svgrepo-com.svg"), + callback=self.cameraSettings + ) def set_image(self, pixmap: QPixmap): self.viewer.set_image(pixmap) @@ -230,14 +229,13 @@ class ViewWithOverlay(QWidget): right_corner += self.orient_btn.width() + 10 self.orient_btn.move(self.width() - right_corner, 10) - def toggle_orientation(self, orientation): - if orientation == Qt.Orientation.Vertical: - self.flip_btn.setIcon(QIcon("ui/icons/flip-vertical-svgrepo-com.svg")) - self.orient_btn.setIcon(QIcon("ui/icons/horizontal-stacks-svgrepo-com.svg")) - else: - self.flip_btn.setIcon(QIcon("ui/icons/flip-horizontal-svgrepo-com.svg")) - self.orient_btn.setIcon(QIcon("ui/icons/vertical-stacks-svgrepo-com.svg")) - + def toggle_orientation(self, orientation): + if orientation == Qt.Orientation.Vertical: + self.flip_btn.setIcon(QIcon(str(ICONS_DIR / "flip-vertical-svgrepo-com.svg"))) + self.orient_btn.setIcon(QIcon(str(ICONS_DIR / "horizontal-stacks-svgrepo-com.svg"))) + else: + self.flip_btn.setIcon(QIcon(str(ICONS_DIR / "flip-horizontal-svgrepo-com.svg"))) + self.orient_btn.setIcon(QIcon(str(ICONS_DIR / "vertical-stacks-svgrepo-com.svg"))) def enterEvent(self, event: QEnterEvent) -> None: if self.live: self.camera_btn.show()