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:
13
settings.py
Normal file
13
settings.py
Normal file
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user