-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgui.py
More file actions
253 lines (171 loc) · 5.5 KB
/
gui.py
File metadata and controls
253 lines (171 loc) · 5.5 KB
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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
from ryven.gui_env import *
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QLineEdit
#
# General Base Classes
#
class PythonOCCNodeGuiBase(NodeGUI):
input_widget_classes = {
'DataSmall': inp_widgets.Builder.evaled_line_edit(size='s', resizing=True),
}
@staticmethod
def builder():
return GuiBuilder
class GuiBuilder:
@staticmethod
def attach_input_widgets(input_widgets):
"""
A decorator which automatically attaches input widgets specified
in the input_widgets list to the gui of the node.
"""
# make sure all input widget names provided are valid
assert all([
wn in PythonOCCNodeGuiBase.input_widget_classes
for wn in input_widgets if wn is not None
])
def decorator(cls):
inp_widgets = {
i: {'name': widget_name, 'pos': 'besides'}
for i, widget_name in enumerate(input_widgets)
if widget_name is not None
}
if not issubclass(cls.GUI, PythonOCCNodeGuiBase):
# override GUI class
class AutoInputWidgets_NodeGui(PythonOCCNodeGuiBase):
init_input_widgets = inp_widgets
cls.GUI = AutoInputWidgets_NodeGui
else:
# add input widgets to existing GUI class
cls.GUI.init_input_widgets = inp_widgets
return cls
return decorator
#
# Specific Node GUIs
#
class PyOCCBase_DynamicInputsGui(PythonOCCNodeGuiBase):
def __init__(self, params):
super().__init__(params)
self.num_inputs = 0
self.actions['add input'] = {'method': self.add_operand_input}
self.actions['remove input'] = {}
def initialized(self):
# if the node was loaded from a state, catch up with
# the number of inputs
self.num_inputs = len(self.node.inputs)
# the actions are restrored automatically
self.actions['remove input'] = {
i: {
'method': self.remove_operand_input,
'data': i,
} for i in range(self.num_inputs)
}
def add_operand_input(self):
self.node.add_operand_input()
# update actions
new_index = self.num_inputs
self.actions['remove input'][new_index] = {
'method': self.remove_operand_input,
'data': new_index,
}
self.num_inputs += 1
def remove_operand_input(self, index):
self.node.remove_operand_input(index)
del self.actions['remove input'][self.num_inputs-1]
self.num_inputs -= 1
class GpNodeGui(PythonOCCNodeGuiBase):
color = '#5e0a91'
class BrepBuilderAPINodeGui(PythonOCCNodeGuiBase):
color = '#DAA520'
class BrepOffsetAPINodeGui(PythonOCCNodeGuiBase):
color = '#aabb44'
class BrepPrimAPINodeBase(PythonOCCNodeGuiBase):
color = '#aabb44'
class BrepAlgoAPINodeGui(PythonOCCNodeGuiBase):
color = '#ab0c36'
class BrepFilletAPINodeGui(PythonOCCNodeGuiBase):
color = '#e0149c'
class GeomNodeGui(PythonOCCNodeGuiBase):
color = '#c91604'
class GeomAPINodeGui(PythonOCCNodeGuiBase):
color = '#ff4633'
class TopExplorerGui(PythonOCCNodeGuiBase):
color = '#FF00FF'
class BoundingBoxGui(PythonOCCNodeGuiBase):
color = '#FF00FF'
class DisplayNodeGui(PythonOCCNodeGuiBase):
color = '#3355dd'
class ListGui(PyOCCBase_DynamicInputsGui):
color = '#000000'
class ListLengthGui(PythonOCCNodeGuiBase):
color = '#000000'
class FlattenListGui(PythonOCCNodeGuiBase):
color = '#000000'
class ListItemGui(PythonOCCNodeGuiBase):
color = '#000000'
class RepeatDataGui(PythonOCCNodeGuiBase):
color = '#000000'
class SerieGui(PythonOCCNodeGuiBase):
color = '#000000'
class ShiftListGui(PythonOCCNodeGuiBase):
color = '#000000'
class DataExchangeNodeGui(PythonOCCNodeGuiBase):
color = '#6b6767'
#
# inport file node
#
class ImportFileNode_MainWidget(NodeMainWidget, QLineEdit):
value_changed = Signal(object)
def __init__(self, params):
NodeMainWidget.__init__(self, params)
QLineEdit.__init__(self)
# self.setFixedWidth(80)
# self.setMinimumWidth(80)
self.resize(120, 31)
self.editingFinished.connect(self.editing_finished)
def editing_finished(self):
# self.node.update()
self.value_changed.emit(self.get_val())
def get_val(self):
val = None
try:
val = eval(self.text())
except Exception as e:
val = self.text()
return val
def get_state(self):
data = {'text': self.text()}
return data
def set_state(self, data):
self.setText(data['text'])
class ImportFileNode_Gui(NodeGUI):
main_widget_class = ImportFileNode_MainWidget
main_widget_pos = 'between ports'
# ---------------------------------------------------------------------------------------------------------------------------------
#
# Export
#
export_guis([
PythonOCCNodeGuiBase,
PyOCCBase_DynamicInputsGui,
GuiBuilder,
GpNodeGui,
BrepBuilderAPINodeGui,
BrepOffsetAPINodeGui,
BrepPrimAPINodeBase,
BrepAlgoAPINodeGui,
BrepFilletAPINodeGui,
GeomNodeGui,
GeomAPINodeGui,
TopExplorerGui,
BoundingBoxGui,
DisplayNodeGui,
ListGui,
ListLengthGui,
FlattenListGui,
ListItemGui,
RepeatDataGui,
SerieGui,
ShiftListGui,
DataExchangeNodeGui,
ImportFileNode_Gui,
])