Open Robsel opened 2 months ago
i have realized i need to subclass Data, but I don't understand where
It's a bit hard for me to help without precisely understanding the problem.
Datenbank
? what is the purpose?```python
for syntax highlightingThank you for looking into it! I've managed to understand my mistakes and got it working like I wanted since posting.
class Data_sub(Data):
def __init__(self, value=None, load_from=None):
super().__init__(value, load_from)
def serialize(self, data):
self.value ={"data": data}
def deserialize(self):
return self.value["data"]
After subclassing Data to serialize what I want to transfer to another node into a Data object I can then send via
self.set_output_val(index: int, data: Data)
To access the sent data via self.input(index: int)
I needed to add .payload
which isn't specified in the Readme. Without that it is a Data object.
Before being able to use the payload, it needs to be deserialized still:
class PrintNode(Node):
title = 'Print'
init_inputs = [NodeInputType()]
def __init__(self, params: Tuple[Flow | Session]):
self.dat= Data_sub()
super().__init__(params)
def update_event(self, inp=-1):
print(self.input(0).payload) #prints my Data_sub object
self.dat=self.input(0)
k = self.dat.deserialize()
print(k) #prints the data
With this I managed to transfer a dict between nodes.
It seems superfluous to have to subclass Data instead of (de)serialize being a def to call onto to send custom data between nodes.
There is also no error in console when using set_output_val()
wrong, which would be helpful.
Unrelated, but before I struggle for another month I'd rather ask: I plan to use Ryven as a Design GUI, so one can model "a conversation" via nodes with content and paths between them. Is there a quick way to export this, with names for the paths and the nodes (with content)?
I don't fully understand what you intend to use this serialize
/deserialize
for, there is no need to serialize data structure when passing them from one node to another. You can just pass the Data
object to set_output_val
and retrieve it in the receiving node with input()
.
I plan to use Ryven as a Design GUI, so one can model "a conversation" via nodes with content and paths between them. Is there a quick way to export this, with names for the paths and the nodes (with content)?
So Ryven saves projects in a JSON format that should be easy to work with for further processing. Otherwise, you can build it directly into the nodes. For example:
say we have a node "oo:plus:o" (2 in, 1 out) and "oo:minus:o" and they apply "+" and "-" on numeric input values. Now you want to add the ability to instead generate a parameterized expression, e.g."(inp1 + inp2) - (inp3 + inp4)". I would probably define a new data type class Expr(Data)
(as opposed to Numeric(Data)
or something) which you treat differently in your update_event()
in plus/minus.[^1] This is just an example to get you started, there are many completely different approaches.
[^1]: The very Pythonic way would be to not change your plus/minus nodes at all but overload the __add__
and __sub__
methods in Expr
to secretly generate the expression instead or performing the calculation, when the respective operations are applied to two Expr
s, but this might make life more difficult than it needs to be.
My point was that I need to subclass Data in the first place to pass custom data, an info I only found thoroughly searching and reading the source code. For example arithmatic
is a complex data structure:
def update_event(self):
self.arithmatic.serialize
self.set_output_val(0, self.arithmatic)
But I guess at that point it would be just as possible to implement this into set_output_val
, so the Data subclass didnt have to exist in the first place.
I will probably use the JSON provided, but thats a great way to explain it :) Thank you for the feedback, it's much appreciated.
nodes.py:
gui.py:
I can import the nodes just fine and I've checked for errors in the code but it's not that complicated, any use of set_output_val results in nothing.
I put in prints in the "Textbox" node, and they only ever confirm 'ok', which means as soon as self.set_output_val is called, it stops the rest of the update_event def
I'm sorry for messy code. :°