Skip to content

Commit 040ace8

Browse files
committed
Update AutoNode and TabSearch
1 parent 24cd46a commit 040ace8

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

NodeGraphQt/widgets/tab_search.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,15 @@ def __init__(self, node_dict=None):
153153
self.line_edit.returnPressed.connect(self._on_search_submitted)
154154
self.line_edit.textChanged.connect(self._on_text_changed)
155155
self.rebuild = False
156+
self._block_submit = False
156157

157158
def __repr__(self):
158159
return '<{} at {}>'.format(self.__class__.__name__, hex(id(self)))
159160

161+
def keyPressEvent(self, event):
162+
super(TabSearchMenuWidget, self).keyPressEvent(event)
163+
self.line_edit.keyPressEvent(event)
164+
160165
def _on_text_changed(self, text):
161166
self._clear_actions()
162167

@@ -187,26 +192,29 @@ def _close(self):
187192
self._set_menu_visible(False)
188193
self.setVisible(False)
189194
self.menuAction().setVisible(False)
195+
self._block_submit = True
190196

191197
def _show(self):
192198
self.line_edit.setText("")
193199
self.line_edit.setFocus()
194200
self._set_menu_visible(True)
201+
self._block_submit = False
195202
self.exec_(QtGui.QCursor.pos())
196203

197204
def _on_search_submitted(self):
198-
action = self.sender()
199-
if type(action) is not QtWidgets.QAction:
200-
if len(self._searched_actions) > 0:
201-
action = self._searched_actions[0]
202-
else:
203-
self._close()
204-
return
205+
if not self._block_submit:
206+
action = self.sender()
207+
if type(action) is not QtWidgets.QAction:
208+
if len(self._searched_actions) > 0:
209+
action = self._searched_actions[0]
210+
else:
211+
self._close()
212+
return
205213

206-
text = action.text()
207-
node_type = self._node_dict.get(text)
208-
if node_type:
209-
self.search_submitted.emit(node_type)
214+
text = action.text()
215+
node_type = self._node_dict.get(text)
216+
if node_type:
217+
self.search_submitted.emit(node_type)
210218

211219
self._close()
212220

@@ -223,6 +231,7 @@ def build_menu_tree(self):
223231
if depth in menu_tree.keys():
224232
if menu_name not in menu_tree[depth].keys():
225233
new_menu = QtWidgets.QMenu(menu_name)
234+
new_menu.keyPressEvent = self.keyPressEvent
226235
new_menu.setStyleSheet(STYLE_QMENU)
227236
menu_tree[depth][menu_path] = new_menu
228237
else:

example_auto_nodes/node_base/auto_node.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def autoCook(self, mode):
8181
@property
8282
def cookTime(self):
8383
"""
84-
Get the last cooked time of the node.
84+
Returns the last cooked time of the node.
8585
"""
8686

8787
return self._cookTime
@@ -98,6 +98,14 @@ def cookTime(self, cook_time):
9898
self._cookTime = cook_time
9999
self._update_tool_tip()
100100

101+
@property
102+
def has_error(self):
103+
"""
104+
Returns whether the node has errors.
105+
"""
106+
107+
return self._error
108+
101109
def update_stream(self, forceCook=False):
102110
"""
103111
Update all down stream nodes.
@@ -352,17 +360,11 @@ def _setup_tool_tip(self):
352360

353361
def error(self, message=None):
354362
"""
355-
Update the node tooltip.
363+
Set error message to node tooltip.
356364
357365
Args:
358-
message(str): the describe of the error or None.
359-
360-
Returns:
361-
if message is None, returns whether the node has error.
366+
message(str): the describe of the error.
362367
"""
363-
364-
if message is None:
365-
return self._error
366368
self._show_error(message)
367369

368370
# def __del__(self):

example_auto_nodes/node_base/subgraph_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def run(self):
168168
node.when_disabled()
169169
else:
170170
node.cook()
171-
if node.error():
171+
if node.has_error:
172172
self.error("/"+node.view.toolTip())
173173
break
174174

example_auto_nodes/node_base/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def _update_nodes(nodes):
77
node.when_disabled()
88
else:
99
node.cook()
10-
if node.error():
10+
if node.has_error:
1111
break
1212

1313

0 commit comments

Comments
 (0)