Module simpleNE
source code
This modules implements the classes NetworkBuilder.
An instance of a SimpleNetworkBuilder provides a Canvas to which NetworkNode
and NetworkConnections can be added to build networks.
The network maintains a list of selected nodes.
Node can have multiple ports. Connections know the 2 nodes they connect and
the port numbers on which they are connected. in a connection, node1 is always
the node from which the connection was initiated and is considered to be the
parent of node2.
Nodes maintain a dictionary of (connections:nodes) paires indicating which node
is conencted by which connection.
Every node has a computeFunction which can be run in a separate thread.
To run a node call the node's schedule method. This will place this node in
a thread safe queue. If the queue is started (see startQueueHandler,
stopQueueHandler), the node's compute function will be called as soon as
all parent nodes are not running.
For data flow, it is the node's compute function task to schedule it's
children node.
node addition and node connection, node selection and deselection,
connection selection and deselection
This file provides an implementation of 1 port networkNodes and multi-port
NetworkNodes as well as an implementation of NetworkConnection.
here is an example of how to use this:
# instanciate an editor
editor = NetworkBuilder('My Network Builder')
# instanciate a node
node1 = NetworkNode(name='node1')
# add this node to the editor
editor.addNode(node1, 100, 100)
# nodes have several methods tha can be used to alter its representation
node1.rename('operator1')
node1.highlight()
node1.unhighlight()
# create a second node
node2 = NetworkNode(name='node2')
editor.addNode(node2, 200, 200)
# connect these 2 nodes
conn1 = editor.connectNodes(node1, node2)
# connections are objects too that can be altered
conn1.highlight()
conn1.unhighlight()
# create a 3rd node and connect it using angular lines
node3 = NetworkNode(name='node3')
editor.addNode(node3, 300, 100)
conn2 = editor.connectNodes(node3, node2, mode='angles')
# create a 4th node and connect it with a spline
node4 = NetworkNode(name='node4')
editor.addNode(node4, 350, 270)
conn3 = editor.connectNodes(node2, node4, mode='angles', smooth=1)
# nodes can be moved
node1.move(200, 100)
# connections can update their representation to reflect node motion
conn1.updatePosition()
# nodes can be selected
editor.selectNodes([node1, node2, node3])
editor.deselectNodes([node1, node4])
editor.clearSelection()
# a sub graph can be moved
editor.moveSubGraph(editor.selectedNodes, 10, 20)
# nodes and connections can be deleted
editor.deleteNodes([node2])
node5 = NetworkNode(name='node5')
editor.addNode(node5, 100, 200)
conn4 = editor.connectNodes(node1, node5, mode='angles')
editor.deleteConnections([conn4])
# try nodes of type 2
n1 = NetworkNode2('test1')
ed.addNode(n1, 100, 350)
n1.addOutputPort()
from NetworkEditor.simpleNE import NetworkNode2
n2 = NetworkNode2('test2')
ed.addNode(n2, 300, 350)
n2.addInputPort()
from NetworkEditor.simpleNE import NetworkConnection
ed.connectNodes(n1, n2, 2, 1)
ed.connectNodes(node5, n2, 0, 2)
ed.selectNodes([n2])
ed.moveSubGraph(ed.selectedNodes, 10, 20)
|
EditorBase
Base class for a network builder.
|
|
NetworkBuilder
This class implements a simple network builder that provides a Canvas
to which NetworkNodes can be added.
|
|
ed = NetworkBuilder("test builder")
|
|
top = Tkinter.Toplevel()
|
|
ed1 = NetworkBuilder("test builder1", master= top, visible...
|
|
node1 = NetworkNode(name= 'node1')
|
|
node2 = NetworkNode(name= 'node2')
|
|
conn1 = ed.connectNodes(node1, node2)
|
|
node3 = NetworkNode(name= 'node3')
|
|
conn2 = ed.connectNodes(node3, node2, mode= 'angles')
|
|
node4 = NetworkNode(name= 'node4')
|
|
conn3 = ed.connectNodes(node2, node4, mode= 'angles', smooth...
|
|
node5 = NetworkNode(name= 'node5')
|
|
conn4 = ed.connectNodes(node2, node5)
|
|
n1 = NetworkNode('test1')
|
|
n2 = NetworkNode('test2')
|
ed
None
-
- Value:
NetworkBuilder("test builder")
|
|
ed1
None
-
- Value:
NetworkBuilder("test builder1", master= top, visibleWidth= 600, totalW
idth= 3000)
|
|
node1
None
-
- Value:
NetworkNode(name= 'node1')
|
|
node2
None
-
- Value:
NetworkNode(name= 'node2')
|
|
conn1
None
-
- Value:
ed.connectNodes(node1, node2)
|
|
node3
None
-
- Value:
NetworkNode(name= 'node3')
|
|
conn2
None
-
- Value:
ed.connectNodes(node3, node2, mode= 'angles')
|
|
node4
None
-
- Value:
NetworkNode(name= 'node4')
|
|
conn3
None
-
- Value:
ed.connectNodes(node2, node4, mode= 'angles', smooth= 1)
|
|
node5
None
-
- Value:
NetworkNode(name= 'node5')
|
|
conn4
None
-
- Value:
ed.connectNodes(node2, node5)
|
|