ironflow.model.model module
The back-end model which interfaces with Ryven.
- class ironflow.model.model.HasSession(session_title: str, *args, extra_nodes_packages: list | None = None, enable_ryven_log: bool = False, **kwargs)[source]
Bases:
ABCMixin for an object which has a Ryven session as the underlying model
- property active_script_index: int
- create_script(title: str | None = None, create_default_logs: bool = True, data: dict | None = None) None[source]
- property n_scripts
- property next_auto_script_name
- recommend_nodes(port: NodeInput | NodeOutput)[source]
- register_node(node_class: Type[Node], node_group: str | None = None) None[source]
Registers a node class with the ryven session and model, storing it in nodes_dictionary. Some node attributes (identifier_prefix and type_) are also set on the Node class.
- Parameters:
node_class (Type[Node]) – The node class to register.
node_group (str | None) – The sub-collection to which this node belongs. (Default is None, which uses the last bit of the module path.)
- Note: The sub-collection in the nodes_dictionary to which the node gets added depends only on the tail of its
module path, so it is possible that nodes from two different sources get grouped together. In case this leads to a conflict, node_module can be explicitly provided and this will be used instead.
- Note: You can re-register a class to update its functionality, but only newly placed nodes will see this
update. Already-placed nodes are still instances of the old class and need to be deleted.
- Note: You can save the graph as normal, but new gui instances will need to register the same custom nodes before
loading the saved graph is possible.
Example
>>> from ironflow import GUI >>> from ironflow.node_tools import Node, NodeInputBP, NodeOutputBP, dtypes, input_widgets >>> gui = GUI(script_title='foo') >>> >>> class MyNode(Node): >>> title = "MyUserNode" >>> init_inputs = [ >>> NodeInputBP(dtype=dtypes.Integer(default=1), label="foo") >>> ] >>> init_outputs = [ >>> NodeOutputBP(label="bar") >>> ] >>> color = 'cyan' >>> >>> def update_event(self, inp=-1): >>> self.set_output_val(0, self.input(0) + 42) >>> >>> gui.register_node(MyNode)
- register_nodes(source: str | Path | ModuleType | list | tuple, node_group: str | None = None) None[source]
- register_nodes_from_file(file_path: str | Path, node_group: str | None = None) None[source]
Loads a .py file as a module, then searches through it for all subclasses ironflow.main.node.Node whose name ends with ‘_Node’ and register them with the ryven session and the model’s nodes_dictionary.
- Parameters:
file_path (str | pathlib.Path) – The .py file to load.
node_group (str | None) – The sub-collection to which this node belongs. (Default is None, which uses the file name stripped of its .py suffix.)
- register_nodes_from_module(module: ModuleType, node_group: str | None = None) None[source]
Search through the provided python module for all subclasses ironflow.main.node.Node whose name ends with ‘_Node’ and register them with the ryven session and the model’s nodes_dictionary.
- Parameters:
module (types.ModuleType) – The module to register from.
node_group (str | None) – The sub-collection to which this node belongs. (Default is None, which uses the last bit of the module path.)