Skip to content

Commit 0e325d1

Browse files
committed
minor bug fix and doc clean up
1 parent d7f2ca5 commit 0e325d1

File tree

7 files changed

+77
-40
lines changed

7 files changed

+77
-40
lines changed

NodeGraphQt/base/graph.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,29 @@ class NodeGraph(QtCore.QObject):
2525
base node graph controller.
2626
"""
2727

28-
#: signal emits the node object when a node is created in the node graph.
28+
#: (signal) emits the node object when a node is created in the node graph.
2929
node_created = QtCore.Signal(NodeObject)
30-
#: signal emits a list of node ids from the deleted nodes.
30+
#: (signal) emits a list of node ids from the deleted nodes.
3131
nodes_deleted = QtCore.Signal(list)
32-
#: signal emits the node object when selected in the node graph.
32+
#: (signal) emits the node object when selected in the node graph.
3333
node_selected = QtCore.Signal(NodeObject)
34-
#: signal triggered when a node is double clicked and emits the node.
34+
#: (signal) triggered when a node is double clicked and emits the node.
3535
node_double_clicked = QtCore.Signal(NodeObject)
36-
#: signal for when a node has been connected emits (source port, target port).
36+
#: (signal) for when a node has been connected emits (source port, target port).
3737
port_connected = QtCore.Signal(Port, Port)
38-
#: signal for when a node has been disconnected emits (source port, target port).
38+
#: (signal) for when a node has been disconnected emits (source port, target port).
3939
port_disconnected = QtCore.Signal(Port, Port)
40-
#: signal for when a node property has changed emits (node, property name, property value).
40+
#: (signal) for when a node property has changed emits (node, property name, property value).
4141
property_changed = QtCore.Signal(NodeObject, str, object)
42-
#: signal for when drop data has been added to the graph.
42+
#: (signal) for when drop data has been added to the graph.
4343
data_dropped = QtCore.Signal(QtCore.QMimeData, QtCore.QPoint)
4444

4545
def __init__(self, parent=None):
4646
super(NodeGraph, self).__init__(parent)
4747
self.setObjectName('NodeGraphQt')
48+
self._widget = None
4849
self._model = NodeGraphModel()
49-
self._viewer = NodeViewer(parent)
50+
self._viewer = NodeViewer()
5051
self._node_factory = NodeFactory()
5152
self._undo_stack = QtWidgets.QUndoStack(self)
5253

@@ -223,23 +224,42 @@ def model(self):
223224
"""
224225
return self._model
225226

227+
@property
228+
def widget(self):
229+
"""
230+
Return the node graph widget.
231+
232+
Returns:
233+
QtWidgets.QWidget: node graph widget.
234+
"""
235+
if self._widget is None:
236+
self._widget = QtWidgets.QWidget()
237+
layout = QtWidgets.QVBoxLayout(self._widget)
238+
layout.setContentsMargins(0, 0, 0, 0)
239+
layout.addWidget(self._viewer)
240+
return self._widget
241+
226242
def show(self):
227243
"""
228-
Show node graph viewer widget this is just a convenience
229-
function to :meth:`NodeGraph.viewer().show()`.
244+
Show node graph widget this is just a convenience
245+
function to :meth:`NodeGraph.widget.show()`.
230246
"""
231-
self._viewer.show()
247+
self._widget.show()
232248

233249
def close(self):
234250
"""
235251
Close node graph NodeViewer widget this is just a convenience
236-
function to :meth:`NodeGraph.viewer().close()`.
252+
function to :meth:`NodeGraph.widget.close()`.
237253
"""
238-
self._viewer.close()
254+
self._widget.close()
239255

