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.
This commit is contained in:
2025-10-14 08:33:08 +02:00
parent bbdb7d3459
commit d62b367b47
3 changed files with 44 additions and 31 deletions

View File

@@ -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()