Skip to content

Commit 4aa01c4

Browse files
committed
helper method to get items by type (Node, Connection, etc)
1 parent 624715c commit 4aa01c4

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

node_editor/gui/view.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import Any
4+
from typing import List
35
from typing import Optional
46

57
from PySide6 import QtCore
@@ -158,25 +160,12 @@ def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
158160
This method is called when a context menu event is triggered in the view. It finds the item at the
159161
event position and shows a context menu if the item is a Node.
160162
"""
161-
# cursor = QtGui.QCursor()
162-
# origin = self.mapFromGlobal(cursor.pos())
163-
# pos = self.mapFromGlobal(cursor.pos())
164163
item = self.itemAt(event.pos())
165164

166165
if item:
167166
if isinstance(item, Node):
168167
print("Found Node", item)
169168

170-
# menu = QtWidgets.QMenu(self)
171-
172-
# hello_action = QtWidgets.QAction("Hello", self)
173-
174-
# menu.addAction(hello_action)
175-
# action = menu.exec_(self.mapToGlobal(pos))
176-
177-
# if action == hello_action:
178-
# print("Hello")
179-
180169
def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None:
181170
"""
182171
This method is called when a drag and drop event enters the view. It checks if the mime data format
@@ -233,3 +222,11 @@ def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
233222
self._pan_start_y = event.y()
234223

235224
super().mouseMoveEvent(event)
225+
226+
def get_items_by_type(self, item_class: type) -> List[Any]:
227+
items = []
228+
for item in self.scene().items():
229+
print(f"current item: {item}, class: {item_class}")
230+
if isinstance(item, item_class):
231+
items.append(item)
232+
return items

0 commit comments

Comments
 (0)