-
Notifications
You must be signed in to change notification settings - Fork 247
/
hotkey_functions.py
281 lines (212 loc) · 5.89 KB
/
hotkey_functions.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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/python
# ------------------------------------------------------------------------------
# menu command functions
# ------------------------------------------------------------------------------
def zoom_in(graph):
"""
Set the node graph to zoom in by 0.1
"""
zoom = graph.get_zoom() + 0.1
graph.set_zoom(zoom)
def zoom_out(graph):
"""
Set the node graph to zoom in by 0.1
"""
zoom = graph.get_zoom() - 0.2
graph.set_zoom(zoom)
def reset_zoom(graph):
"""
Reset zoom level.
"""
graph.reset_zoom()
def layout_h_mode(graph):
"""
Set node graph layout direction to horizontal.
"""
graph.set_layout_direction(0)
def layout_v_mode(graph):
"""
Set node graph layout direction to vertical.
"""
graph.set_layout_direction(1)
def open_session(graph):
"""
Prompts a file open dialog to load a session.
"""
current = graph.current_session()
file_path = graph.load_dialog(current)
if file_path:
graph.load_session(file_path)
def import_session(graph):
"""
Prompts a file open dialog to load a session.
"""
current = graph.current_session()
file_path = graph.load_dialog(current)
if file_path:
graph.import_session(file_path)
def save_session(graph):
"""
Prompts a file save dialog to serialize a session if required.
"""
current = graph.current_session()
if current:
graph.save_session(current)
msg = 'Session layout saved:\n{}'.format(current)
viewer = graph.viewer()
viewer.message_dialog(msg, title='Session Saved')
else:
save_session_as(graph)
def save_session_as(graph):
"""
Prompts a file save dialog to serialize a session.
"""
current = graph.current_session()
file_path = graph.save_dialog(current)
if file_path:
graph.save_session(file_path)
def clear_session(graph):
"""
Prompts a warning dialog to new a node graph session.
"""
if graph.question_dialog('Clear Current Session?', 'Clear Session'):
graph.clear_session()
def clear_undo(graph):
"""
Prompts a warning dialog to clear undo.
"""
viewer = graph.viewer()
msg = 'Clear all undo history, Are you sure?'
if viewer.question_dialog('Clear Undo History', msg):
graph.clear_undo_stack()
def copy_nodes(graph):
"""
Copy nodes to the clipboard.
"""
graph.copy_nodes()
def cut_nodes(graph):
"""
Cut nodes to the clip board.
"""
graph.cut_nodes()
def paste_nodes(graph):
"""
Pastes nodes copied from the clipboard.
"""
graph.paste_nodes()
def delete_nodes(graph):
"""
Delete selected node.
"""
graph.delete_nodes(graph.selected_nodes())
def extract_nodes(graph):
"""
Extract selected nodes.
"""
graph.extract_nodes(graph.selected_nodes())
def clear_node_connections(graph):
"""
Clear port connection on selected nodes.
"""
graph.undo_stack().beginMacro('clear selected node connections')
for node in graph.selected_nodes():
for port in node.input_ports() + node.output_ports():
port.clear_connections()
graph.undo_stack().endMacro()
def select_all_nodes(graph):
"""
Select all nodes.
"""
graph.select_all()
def clear_node_selection(graph):
"""
Clear node selection.
"""
graph.clear_selection()
def invert_node_selection(graph):
"""
Invert node selection.
"""
graph.invert_selection()
def disable_nodes(graph):
"""
Toggle disable on selected nodes.
"""
graph.disable_nodes(graph.selected_nodes())
def duplicate_nodes(graph):
"""
Duplicated selected nodes.
"""
graph.duplicate_nodes(graph.selected_nodes())
def expand_group_node(graph):
"""
Expand selected group node.
"""
selected_nodes = graph.selected_nodes()
if not selected_nodes:
graph.message_dialog('Please select a "GroupNode" to expand.')
return
graph.expand_group_node(selected_nodes[0])
def fit_to_selection(graph):
"""
Sets the zoom level to fit selected nodes.
"""
graph.fit_to_selection()
def show_undo_view(graph):
"""
Show the undo list widget.
"""
graph.undo_view.show()
def curved_pipe(graph):
"""
Set node graph pipes layout as curved.
"""
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.CURVED.value)
def straight_pipe(graph):
"""
Set node graph pipes layout as straight.
"""
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.STRAIGHT.value)
def angle_pipe(graph):
"""
Set node graph pipes layout as angled.
"""
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.ANGLE.value)
def bg_grid_none(graph):
"""
Turn off the background patterns.
"""
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_NONE.value)
def bg_grid_dots(graph):
"""
Set background node graph background with grid dots.
"""
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_DOTS.value)
def bg_grid_lines(graph):
"""
Set background node graph background with grid lines.
"""
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_LINES.value)
def layout_graph_down(graph):
"""
Auto layout the nodes down stream.
"""
nodes = graph.selected_nodes() or graph.all_nodes()
graph.auto_layout_nodes(nodes=nodes, down_stream=True)
def layout_graph_up(graph):
"""
Auto layout the nodes up stream.
"""
nodes = graph.selected_nodes() or graph.all_nodes()
graph.auto_layout_nodes(nodes=nodes, down_stream=False)
def toggle_node_search(graph):
"""
show/hide the node search widget.
"""
graph.toggle_node_search()