Finding Objects in the Editor

If you have a form which has a quite complicated structure, with multiple nested blocks and containers, working how to access some control from inside an event function can become quite difficult, in the sense that getting the name of the control relative to the object whose event function is executing is rather error prone. The editors object finding helper can make a big difference here.

Suppose you have a button; when the button is clicked, some other control somewhere else in the form should be cleared. The code needs to look something like:

def eventFunc (button) :
    button.__parent__.people.address.postcode.value = ''
      

But exactly what is the path? Are you sure that __parent__.people.address.postcode gets you there? Was that block called people or person? OK, here's how to do it. Enter the event function code to the point shown below, with the cursor just after the period at. button.

def eventFunc (button) :
    button.
      

Then enter Ctrl-O (O is for Object. This brings up the object locator dialog:

The dialog shows the object heirarchy of the form as a tree. It is initially opened to the point where the object to which the event function applies (in this case the button) is visible and highlighted. Use the tree to find the target object (and you can see here that the block is called customer and neither people nor person). Then click the Return as Path button, and the path to the target object will be inserted into the editor.

Return as Path returns the path in the form described in the previous Direct Access to Objects section. If you'd like it returned in a form suitable for the getNamedCtrl method, then use the Return as Name button.

Note that this dialog always starts with the object associated with the event. If you had typed button.__parent__. before Ctrl-O, then it would still have started at the button. It does not do anything clever like parse the code; in fact, it works anywhere in the code editor.

For later reference (for the Components and Event/Slot Scripting chapter), this dialog also works when editing slot code.