Skip to content

Commit a2102f1

Browse files
committed
exposed cursor_pos() in NodeGraph. #357
1 parent 1387c1d commit a2102f1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

NodeGraphQt/base/graph.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ def undo_view(self):
525525
self._undo_view.setWindowTitle('Undo History')
526526
return self._undo_view
527527

528+
def cursor_pos(self):
529+
"""
530+
Returns the cursor last position in the node graph.
531+
532+
Returns:
533+
tuple(float, float): cursor x,y coordinates of the scene.
534+
"""
535+
cursor_pos = self.viewer().scene_cursor_pos()
536+
if not cursor_pos:
537+
return 0.0, 0.0
538+
return cursor_pos.x(), cursor_pos.y()
539+
528540
def toggle_node_search(self):
529541
"""
530542
toggle the node search widget visibility.

NodeGraphQt/widgets/viewer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,15 @@ def scene_center(self):
15731573
cent = self._scene_range.center()
15741574
return [cent.x(), cent.y()]
15751575

1576+
def scene_cursor_pos(self):
1577+
"""
1578+
Returns the cursor last position mapped to the scene.
1579+
1580+
Returns:
1581+
QtCore.QPoint: cursor position.
1582+
"""
1583+
return self.mapToScene(self._previous_pos)
1584+
15761585
def nodes_rect_center(self, nodes):
15771586
"""
15781587
Get the center x,y pos from the specified nodes.

0 commit comments

Comments
 (0)