Skip to content

Commit 0881677

Browse files
committed
minior updates.
1 parent e5f0c13 commit 0881677

File tree

4 files changed

+73
-15
lines changed

4 files changed

+73
-15
lines changed

NodeGraphQt/base/menu_setup.py renamed to NodeGraphQt/base/actions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,34 @@ def setup_context_menu(graph):
7979

8080

8181
def zoom_in(graph):
82+
"""
83+
Set the node graph to zoom in by 0.1
84+
85+
Args:
86+
graph (NodeGraphQt.NodeGraph): node graph.
87+
"""
8288
zoom = graph.get_zoom() + 0.1
8389
graph.set_zoom(zoom)
8490

8591

8692
def zoom_out(graph):
93+
"""
94+
Set the node graph to zoom in by 0.1
95+
96+
Args:
97+
graph (NodeGraphQt.NodeGraph): node graph.
98+
"""
8799
zoom = graph.get_zoom() - 0.2
88100
graph.set_zoom(zoom)
89101

90102

91103
def open_session(graph):
104+
"""
105+
Prompts a file open dialog to load a session.
106+
107+
Args:
108+
graph (NodeGraphQt.NodeGraph): node graph.
109+
"""
92110
current = graph.current_session()
93111
viewer = graph.viewer()
94112
file_path = viewer.load_dialog(current)
@@ -97,6 +115,12 @@ def open_session(graph):
97115

98116

99117
def save_session(graph):
118+
"""
119+
Prompts a file save dialog to serialize a session if required.
120+
121+
Args:
122+
graph (NodeGraphQt.NodeGraph): node graph.
123+
"""
100124
current = graph.current_session()
101125
if current:
102126
graph.save_session(current)
@@ -108,6 +132,12 @@ def save_session(graph):
108132

109133

110134
def save_session_as(graph):
135+
"""
136+
Prompts a file save dialog to serialize a session.
137+
138+
Args:
139+
graph (NodeGraphQt.NodeGraph): node graph.
140+
"""
111141
current = graph.current_session()
112142
viewer = graph.viewer()
113143
file_path = viewer.save_dialog(current)
@@ -116,12 +146,24 @@ def save_session_as(graph):
116146

117147

118148
def clear_session(graph):
149+
"""
150+
Prompts a warning dialog to clear the node graph session.
151+
152+
Args:
153+
graph (NodeGraphQt.NodeGraph): node graph.
154+
"""
119155
viewer = graph.viewer()
120156
if viewer.question_dialog('Clear Current Session?', 'Clear Session'):
121157
graph.clear_session()
122158

123159

124160
def clear_undo(graph):
161+
"""
162+
Prompts a warning dialog to clear undo.
163+
164+
Args:
165+
graph (NodeGraphQt.NodeGraph): node graph.
166+
"""
125167
viewer = graph.viewer()
126168
msg = 'Clear all undo history, Are you sure?'
127169
if viewer.question_dialog('Clear Undo History', msg):

NodeGraphQt/base/graph.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from PySide2 import QtCore
77
from PySide2.QtWidgets import QUndoStack, QAction, QApplication
88

9+
from NodeGraphQt.base.actions import setup_context_menu
910
from NodeGraphQt.base.commands import (NodeAddedCmd,
1011
NodeRemovedCmd,
1112
NodeMovedCmd,
1213
PortConnectedCmd)
1314
from NodeGraphQt.base.menu import ContextMenu
14-
from NodeGraphQt.base.menu_setup import setup_context_menu
1515
from NodeGraphQt.base.model import NodeGraphModel
1616
from NodeGraphQt.base.node import NodeObject
1717
from NodeGraphQt.base.port import Port
@@ -22,6 +22,9 @@
2222
class NodeGraph(QtCore.QObject):
2323
"""
2424
base node graph controller.
25+
26+
Args:
27+
default_actions(bool): true to initialize with default context menu actions.
2528
"""
2629

2730
#: signal for when a node has been created in the node graph.
@@ -33,14 +36,14 @@ class NodeGraph(QtCore.QObject):
3336
#: signal for when drop data has been added to the graph.
3437
data_dropped = QtCore.Signal(str, tuple)
3538

36-
def __init__(self, parent=None):
39+
def __init__(self, parent=None, default_actions=True):
3740
super(NodeGraph, self).__init__(parent)
3841
self.setObjectName('NodeGraphQt')
3942
self._model = NodeGraphModel()
4043
self._viewer = NodeViewer()
4144
self._vendor = NodeVendor()
4245
self._undo_stack = QUndoStack(self)
43-
self._init_actions()
46+
self._init_actions(default_actions)
4447
self._wire_signals()
4548

4649
def _wire_signals(self):
@@ -53,15 +56,16 @@ def _wire_signals(self):
5356
self._viewer.node_selected.connect(self._on_node_selected)
5457
self._viewer.data_dropped.connect(self._on_node_data_dropped)
5558

56-
def _init_actions(self):
59+
def _init_actions(self, default_actions=False):
5760
# setup tab search shortcut.
5861
tab = QAction('Search Nodes', self)
5962
tab.setShortcut('tab')
6063
tab.triggered.connect(self._toggle_tab_search)
6164
self._viewer.addAction(tab)
6265

6366
# setup default context menu.
64-
setup_context_menu(self)
67+
if default_actions:
68+
setup_context_menu(self)
6569

6670
def _toggle_tab_search(self):
6771
"""
@@ -197,6 +201,13 @@ def undo_stack(self):
197201
"""
198202
return self._undo_stack
199203

204+
def clear_undo_stack(self):
205+
"""
206+
Clears the undo stack.
207+
(convenience function to :meth:`NodeGraph.undo_stact().clear`)
208+
"""
209+
self._undo_stack.clear()
210+
200211
def begin_undo(self, name='undo'):
201212
"""
202213
Start of an undo block followed by a

docs/nodes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ NodeGraphQt.NodeObject
77

88
**Inherited by:** :ref:`NodeGraphQt.Node`, :ref:`NodeGraphQt.Backdrop`
99

10+
----
11+
12+
13+
Attributes
1014
.. autoattribute:: NodeGraphQt.NodeObject.__identifier__
1115
.. autoattribute:: NodeGraphQt.NodeObject.NODE_NAME
1216

13-
----
14-
1517

18+
Class
1619
.. autoclass:: NodeGraphQt.NodeObject
1720
:members:
1821
:exclude-members: model, NODE_NAME

docs/overview.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ NodeGraphQt is a node graph framework that can be implemented and repurposed int
66
.. image:: _images/overview.png
77
:width: 60%
88

9-
Navigation
10-
==========
9+
Nav Controls
10+
============
1111

1212
+---------------+----------------------------------------------+
1313
| action | controls |
@@ -17,24 +17,26 @@ Navigation
1717
| Pan | *Alt + LMB + Drag* or *MMB + Drag* |
1818
+---------------+----------------------------------------------+
1919

20-
Node Search
21-
===========
20+
Tab Search
21+
==========
2222

2323
.. image:: _images/node_search.png
2424
:width: 269px
2525

26-
Node can be created with the tab node search popup menu similar to Nuke.
26+
Node can be created with the tab node search widget.
2727

2828
+-------------+--------+
2929
| action | hotkey |
3030
+=============+========+
3131
| Show Search | *Tab* |
3232
+-------------+--------+
3333

34-
Hotkeys
35-
=======
34+
Context Menu
35+
============
36+
37+
By default the NodeGraph is has a default context menu with some actions.
38+
3639

37-
The node graph comes built with some default action with assigned hotkeys.
3840

3941
see: :ref:`Menus`
4042

0 commit comments

Comments
 (0)