List of controls within a container

Hello,

I want to write a general purpose function to enable or disable each control inside a container,

something like this:

panel=event.source.parent.getComponent('someContainer')
for ctl in panel.controls:
   print ctl.name
   ctl.enabled=1

But I dont know if there is a property that has a list of all the controls.
Is there a way to do this?

Thank you.

Yes, you can do the following:cont = event.source.parent.getComponent("someContainer") for comp in cont.getComponents(): print comp.name comp.enabled = 1

Thank you very much Travis!

This is great!

Hello Travis,

Taking this code one step ahead… is there a way to determine what type of component is in the cycle?
For instance, let’s say I only want to disable the text fields but not the numeric fields.

Something like:

cont = event.source.parent.getComponent("someContainer")
for comp in cont.getComponents():
    print comp.name
    if comp.type=="textField":
          comp.enabled = 0

Thank you

Yes, but the type is kind of hidden to you:cont = event.source.parent.getComponent("someContainer") for comp in cont.getComponents(): print comp.name if str(comp.getClass()).endswith("PMINumericTextField"): comp.enabled = 0Now to get the actual type you can copy the component from the designer and paste it into a text editor. There you will see the type like PMINumericTextField.

1 Like

Thank you very much Travis!