Profile Picture

Is there an event or a way to know when an RDockWidget has Activated?

Posted By Data Juggler 4 Years Ago
You don't have permission to rate!

Is there an event or a way to know when an RDockWidget has Activated?

Author
Message
Data Juggler
Data Juggler
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)

Group: Forum Members
Last Active: 9 Months Ago
Posts: 1.8K, Visits: 5.6K
I have some code that I know works, because if you call it in a button event, it works. If I call the same code before the dock widget has finished loading, I get a Class Name error.

I have this Python Script:
https://github.com/DataJuggler/PythonScripts/blob/main/CarDriver.py

I created a class called PropInfo, so I can load all the props into memory, and not have to call prop.GetName() more than once per prop.

I had to rearrange my user interface to have a Load Props button, and after clicking that, the other buttons become enabled.

https://forum.reallusion.com/uploads/images/45e99e10-093e-4bae-89e1-c850.png

After clicking, I enable the other buttons.

https://forum.reallusion.com/uploads/images/477800bc-79a4-4a13-b76b-c1da.png

I would much prefer to not force the users to click the Load Props button, since I know the call to get all_props works.

For some reason, this method throws an error if called before the UI has finished loading.

def ConvertProps(all_props):
    
    # initial value
    props = []
    # counter
    count = 0
    # ensure the all_props exist
    if (all_props is not None):
        # iterate all_props
        for i in range (len(all_props)):
            # create a new class
            prop = PropInfo()
            
            # set the properties
            prop.Prop = all_props[i]
            prop.Name = prop.Prop.GetName()
            prop.Index = count

            # add this item
            props.append(prop)

            # increment
            count = count + 1
    # return value
    return props

The error is from this line:
prop = PropInfo()

This works fine if I do it in a button click event.

If I try and call LoadProps or ConvertProps before the UI is shown, I get this:

Error:
<class 'NameError'>, File: C:/Projects/GitHub/PythonScripts/CarDriver/CarDriver.py, Line: 525

My work around works to enable the other buttons after they click the Load Props button, but I don't understand why I can't "Preload" the Props collection.

In Windows Forms I would look for an 'Activated' event, but I don't see a way in the RDockWidget.

Do duplicate this, call LoadProps() anywhere after all_props is loaded:

all_props = RLPy.RScene.FindObjects(RLPy.EObjectType_Prop)

# throws error before UI is shown
LoadProps()

Thanks, if anyone has any insight.



Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png





Reading This Topic