def simulate_destruction_notifications(self): """emits messages as if we were adding elements to the composite node""" Node.simulate_destruction_notifications(self) ids = self.vertices() for eltid in ids: node = self.node(eltid) self.notify_vertex_removal(node) for eid in self.edges(): (src_id, dst_id) = self.source(eid), self.target(eid) etype = None src_port_id = self.local_id(self.source_port(eid)) dst_port_id = self.local_id(self.target_port(eid)) nodeSrc = self.node(src_id) nodeDst = self.node(dst_id) src_port = nodeSrc.output_desc[src_port_id] dst_port = nodeDst.input_desc[dst_port_id] #don't notify if the edge is connected to the input or #output nodes. # if(src_id == self.id_in or dst_id == self.id_out): # continue edgedata = "default", eid self.notify_listeners(("edge_removed", edgedata))
def __init__(self, inputs): """ inputs : list of dict(name='', interface='', value'',...) """ Node.__init__(self, outputs=inputs) self.internal_data['caption'] = "In"
def set_io(self, inputs, outputs): """ Define inputs and outputs Inputs and outputs are list of dict(name='', interface='', value='') """ # I/O ports # Remove node if nb of input has changed if (self.id_in is not None and len(inputs) != self.node(self.id_in).get_nb_output()): self.remove_node(self.id_in) self.id_in = None if (self.id_out is not None and len(outputs) != self.node(self.id_out).get_nb_input()): self.remove_node(self.id_out) self.id_out = None # Create new io node if necessary if (self.id_in is None): self.id_in = self.add_node(CompositeNodeInput(inputs)) else: self.node(self.id_in).set_io((), inputs) if (self.id_out is None): self.id_out = self.add_node(CompositeNodeOutput(outputs)) else: self.node(self.id_out).set_io(outputs, ()) Node.set_io(self, inputs, outputs)
def set_io(self, inputs, outputs): """ Define inputs and outputs Inputs and outputs are list of dict(name='', interface='', value='') """ # I/O ports # Remove node if nb of input has changed if(self.id_in is not None and len(inputs) != self.node(self.id_in).get_nb_output()): self.remove_node(self.id_in) self.id_in = None if(self.id_out is not None and len(outputs) != self.node(self.id_out).get_nb_input()): self.remove_node(self.id_out) self.id_out = None # Create new io node if necessary if(self.id_in is None): self.id_in = self.add_node(CompositeNodeInput(inputs)) else: self.node(self.id_in).set_io((), inputs) if(self.id_out is None): self.id_out = self.add_node(CompositeNodeOutput(outputs)) else: self.node(self.id_out).set_io(outputs, ()) Node.set_io(self, inputs, outputs)
def simulate_destruction_notifications(self): """emits messages as if we were adding elements to the composite node""" Node.simulate_destruction_notifications(self) ids = self.vertices() for eltid in ids: node = self.node(eltid) self.notify_vertex_removal(node) for eid in self.edges(): (src_id, dst_id) = self.source(eid), self.target(eid) etype=None src_port_id = self.local_id(self.source_port(eid)) dst_port_id = self.local_id(self.target_port(eid)) nodeSrc = self.node(src_id) nodeDst = self.node(dst_id) src_port = nodeSrc.output_desc[src_port_id] dst_port = nodeDst.input_desc[dst_port_id] #don't notify if the edge is connected to the input or #output nodes. # if(src_id == self.id_in or dst_id == self.id_out): # continue edgedata = "default", eid self.notify_listeners(("edge_removed", edgedata))
def invalidate(self): """ Invalidate nodes """ Node.invalidate(self) for vid in set(self.vertices()): node = self.actor(vid) node.invalidate()
def reset(self): """ Reset nodes """ Node.reset(self) for vid in set(self.vertices()): node = self.actor(vid) node.reset()
def _init_internal_data(self, d): """This method is called after the node has been instantiated, to fill in the internal_data dictionnary.""" Node._init_internal_data(self, d) inputs = d.get("methodSig") methodName = d.get("methodName") if inputs and methodName: self.internal_data["methodName"] = methodName self.internal_data["methodSig"] = inputs self.build_ports(inputs)
def __init__(self, inputs=(), outputs=()): """ Inputs and outputs are list of dict(name='', interface='', value='') """ DataFlow.__init__(self) self.id_in = None self.id_out = None Node.__init__(self, inputs, outputs) # graph modification status self.graph_modified = False self.evaluating = False self.eval_algo = None
def __init__(self, packagedata, editors=None, includes=[]): """ @packagedata : A file contained in a defined package. @editors : A dictionary of commands which act on the file. @includes : Other files that are included in the data file. """ Node.__init__(self, inputs=(dict(name='data', interface=IData, value=packagedata), dict(name='editors', interface=None, value=editors), dict(name='includes', interface=None, value=includes)), outputs=(dict(name='data', interface=IData), ), ) self.caption = '%s' % (packagedata.name) self.watch = None self.monitor_file(str(packagedata)) if not includes: self.set_port_hidden(2, True)
def create_fake_node(self, vid): """ Return an empty node with the correct number of inputs and output """ # Count in and out needed ins = 0 outs = 0 for eid, link in self.connections.iteritems(): (source_vid, source_port, target_vid, target_port) = link if(source_vid == vid): outs = max(outs, source_port) elif(target_vid == vid): ins = max(ins, target_port) node = Node() attributes = copy.deepcopy(self.elt_data[vid]) ad_hoc = copy.deepcopy(self.elt_ad_hoc.get(vid, None)) self.load_ad_hoc_data(node, attributes, ad_hoc) # copy node input data if any values = copy.deepcopy(self.elt_value.get(vid, ())) for p in range(ins+1): port = node.add_input(name="In"+str(p)) for p in range(outs+1): port = node.add_output(name="Out"+str(p)) for vs in values: try: #the two first elements are the historical #values : port Id and port value #beyond that are extensions added by gengraph: #the ad_hoc_dict representation is third. port, v = vs[:2] node.set_input(port, eval(v)) if(len(vs)>2): d = MetaDataDict(vs[2]) node.input_desc[port].get_ad_hoc_dict().update(d) except: continue return node
def test_dataflow_state_get_data(): df = DataFlow() vid1 = df.add_vertex() pid10 = df.add_in_port(vid1, "in") pid11 = df.add_out_port(vid1, "out") vid2 = df.add_vertex() pid21 = df.add_out_port(vid2, "out") vid5 = df.add_vertex() pid51 = df.add_out_port(vid5, "out") vid3 = df.add_vertex() pid31 = df.add_in_port(vid3, "in1") pid32 = df.add_in_port(vid3, "in2") pid33 = df.add_out_port(vid3, "res") vid4 = df.add_vertex() pid41 = df.add_in_port(vid4, "in") df.connect(pid11, pid31) df.connect(pid21, pid32) df.connect(pid33, pid41) df.connect(pid51, pid32) dfs = DataflowState(df) for pid in df.ports(): raises(KeyError, lambda: dfs.get_data(pid)) for i, pid in enumerate([pid11, pid21, pid33, pid51]): dfs.set_data(pid, i) raises(KeyError, lambda: dfs.get_data(pid10)) dfs.set_data(pid10, 'a') assert dfs.get_data(pid10) == 'a' for i, pid in enumerate([pid11, pid21, pid33, pid51]): assert dfs.get_data(pid) == i assert dfs.get_data(pid31) == 0 assert tuple(dfs.get_data(pid32)) == (1, 3) assert dfs.get_data(pid41) == 2 n2 = Node() df.set_actor(vid2, n2) assert tuple(dfs.get_data(pid32)) == (1, 3) n5 = Node() df.set_actor(vid5, n5) assert tuple(dfs.get_data(pid32)) == (1, 3) n2.get_ad_hoc_dict().set_metadata('position', [10, 0]) n5.get_ad_hoc_dict().set_metadata('position', [0, 0]) assert tuple(dfs.get_data(pid32)) == (3, 1)
def test_dataflow_state_get_data(): df = DataFlow() vid1 = df.add_vertex() pid10 = df.add_in_port(vid1, "in") pid11 = df.add_out_port(vid1, "out") vid2 = df.add_vertex() pid21 = df.add_out_port(vid2, "out") vid5 = df.add_vertex() pid51 = df.add_out_port(vid5, "out") vid3 = df.add_vertex() pid31 = df.add_in_port(vid3, "in1") pid32 = df.add_in_port(vid3, "in2") pid33 = df.add_out_port(vid3, "res") vid4 = df.add_vertex() pid41 = df.add_in_port(vid4, "in") df.connect(pid11, pid31) df.connect(pid21, pid32) df.connect(pid33, pid41) df.connect(pid51, pid32) dfs = DataflowState(df) for pid in df.ports(): assert_raises(KeyError, lambda: dfs.get_data(pid)) for i, pid in enumerate([pid11, pid21, pid33, pid51]): dfs.set_data(pid, i) assert_raises(KeyError, lambda: dfs.get_data(pid10)) dfs.set_data(pid10, 'a') assert dfs.get_data(pid10) == 'a' for i, pid in enumerate([pid11, pid21, pid33, pid51]): assert dfs.get_data(pid) == i assert dfs.get_data(pid31) == 0 assert tuple(dfs.get_data(pid32)) == (1, 3) assert dfs.get_data(pid41) == 2 n2 = Node() df.set_actor(vid2, n2) assert tuple(dfs.get_data(pid32)) == (1, 3) n5 = Node() df.set_actor(vid5, n5) assert tuple(dfs.get_data(pid32)) == (1, 3) n2.get_ad_hoc_dict().set_metadata('position', [10, 0]) n5.get_ad_hoc_dict().set_metadata('position', [0, 0]) assert tuple(dfs.get_data(pid32)) == (3, 1)
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) self.state = True
def __init__(self, *args): """ Constructor """ Node.__init__(self, *args) self.reset()
def __init__(self, *args, **kwargs): Node.__init__(self, *args, **kwargs) self.internal_data["methodName"] = None self.internal_data["methodSig"] = None self.add_output(name='func_result')
def reset(self): Node.reset(self) self.state = True
def __init__(self, *args): """ Constructor """ Node.__init__(self, *args) self.iterable = "Empty"
def __init__(self, *args): Node.__init__(self, *args) self.set_caption("X")
def __init__(self, *args): Node.__init__(self, *args) self.widget = None self.enabled = not (QtCore.QCoreApplication.instance() is None)
def __init__(self): Node.__init__(self) self.add_input(name="geom", interface=None) self.add_output(name="scene", interface=None)
def close(self): for vid in set(self.vertices()): node = self.actor(vid) node.close() Node.close(self)
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) self.world = World()
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs)
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) self.pool = DataPool()
def __init__(self, *args): Node.__init__(self, *args) self.previous = None
def __init__(self,*args): Node.__init__(self,*args) self.widget = None self.enabled = not (QtCore.QCoreApplication .instance() is None)
def __init__(self, inputs, outputs): Node.__init__(self, inputs, outputs) AbstractListener.__init__(self) self.cm = ControlManager() self.cm.register_listener(self)
def __init__( self, inputs, outputs ): Node.__init__( self, inputs, outputs )