Ryven icon indicating copy to clipboard operation
Ryven copied to clipboard

Disable input widget or mark it as unused?

Open sphh opened this issue 4 years ago • 10 comments

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:

  1. Have three inputs and change the label_str accordingly. This works perfectly.
  2. 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?

sphh avatar Apr 03 '22 20:04 sphh

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.

leon-thomm avatar Apr 03 '22 20:04 leon-thomm

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?

sphh avatar Apr 03 '22 20:04 sphh

self.item.inputs[i].widget, and remember to do that checked if you want to enable headless deployment

leon-thomm avatar Apr 03 '22 20:04 leon-thomm

Thanks! Very helpful indeed.

Do I have to check for the existence of self.item or of self.item.inputs[i].widget?

sphh avatar Apr 03 '22 20:04 sphh

Check for self.item, i.e.

if self.item:
    ...

leon-thomm avatar Apr 03 '22 20:04 leon-thomm

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)

sphh avatar Apr 03 '22 21:04 sphh

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.

sphh avatar Apr 03 '22 21:04 sphh

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?

sphh avatar Apr 04 '22 21:04 sphh

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

leon-thomm avatar Apr 05 '22 08:04 leon-thomm

Excellent! That's that one I was looking for. Thanks.

sphh avatar Apr 05 '22 09:04 sphh