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.
211 lines
7.6 KiB
Python
211 lines
7.6 KiB
Python
from PySide6.QtWidgets import QDialog, QHBoxLayout ,QVBoxLayout, QPushButton, QGroupBox, QLabel, QRadioButton, QWidget, QToolButton, QSlider, QButtonGroup
|
|
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"]
|
|
|
|
class LabeledSpinSelector(QWidget):
|
|
indexChanged = Signal(int)
|
|
|
|
def __init__(self, title: str, values: list[str], show_slider: bool = False, parent=None):
|
|
super().__init__(parent)
|
|
self.values = values
|
|
self.current_index = 0
|
|
self.show_slider = show_slider
|
|
self._init_ui(title)
|
|
|
|
def _init_ui(self, title: str, button_size: int = 24, icon_size: int = 16):
|
|
self.title_label = QLabel(title)
|
|
|
|
decrement_button = QToolButton()
|
|
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(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)
|
|
|
|
self.value_label = QLabel(self.values[self.current_index] if self.values else "N/A")
|
|
self.value_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
self.value_label.setStyleSheet("background-color: rgb(48, 48, 48);")
|
|
self.value_label.setFixedHeight(button_size - 2)
|
|
|
|
spin_layout = QHBoxLayout()
|
|
spin_layout.addWidget(decrement_button)
|
|
spin_layout.addWidget(self.value_label)
|
|
spin_layout.addWidget(increment_button)
|
|
|
|
top_layout = QHBoxLayout()
|
|
top_layout.addWidget(self.title_label)
|
|
top_layout.addLayout(spin_layout)
|
|
|
|
self.slider = QSlider(Qt.Orientation.Horizontal)
|
|
self.slider.setRange(0, max(0, len(self.values) - 1))
|
|
self.slider.setTickPosition(QSlider.TickPosition.TicksBelow)
|
|
self.slider.valueChanged.connect(self._slider_changed)
|
|
|
|
main_layout = QVBoxLayout()
|
|
main_layout.addLayout(top_layout)
|
|
if self.show_slider:
|
|
main_layout.addWidget(self.slider)
|
|
|
|
main_layout.setContentsMargins(0, 0, 0, 0)
|
|
self.setLayout(main_layout)
|
|
|
|
def _increment(self):
|
|
if not self.values:
|
|
return
|
|
new_index = min(self.current_index + 1, len(self.values) - 1)
|
|
self.set_index(new_index)
|
|
|
|
def _decrement(self):
|
|
if not self.values:
|
|
return
|
|
new_index = max(self.current_index - 1, 0)
|
|
self.set_index(new_index)
|
|
|
|
def _slider_changed(self, index):
|
|
if not self.values:
|
|
return
|
|
self.set_index(index)
|
|
|
|
def set_label(self, label: str):
|
|
self.title_label.setText(label)
|
|
|
|
def set_index(self, index: int):
|
|
if not self.values or not (0 <= index < len(self.values)):
|
|
return
|
|
if self.current_index != index:
|
|
self.current_index = index
|
|
self.value_label.setText(self.values[index])
|
|
if self.show_slider:
|
|
self.slider.setValue(index)
|
|
self.indexChanged.emit(index)
|
|
else:
|
|
# Always update UI even if index is the same (for initial set)
|
|
self.value_label.setText(self.values[index])
|
|
if self.show_slider:
|
|
self.slider.setValue(index)
|
|
|
|
class ViewSettingsDialog(QDialog):
|
|
detectDevice = Signal(str)
|
|
connectionChanged = Signal(str)
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Ustawienia widoku")
|
|
self.setFixedSize(640, 480)
|
|
|
|
self.setWindowFlags(self.windowFlags() | Qt.WindowType.WindowStaysOnTopHint)
|
|
|
|
# self.setup_ui()
|
|
camera_frame = self._create_devices_frame("camera")
|
|
hdmi_frame = self._create_devices_frame("hdmi")
|
|
conn_frame = self._create_connection_frame()
|
|
camera_settings = self._create_settings_frame()
|
|
hdmi_settings = self._create_settings_frame()
|
|
dialog_buttons = self._create_dialog_buttons()
|
|
|
|
hdmi_settings.setEnabled(False)
|
|
|
|
settings_layout = QHBoxLayout()
|
|
settings_layout.addWidget(camera_settings, 1)
|
|
settings_layout.addWidget(hdmi_settings, 1)
|
|
# main layout
|
|
main_layout = QVBoxLayout(self)
|
|
main_layout.addWidget(camera_frame)
|
|
main_layout.addWidget(hdmi_frame)
|
|
main_layout.addWidget(conn_frame)
|
|
main_layout.addLayout(settings_layout)
|
|
main_layout.addLayout(dialog_buttons)
|
|
|
|
main_layout.setStretch(3, 1)
|
|
|
|
self.last_choice = None
|
|
|
|
|
|
def _create_dialog_buttons(self):
|
|
ok_btn = QPushButton("OK")
|
|
ok_btn.clicked.connect(self.accept)
|
|
|
|
cancel_btn = QPushButton("Anuluj")
|
|
cancel_btn.setDefault(True)
|
|
cancel_btn.clicked.connect(self.reject)
|
|
|
|
layout = QHBoxLayout()
|
|
layout.addStretch()
|
|
layout.addWidget(ok_btn)
|
|
layout.addWidget(cancel_btn)
|
|
|
|
return layout
|
|
|
|
def _create_devices_frame(self, name):
|
|
frame = QGroupBox()
|
|
frame.setTitle("Wykryte aparaty")
|
|
frame.setContentsMargins(6, 20, 6, 10)
|
|
|
|
device_label = QLabel("Nie wykryto podłączonych urządzeń.")
|
|
detect_button = QPushButton("Wykryj...")
|
|
detect_button.clicked.connect(lambda: self.detectDevice.emit(name))
|
|
|
|
layout = QHBoxLayout()
|
|
layout.addWidget(device_label)
|
|
layout.addStretch()
|
|
layout.addWidget(detect_button)
|
|
|
|
frame.setLayout(layout)
|
|
|
|
return frame
|
|
|
|
def _create_connection_frame(self):
|
|
frame = QGroupBox()
|
|
frame.setTitle("Wybór połączenia")
|
|
frame.setContentsMargins(6, 20, 6, 10)
|
|
|
|
radio_usb = QRadioButton("USB")
|
|
radio_hybrid = QRadioButton("USB + HDMI")
|
|
radio_hdmi = QRadioButton("HDMI")
|
|
|
|
radio_hdmi.setEnabled(False)
|
|
|
|
radio_usb.clicked.connect(lambda: self.radio_toggle("usb"))
|
|
radio_hybrid.clicked.connect(lambda: self.radio_toggle("hybrid"))
|
|
radio_hdmi.clicked.connect(lambda: self.radio_toggle("hdmi"))
|
|
|
|
radio_layout = QHBoxLayout()
|
|
radio_layout.addStretch()
|
|
radio_layout.addWidget(radio_usb)
|
|
radio_layout.addStretch()
|
|
radio_layout.addWidget(radio_hybrid)
|
|
radio_layout.addStretch()
|
|
radio_layout.addWidget(radio_hdmi)
|
|
radio_layout.addStretch()
|
|
|
|
frame.setLayout(radio_layout)
|
|
|
|
return frame
|
|
|
|
# def _create_settings_frame(self, settings: dict[str, list[str]]):
|
|
def _create_settings_frame(self):
|
|
frame = QGroupBox()
|
|
frame.setTitle("Ustawienia aparatu")
|
|
|
|
layout = QVBoxLayout()
|
|
# for key, value in settings.items():
|
|
# layout.addWidget(LabeledSpinSelector(key, value))
|
|
layout.addStretch()
|
|
|
|
frame.setLayout(layout)
|
|
return frame
|
|
|
|
def radio_toggle(self, value):
|
|
if self.last_choice != value:
|
|
self.last_choice = value
|
|
self.connectionChanged.emit(value) |