On Nov 15, 2010, at 5:06 AM, Fraser Burns wrote:

> A typical instance of a panel might be:
>    pan = self.Panel = dabo.ui.dPanel(self, BackColor=(255,200,200))
> 
> It is also valid to write:
>    self.Panel = dabo.ui.dPanel(self, BackColor=(255,200,200), Name="Foo")
> 
> Then you could refer to it as pan, or as self.Panel or as self.Foo
> 
> When coding in Python the first form seems to be the norm.
> When using Class Designer, the third form seems to take over.
> 
> So quite where does the Name property fit in?
> How should these different forms be best used?

        The first form assigns two names: one local to the method ('pan'), 
which can then be used to further manipulate or otherwise interact with the 
panel in the method it was created. The second name ('self.Panel') also stores 
a reference to the panel in the parent object's namespace, so that other 
methods of that object can refer to it later. If you're just adding objects 
that you won't need to interact with later on, storing a reference as an 
attribute is probably not necessary.

        The 'Name' property, though, is a Dabo convenience that ensures that 
every object within a container has a unique name. If you set it explicitly, it 
is your responsibility to ensure that no other siblings have the same name, or 
a NameError is raised. The more common practice is to allow Dabo to set the 
Name when the object is created; this will result in a series of names based on 
the object's class (e.g., 'dPanel', 'dPanel1', 'dPanel2', etc.). Names 
automagically become a reference to the object by its parent, and you can use a 
dot-separated list of containers to reference an object nested deeply within 
others; e.g.: 
self.Form.dPageFrame1.dPage3.dPanel.dSplitter.MixedSplitterPanel1.dPanel3.dTextBox

        While such nested referencing works, it is very brittle and should be 
avoided, as changing the Name of any one of those containers will break the 
reference. If you need a reference to the textbox described above, a much 
better strategy would be to assign a meaningful value to its 'RegID' property. 
'RegID' is completely optional, but if you assign a value, it must be unique 
among all members of a form. It is then incorporated into the form's namespace, 
so instead of the bulky reference above, you can reference it as 
'self.Form.NestedTextbox', assuming that you assigned it a RegID of 
'NestedTextbox'. 

        A good rule of thumb is that anytime you find yourself using more than 
one dot to reference an object, you either need to rethink your design, or you 
need to use RegIDs to simplify your references.



-- Ed Leafe



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to