It seems that in flow_view.py (click_handler), the init is called once in self._scene.registry.create(model_name) and another time in self.scene.create_node(type)
Expected Behavior
NodeDataModel init method should be called only once per node when using the GUI for adding a node.
Note: this issue does not occur when the node is added directly in the Python script as it is done in calculator.py.
self._scene.registry.create(model_name) (line 168 of flow_view.py) should check whether a model exists already without having to create an instance.
If the model does exist, icreate an instance of that model thru the call to self.scene.create_node(type) (line 170 from flow_view.py)
Current Behavior
self._scene.registry.create(model_name) creates an instance of the class "model_name" (hence calling init) and call init again in self.scene.create_node(type)
This occurs only when click_handler (line 163 of flow_view.py) is called
Calling init only once ensures that what is done inside the init will be done once.
Possible Solution
If a model has been created already, do not create it again, what could be done by having a way to check whether a model has been created already
Steps to Reproduce (for bugs)
I have added a print('NumberSourceDataModel') in the init of NumberSourceDataModel in calculator.py (provided as an example by qtpynodeeditor).
When I run calculator.py, this message is printed 10 times as expected (5 * 2)
But when I add a NumberSourceDataModel from the screen, I have 2 print for a single instance, what I find not normal.
Context
I have a NodeDataModel for Webcam acquisition using opencv.VideoCapture. This call is very long already but when called twice it is even worst.
Your Environment
python 3, pyqt5, last qtpynodeeditor version installed in July