Newer
Older
from qtpy.QtWidgets import QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout,\
Angus Lothian
committed
QLabel, QCheckBox, QGridLayout
from qtpy.QtCore import Qt
from qtpy.QtGui import QDoubleValidator
Angus Lothian
committed
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
class PropertiesWindow(QDialog):
def __init__(self, operation, main_window):
super(PropertiesWindow, self).__init__()
self.operation = operation
self._window = main_window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("Properties")
self.name_layout = QHBoxLayout()
self.name_layout.setSpacing(50)
self.name_label = QLabel("Name:")
self.edit_name = QLineEdit(self.operation.operation_path_name)
self.name_layout.addWidget(self.name_label)
self.name_layout.addWidget(self.edit_name)
self.latency_fields = dict()
self.vertical_layout = QVBoxLayout()
self.vertical_layout.addLayout(self.name_layout)
if hasattr(self.operation.operation, "value") or hasattr(self.operation.operation, "initial_value"):
self.constant_layout = QHBoxLayout()
self.constant_layout.setSpacing(50)
self.constant_value = QLabel("Value:")
if hasattr(self.operation.operation, "value"):
self.edit_constant = QLineEdit(str(self.operation.operation.value))
else:
self.edit_constant = QLineEdit(str(self.operation.operation.initial_value))
self.only_accept_float = QDoubleValidator()
self.edit_constant.setValidator(self.only_accept_float)
self.constant_layout.addWidget(self.constant_value)
self.constant_layout.addWidget(self.edit_constant)
self.vertical_layout.addLayout(self.constant_layout)
self.show_name_layout = QHBoxLayout()
self.check_show_name = QCheckBox("Show name?")
if self.operation.is_show_name:
self.check_show_name.setChecked(1)
else:
self.check_show_name.setChecked(0)
self.check_show_name.setLayoutDirection(Qt.RightToLeft)
self.check_show_name.setStyleSheet("spacing: 170px")
self.show_name_layout.addWidget(self.check_show_name)
self.vertical_layout.addLayout(self.show_name_layout)
if self.operation.operation.input_count > 0:
self.latency_layout = QHBoxLayout()
self.latency_label = QLabel("Set latency for input ports (-1 for None):")
Angus Lothian
committed
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
self.latency_layout.addWidget(self.latency_label)
self.vertical_layout.addLayout(self.latency_layout)
input_grid = QGridLayout()
x, y = 0, 0
for i in range(self.operation.operation.input_count):
input_layout = QHBoxLayout()
input_layout.addStretch()
if i % 2 == 0 and i > 0:
x += 1
y = 0
input_label = QLabel("in" + str(i))
input_layout.addWidget(input_label)
input_value = QLineEdit()
try:
input_value.setPlaceholderText(str(self.operation.operation.latency))
except ValueError:
input_value.setPlaceholderText("-1")
int_valid = QDoubleValidator()
int_valid.setBottom(-1)
input_value.setValidator(int_valid)
input_value.setFixedWidth(50)
self.latency_fields["in" + str(i)] = input_value
input_layout.addWidget(input_value)
input_layout.addStretch()
input_layout.setSpacing(10)
input_grid.addLayout(input_layout, x, y)
y += 1
self.vertical_layout.addLayout(input_grid)
if self.operation.operation.output_count > 0:
self.latency_layout = QHBoxLayout()
self.latency_label = QLabel("Set latency for output ports (-1 for None):")
Angus Lothian
committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
self.latency_layout.addWidget(self.latency_label)
self.vertical_layout.addLayout(self.latency_layout)
input_grid = QGridLayout()
x, y = 0, 0
for i in range(self.operation.operation.output_count):
input_layout = QHBoxLayout()
input_layout.addStretch()
if i % 2 == 0 and i > 0:
x += 1
y = 0
input_label = QLabel("out" + str(i))
input_layout.addWidget(input_label)
input_value = QLineEdit()
try:
input_value.setPlaceholderText(str(self.operation.operation.latency))
except ValueError:
input_value.setPlaceholderText("-1")
int_valid = QDoubleValidator()
int_valid.setBottom(-1)
input_value.setValidator(int_valid)
input_value.setFixedWidth(50)
self.latency_fields["out" + str(i)] = input_value
input_layout.addWidget(input_value)
input_layout.addStretch()
input_layout.setSpacing(10)
input_grid.addLayout(input_layout, x, y)
y += 1
self.vertical_layout.addLayout(input_grid)
self.ok = QPushButton("OK")
self.ok.clicked.connect(self.save_properties)
self.vertical_layout.addWidget(self.ok)
self.setLayout(self.vertical_layout)
def save_properties(self):
self._window.logger.info(f"Saving properties of operation: {self.operation.name}.")
self.operation.name = self.edit_name.text()
self.operation.operation.name = self.edit_name.text()
self.operation.label.setPlainText(self.operation.name)
if hasattr(self.operation.operation, "value"):
self.operation.operation.value = float(self.edit_constant.text().replace(",", "."))
elif hasattr(self.operation.operation, "initial_value"):
self.operation.operation.initial_value = float(self.edit_constant.text().replace(",", "."))
if self.check_show_name.isChecked():
self.operation.label.setOpacity(1)
self.operation.is_show_name = True
else:
self.operation.label.setOpacity(0)
self.operation.is_show_name = False
self.operation.operation.set_latency_offsets({port: float(self.latency_fields[port].text().replace(",", ".")) if self.latency_fields[port].text() and float(self.latency_fields[port].text().replace(",", ".")) > 0 else None for port in self.latency_fields})
self.reject()