|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +from typing import Any |
| 4 | +from typing import List |
3 | 5 | from typing import Optional
|
4 | 6 |
|
5 | 7 | from PySide6 import QtCore
|
@@ -158,25 +160,12 @@ def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
|
158 | 160 | This method is called when a context menu event is triggered in the view. It finds the item at the
|
159 | 161 | event position and shows a context menu if the item is a Node.
|
160 | 162 | """
|
161 |
| - # cursor = QtGui.QCursor() |
162 |
| - # origin = self.mapFromGlobal(cursor.pos()) |
163 |
| - # pos = self.mapFromGlobal(cursor.pos()) |
164 | 163 | item = self.itemAt(event.pos())
|
165 | 164 |
|
166 | 165 | if item:
|
167 | 166 | if isinstance(item, Node):
|
168 | 167 | print("Found Node", item)
|
169 | 168 |
|
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 |
| - |
180 | 169 | def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None:
|
181 | 170 | """
|
182 | 171 | 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:
|
233 | 222 | self._pan_start_y = event.y()
|
234 | 223 |
|
235 | 224 | 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