240256
def viewer(self):
241257
"""
242-
Return the node graph viewer widget.
258+
Returns the view interface used by the node graph.
259+
260+
Note:
261+
All functions in the `NodeViewer` should only be used internally
262+
by the `NodeGraph` class.
243263
244264
Returns:
245265
NodeGraphQt.widgets.viewer.NodeViewer: viewer widget.

NodeGraphQt/widgets/viewer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
class NodeViewer(QtWidgets.QGraphicsView):
2424
"""
25-
node viewer is the widget used for displaying the scene and nodes
25+
The widget interface used for displaying the scene and nodes.
2626
27-
functions in this class is used internally by the
27+
functions in this class are called by the
2828
class:`NodeGraphQt.NodeGraph` class.
2929
"""
3030

@@ -40,8 +40,6 @@ class NodeViewer(QtWidgets.QGraphicsView):
4040

4141
def __init__(self, parent=None):
4242
super(NodeViewer, self).__init__(parent)
43-
if parent is not None:
44-
self.setWindowFlags(QtCore.Qt.Window)
4543

4644
scene_pos = (SCENE_AREA / 2) * -1
4745
self.setScene(NodeScene(self))
@@ -51,7 +49,7 @@ def __init__(self, parent=None):
5149
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
5250
self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
5351
self.setAcceptDrops(True)
54-
self.resize(1000, 800)
52+
self.resize(850, 800)
5553

5654
self._pipe_layout = PIPE_LAYOUT_CURVED
5755
self._detached_port = None

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ if __name__ == '__main__':
8282
# connect node a input to node b output.
8383
node_a.set_input(0, node_b.output(0))
8484

85-
# show widget.
86-
viewer = graph.viewer()
87-
viewer.show()
85+
# get the widget and show.
86+
graph_widget = graph.widget
87+
graph_widget.show()
8888

8989
app.exec_()
9090
```

docs/graph.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ The ``NodeGraph`` class is the main controller for managing all nodes.
88
.. image:: _images/graph.png
99
:width: 60%
1010

11-
----
11+
NodeGraph
12+
=========
13+
14+
NodeGraph Attributes
15+
--------------------
16+
17+
.. autoattribute:: NodeGraphQt.NodeGraph.widget
18+
.. autoattribute:: NodeGraphQt.NodeGraph.model
19+
20+
NodeGraph Class
21+
---------------
1222

1323
.. autoclass:: NodeGraphQt.NodeGraph
1424
:members:
15-
:exclude-members: model
25+
:exclude-members: model, widget

docs/nodes.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ NodeObject
99

1010
The ``NodeGraphQt.NodeObject`` class is the main base class that all nodes inherit from.
1111

12-
----
1312

14-
.. autoclass:: NodeGraphQt.NodeObject
15-
:members:
16-
:exclude-members: model, NODE_NAME
17-
18-
Attributes
13+
NodeObject Attributes
14+
---------------------
1915

2016
.. autoattribute:: NodeGraphQt.NodeObject.__identifier__
2117
.. autoattribute:: NodeGraphQt.NodeObject.NODE_NAME
18+
.. autoattribute:: NodeGraphQt.NodeObject.graph
19+
.. autoattribute:: NodeGraphQt.NodeObject.id
20+
.. autoattribute:: NodeGraphQt.NodeObject.model
21+
.. autoattribute:: NodeGraphQt.NodeObject.view
22+
23+
24+
NodeObject Class
25+
----------------
26+
27+
.. autoclass:: NodeGraphQt.NodeObject
28+
:members:
29+
:exclude-members: NODE_NAME, graph, id, model, view
2230

2331

2432
BaseNode
@@ -55,7 +63,8 @@ code snippet.
5563
# create an output port.
5664
self.add_output('out')
5765
58-
----
66+
Base Class
67+
----------
5968

6069
.. autoclass:: NodeGraphQt.BaseNode
6170
:members:
@@ -72,7 +81,8 @@ The ``NodeGraphQt.BackdropNode`` class allows other node object to be nested ins
7281
.. image:: _images/backdrop.png
7382
:width: 250px
7483

75-
----
84+
BackdropNode Class
85+
------------------
7686

7787
.. autoclass:: NodeGraphQt.BackdropNode
7888
:members:

docs/overview.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ example code:
9797
graph.register_node(FooNode)
9898
9999
# show the node graph widget.
100-
viewer = graph.viewer()
101-
viewer.show()
100+
graph_widget = graph.widget
101+
graph_widget.show()
102102
103103
# create two nodes.
104104
node_a = graph.create_node('com.chantasticvfx.FooNode', name='node A')

example.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def __init__(self):
4242
# set up default menu and commands.
4343
setup_context_menu(graph)
4444

45-
# viewer widget used for the node graph.
46-
viewer = graph.viewer()
47-
viewer.resize(1100, 800)
48-
viewer.show()
45+
# widget used for the node graph.
46+
graph_widget = graph.widget
47+
graph_widget.resize(1100, 800)
48+
graph_widget.show()
4949

5050

5151
# show the properties bin when a node is "double clicked" in the graph.
@@ -117,5 +117,4 @@ def show_nodes_list(node):
117117
menu_node.set_input(0, bar_node.output(1))
118118
bar_node.set_input(0, text_node.output(0))
119119

120-
121120
app.exec_()

0 commit comments

Comments
 (0)