-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_dialog.py
70 lines (55 loc) · 3.35 KB
/
settings_dialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from typing import Any
from PyQt6.QtCore import QSettings, QVariant, Qt
from PyQt6.QtGui import QAction, QIcon
from PyQt6.QtWidgets import QDialog, QLineEdit, QFileDialog, QToolButton, QSpinBox, QCheckBox
from PyQt6.uic import loadUi
from helpers import get_ui_path
class SettingsDialog(QDialog):
def __init__(self, q_settings: QSettings, parent=None):
super(SettingsDialog, self).__init__(parent)
self.__q_settings = q_settings
self.settings: dict[str, Any] = dict()
loadUi(get_ui_path('ui/settings_dialog.ui'), self)
self.working_directory_input: QLineEdit = self.findChild(QLineEdit, "workingDirectoryInput")
self.working_directory_input.setText(q_settings.value("workingDirectory"))
self.working_directory_input.textChanged.connect(
lambda text: self.set("workingDirectory", text)
)
open_action = QAction("Arbeitsverzeichnis wählen", self)
open_action.setIcon(QIcon(get_ui_path("ui/folder-open.svg")))
open_action.triggered.connect(self.choose_working_directory)
self.working_directory_input.addAction(open_action, QLineEdit.ActionPosition.TrailingPosition)
tool_button: QToolButton
for tool_button in self.working_directory_input.findChildren(QToolButton):
tool_button.setCursor(Qt.CursorShape.PointingHandCursor)
self.max_pixmap_cache_input: QSpinBox = self.findChild(QSpinBox, "maxPixmapCacheInput")
self.max_pixmap_cache_input.setValue(int(q_settings.value("maxPixmapCache")))
self.max_pixmap_cache_input.textChanged.connect(
lambda text: self.set("maxPixmapCache", int(text))
)
self.max_burst_number_input: QSpinBox = self.findChild(QSpinBox, "maxBurstNumberInput")
self.max_burst_number_input.setValue(int(q_settings.value("maxBurstNumber")))
self.max_burst_number_input.textChanged.connect(
lambda text: self.set("maxBurstNumber", int(text))
)
self.enable_bluetooth_checkbox: QCheckBox = self.findChild(QCheckBox, "enableBluetoothCheckbox")
self.enable_bluetooth_checkbox.setChecked(q_settings.value("enableBluetooth", type=bool))
self.enable_bluetooth_checkbox.stateChanged.connect(
lambda: self.set("enableBluetooth", self.enable_bluetooth_checkbox.isChecked())
)
self.enable_second_screen_mirror_checkbox: QCheckBox = self.findChild(QCheckBox, "enableSecondScreenMirrorCheckbox")
self.enable_second_screen_mirror_checkbox.setChecked(q_settings.value("enableSecondScreenMirror", type=bool))
self.enable_second_screen_mirror_checkbox.stateChanged.connect(
lambda: self.set("enableSecondScreenMirror", self.enable_second_screen_mirror_checkbox.isChecked())
)
def set(self, name: str, value: QVariant):
self.settings[name] = value
def choose_working_directory(self):
file_dialog = QFileDialog(self,
"Arbeitsverzeichnis wählen",
self.working_directory_input.text())
file_dialog.setFileMode(QFileDialog.FileMode.Directory)
if file_dialog.exec():
print(file_dialog.selectedFiles())
if file_dialog.selectedFiles():
self.working_directory_input.setText(file_dialog.selectedFiles()[0])