class Activator(pynetsym.Activator): infected_nodes = Set(CInt) def tick(self): if self.infected_nodes: super(Activator, self).tick() else: # no more infected nodes, we can just quit! self.signal_termination('No more infected') def infected(self, node): """ Whenever a node is infected, it notifies the Activator. The activator keeps track of the infected nodes, which are the only ones that receive an `activate` message. """ self.infected_nodes.add(node) self.send(Recorder.name, 'node_infected', node=node) def not_infected(self, node): """ Whenever a node recovers, it notifies the Activator. """ self.infected_nodes.remove(node) self.send(Recorder.name, 'node_recovered', node=node) def nodes_to_activate(self): """ Only the infected nodes are activated. """ return self.infected_nodes
class NestedContainerClass(HasTraits): # Used in regression test for changes to nested containers # Nested list list_of_list = List(List) # enthought/traits#281 dict_of_list = Dict(Str, List(Str)) # Similar to enthought/traits#281 dict_of_union_none_or_list = Dict(Str, Union(List(), None)) # Nested dict # enthought/traits#25 list_of_dict = List(Dict) dict_of_dict = Dict(Str, Dict) dict_of_union_none_or_dict = Dict(Str, Union(Dict(), None)) # Nested set list_of_set = List(Set) dict_of_set = Dict(Str, Set) dict_of_union_none_or_set = Dict(Str, Union(Set(), None))
class BasicConfigurator(AbstractConfigurator): """ A BasicConfigurator needs a network_size parameter that specifies the size of the initial network. network_size nodes of type node_type (specified in the body of the configurator) are created and are passed the arguments from additional_arguments specified in node_options. """ options = {"starting_network_size"} starting_network_size = Int(1000) node_type = Type node_options = Set(Str) def create_edges(self): pass def create_nodes(self): self.node_arguments = extract_sub_dictionary(self.full_parameters, self.node_options) node_ids = SequenceAsyncResult([ self.send(NodeManager.name, 'create_node', cls=self.node_type, parameters=self.node_arguments) for _r in xrange(self.starting_network_size) ]) self.node_identifiers = node_ids.get()
class A(HasTraits): alist = List(Int, list(range(5))) adict = Dict(Str, Int, dict(a=1, b=2)) aset = Set(Int, set(range(5))) events = List() @on_trait_change("alist_items,adict_items,aset_items") def _receive_events(self, object, name, old, new): self.events.append((name, new))
class Activator(pynetsym.Activator): infected_nodes = Set(Int) def tick(self): if self.infected_nodes: super(Activator, self).tick() else: self.signal_termination('No more infected') def infected(self, node): self.infected_nodes.add(node) self.send(Recorder.name, 'node_infected', node=node) def not_infected(self, node): self.infected_nodes.remove(node) self.send(Recorder.name, 'node_recovered', node=node) def nodes_to_activate(self): return self.infected_nodes
class ClassWithSet(HasTraits): values = Set()