Comments (8)
Please also post a complete minimal example reproducing the problem, so I can quickly inspect it.
from ryvencore-qt.
Sorry for the unclear description. Here is my node defination nodes.py
:
import ryvencore_qt as rc
from qtpy import QtWidgets
class MyWidget(rc.IWB, QtWidgets.QLineEdit):
def __init__(self, params):
rc.IWB.__init__(self, params)
QtWidgets.QLineEdit.__init__(self)
self.setPlaceholderText("Input...")
self.editingFinished.connect(self.update_node)
self.setFixedWidth(100)
def get_val(self):
return self.text()
def val_update_event(self, val):
self.setText(str(val))
class MyNode(rc.Node):
title = 'My test node'
init_inputs = [
rc.NodeInputBP(
dtype=rc.dtypes.Data(default=1), # if remove this line will be ok
add_data={
'widget name': 'my',
'widget pos': 'below',
}
),
]
input_widget_classes = {
'my': MyWidget
}
init_outputs = []
def __init__(self, params):
super().__init__(params)
def update_event(self, inp=-1):
print(
self.input(0) # get data from the first input
)
export_nodes = [
MyNode,
]
When create the node, this error occured:
$ python main.py
Traceback (most recent call last):
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowView.py", line 830, in create_node__cmd
self._push_undo(
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowView.py", line 286, in _push_undo
cmd.activate()
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowCommands.py", line 39, in activate
self.redo()
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowCommands.py", line 45, in redo
self.redo_()
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowCommands.py", line 120, in redo_
self.call(self.flow.create_node, (self.node_class,))
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowCommands.py", line 63, in call
ret = target_method(*args)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore\Flow.py", line 103, in create_node
self.add_node(node)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore\Flow.py", line 116, in add_node
self.node_added.emit(node)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore\Base.py", line 22, in emit
cb(*args)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\FlowView.py", line 848, in add_node
item.initialize()
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\nodes\NodeItem.py", line 100, in initialize
self.add_new_input(i)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\nodes\NodeItem.py", line 137, in add_new_input
item = InputPortItem(inp.node, self, inp)
File "C:\Users\Nangu\miniconda3\envs\qt\lib\site-packages\ryvencore_qt\src\flows\nodes\PortItem.py", line 82, in __init__
c_d = self.port.add_data['widget data']
KeyError: 'widget data'
from ryvencore-qt.
sorry for the delay, kinda forgot about this :| you are trying to use a dtype and a custom widget at the same time. Specifying a dtype already adds a dedicated widget, and there can only be one. The error message is indeed not helpful...
from ryvencore-qt.
Thanks for your answer. I think it might be better to decouple the widget from the dtype so that the user can control this behavior.
from ryvencore-qt.
I found that this can be solved by using add_data
in the params
:
class MyWidget(rc.IWB, QtWidgets.QLineEdit):
def __init__(self, params):
rc.IWB.__init__(self, params)
QtWidgets.QLineEdit.__init__(self)
add_data = params[0].add_data
default = add_data.get('widget default')
if default:
self.setText(default)
self.setPlaceholderText("Input...")
self.editingFinished.connect(self.update_node)
self.setFixedWidth(100)
def get_val(self):
return self.text()
def val_update_event(self, val):
self.setText(str(val))
class MyNode(rc.Node):
title = 'My test node'
init_inputs = [
rc.NodeInputBP(
add_data={
'widget name': 'my',
'widget pos': 'below',
'widget default': 'hello',
}
),
]
input_widget_classes = {
'my': MyWidget
}
init_outputs = []
def __init__(self, params):
super().__init__(params)
def update_event(self, inp=-1):
print(
self.input(0) # get data from the first input
)
from ryvencore-qt.
Thanks for your answer. I think it might be better to decouple the widget from the dtype so that the user can control this behavior.
this is the point of the dtypes (so far). you can always use custom widgets, the dtypes are for frequently occurring types of input so you don't need to implement primitive widgets like a line edit for a string or something. The dtypes really have no other meaning so far.
from ryvencore-qt.
Understood. Maybe I'm misdirecting the discussion, I just want a way to pass default values to widgets
from ryvencore-qt.
If you want to use dtype widgets they have a default
parameter, e.g.
class MyNode(Node):
init_inputs = [
NodeInputBP('data', dtype=dtypes.Data(default=42.0)),
NodeInputBP('val', dtype=dtypes.Integer(default=5, bounds=(0, 10)),
]
from ryvencore-qt.
Related Issues (7)
- Problem with file open dialogs HOT 3
- Error when connecting to dtype inputs HOT 5
- Blank screen with basic example HOT 2
- Support other Qt bindings HOT 4
- typo HOT 1
- Zoom out is broken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ryvencore-qt.