-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings_window.py
102 lines (80 loc) · 4.18 KB
/
settings_window.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Settings dialog for RenderRob."""
# import appdirs
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QFileDialog
from proto import state_pb2
from utils_rr import ui_utils
class SettingsWindow():
"""Settings dialog for RenderRob.
This class represents a settings dialog for RenderRob. It allows the user to modify various
settings such as the path to Blender, output path, Blender files path, and more. The class also
provides methods to save the state from the settings dialog into the global state.
"""
def __init__(self, state: state_pb2.render_rob_state) -> None: # pylint: disable=no-member
"""Open the settings dialog."""
self.state = state.settings
self.window = ui_utils.load_ui_from_file("ui/settings.ui")
self.window.setWindowTitle("RenderRob Settings")
self.window.setWindowIcon(QIcon("icons/icon.ico"))
# Load state into the settings dialog.
self.make_settings_window_connections(self.window)
self.window.lineEdit_3.setText(self.state.blender_path)
self.window.lineEdit_2.setText(self.state.output_path)
self.window.lineEdit.setText(self.state.blender_files_path)
self.window.checkBox_2.setCheckState(
Qt.Checked if self.state.preview.samples_use else Qt.Unchecked)
self.window.checkBox_3.setCheckState(
Qt.Checked if self.state.preview.frame_step_use else Qt.Unchecked)
self.window.checkBox.setCheckState(
Qt.Checked if self.state.preview.resolution_use else Qt.Unchecked)
self.window.spinBox_3.setValue(int(self.state.preview.samples))
self.window.spinBox_2.setValue(int(self.state.preview.frame_step))
self.window.spinBox.setValue(int(self.state.preview.resolution))
self.window.spinBox_4.setValue(int(self.state.fps))
self.window.lineEdit_4.setText(";".join(self.state.addons))
self.window.exec()
def make_settings_window_connections(self, window: QUiLoader) -> None:
"""Make connections for buttons in settings dialog.."""
window.buttonBox.accepted.connect(self.save_settings_state)
window.blender_button.clicked.connect(self.open_blender_path)
window.files_button.clicked.connect(self.open_blender_files_path)
window.output_button.clicked.connect(self.open_output_path)
def open_blender_path(self) -> None:
"""Open a file dialog to select the path to Blender."""
path = QFileDialog.getOpenFileName(
self.window, caption="Select Blender Path", filter="Blender (*.exe)")
if path:
self.window.lineEdit_3.setText(path[0])
def open_blender_files_path(self) -> None:
"""Open a file dialog to select the path to Blender files."""
path = QFileDialog.getExistingDirectory(self.window, caption="Select Blender Files Path")
if path:
self.window.lineEdit.setText(path)
def open_output_path(self) -> None:
"""Open a file dialog to select the output path."""
path = QFileDialog.getExistingDirectory(self.window, caption="Select Output Path")
if path:
self.window.lineEdit_2.setText(path)
def save_settings_state(self) -> None:
"""Save the state from the settings dialog into the global state."""
self.state.blender_path = self.window.lineEdit_3.text()
self.state.output_path = self.window.lineEdit_2.text()
self.state.blender_files_path = self.window.lineEdit.text()
self.state.preview.samples_use = self.window.checkBox_2.isChecked()
self.state.preview.frame_step_use = self.window.checkBox_3.isChecked()
self.state.preview.resolution_use = self.window.checkBox.isChecked()
# Check if the values are empty, if so, set them to 0.
samples = self.window.spinBox_3.cleanText()
self.state.preview.samples = int(samples) if samples else 0
frame_step = self.window.spinBox_2.cleanText()
self.state.preview.frame_step = int(frame_step) if frame_step else 0
resolution = self.window.spinBox.cleanText()
self.state.preview.resolution = int(resolution) if resolution else 0
fps = self.window.spinBox_4.cleanText()
self.state.fps = int(fps) if resolution else 0
del self.state.addons[:]
addons_str = self.window.lineEdit_4.text()
for addon in addons_str.split(";"):
self.state.addons.append(addon)