Disable input widget or mark it as unused?
I have a node, which implements the relationship
a = b * c * d
Then I can write 3 additional nodes, which calculate
b = a / (c * d)
c = a / (b * d)
d = a / (b * c)
So far so good. But it's also very unwieldy.
Another approach is to have just one node, where the first input is of dtypes.Choice(items=['a', 'b', 'c', 'd']), which selects which variable will be calculated.
Now there are two routes concerning the input:
- Have three inputs and change the
label_straccordingly. This works perfectly. - Have four inputs and use only those, which are needed. This also works fine, but it would be nice to have a visual indicator to mark the unused input.
How would I disable an input widget or mark it as unused?
Currently, inputs cannot be disabled as a whole, you could only disable a Qt widget. Sounds reasonable, though, I'd call that a missing feature.
Thanks for considering this a missing feature.
Since I use a dtype, disabling the Qt widget would already be a good indication, that the input is not used. How would I get at the Input Qt widget from inside a Node?
self.item.inputs[i].widget, and remember to do that checked if you want to enable headless deployment
Thanks! Very helpful indeed.
Do I have to check for the existence of self.item or of self.item.inputs[i].widget?
Check for self.item, i.e.
if self.item:
...
Thanks, works perfect: The dtypes input widget is now disabled.
The only minor problem is, that both widgets look the nearly the same; but this is a problem of the flow theme … (and I believe it will be sorted, when the whole input can be marked as disabled/unused)
The workaround works perfectly, but I leave this issue open, because it refers to the feature request of disabling the whole input. I hope, this is ok.
I now encountered another ‘error’: When I add such a node, all input widgets are initially active. I tried to update the input widgets from the node's __init__() method (after calling super().__init__()), but this does not work – it looks like the graphical interface is not set yet and so self.item is not set.
Where and when in the initialization process would be a good idea to disable the widget?
Yes, there's the view_place_event() which is a method that gets called once the whole GUI of the node was initialized and placed in the scene, e.g.:
class MyNode(Node):
...
def view_place_event(self):
# now you can access self.item
Excellent! That's that one I was looking for. Thanks.