dabo Commit
Revision 1268
Date: 2005-09-08 13:54:51 -0700 (Thu, 08 Sep 2005)
Author: ed

Changed:
U   trunk/dabo/ui/uiwx/dFormMixin.py
U   trunk/dabo/ui/uiwx/dPemMixin.py

Log:
Added the new RegID property to dPemMixin. This is an optional property that 
can be used to simplify object referencing in complex forms. 

I originally had a object retrieval method in the dFormMixin class, but the 
name resolution code seemed much better and cleaner that I removed it. Now, no 
matter where the object is in the containership hierarchy of the form, you can 
reference it using simple dot notation. E.g., if the object's RegID is 
'cellphone', any code in the form can reference it as 'self.cellphone', and any 
other object on the form can reference it as 'self.Form.cellphone'.

Also cleaned up some code for the BorderStyle property.


Diff:
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py    2005-09-08 17:53:51 UTC (rev 1267)
+++ trunk/dabo/ui/uiwx/dFormMixin.py    2005-09-08 20:54:51 UTC (rev 1268)
@@ -22,6 +22,7 @@
                                # No style was explicitly set
                                style = wx.DEFAULT_FRAME_STYLE  
                kwargs["style"] = style
+               self._objectRegistry = {}
                super(dFormMixin, self).__init__(preClass, parent, properties, 
*args, **kwargs)
                
 
@@ -338,6 +339,23 @@
        def sendToBack(self):
                """Places this window behind all others."""
                self.Lower()
+       
+       
+       def registerObject(self, obj):
+               """Stores a reference to the passed object using the RegID key
+               property of the object for later retrieval. You may reference 
the 
+               object as if it were a child object of this form; i.e., by 
using simple
+               dot notation, with the RegID as the 'name' of the object.       
        
+               """
+               if hasattr(obj, "RegID"):
+                       id = obj.RegID
+                       if self._objectRegistry.has_key(id):
+                               raise KeyError, _("Duplicate RegID '%s' found") 
% id
+                       self._objectRegistry[id] = obj
+               if self.__dict__.has_key(id):
+                       dabo.errorLog.write(_("RegID '%s' conflicts with 
existing name") % id)
+               else:
+                       self.__dict__[id] = obj
                
                
        def _appendToMenu(self, menu, caption, function, bitmap=wx.NullBitmap, 
menuId=-1):

Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py     2005-09-08 17:53:51 UTC (rev 1267)
+++ trunk/dabo/ui/uiwx/dPemMixin.py     2005-09-08 20:54:51 UTC (rev 1268)
@@ -155,6 +155,8 @@
                self._finito = False
                # Dict to hold key bindings
                self._keyBindings = {}
+               # Unique identifier attribute, if needed
+               self._registryID = ""
                self.beforeInit()
                
        
@@ -828,21 +830,21 @@
                self.delWindowStyleFlag(wx.DOUBLE_BORDER)
                self.delWindowStyleFlag(wx.STATIC_BORDER)
 
-               style = str(style)
+               style = str(style).lower().strip()
 
-               if style == "None":
+               if style == "none":
                        self.addWindowStyleFlag(wx.NO_BORDER)
-               elif style == "Simple":
+               elif style == "simple":
                        self.addWindowStyleFlag(wx.SIMPLE_BORDER)
-               elif style == "Sunken":
+               elif style == "sunken":
                        self.addWindowStyleFlag(wx.SUNKEN_BORDER)
-               elif style == "Raised":
+               elif style == "raised":
                        self.addWindowStyleFlag(wx.RAISED_BORDER)
-               elif style == "Double":
+               elif style == "double":
                        self.addWindowStyleFlag(wx.DOUBLE_BORDER)
-               elif style == "Static":
+               elif style == "static":
                        self.addWindowStyleFlag(wx.STATIC_BORDER)
-               elif style == "Default":
+               elif style == "default":
                        pass
                else:
                        raise ValueError, ("The only possible values are 
'None', "
@@ -1169,7 +1171,20 @@
                else:
                        self._properties["Position"] = val
 
+
+       def _getRegID(self):
+               return self._registryID
+       def _setRegID(self, val):
+               if self._registryID:
+                       # These should be immutable once set
+                       raise AttributeError, _("RegIDs cannot be changed once 
they are set")
+               self._registryID = val
+               try:
+                       self.Form.registerObject(self)
+               except:
+                       dabo.errorLog.write(_("Failed to register RegID '%s'") 
% val)
        
+       
        def _getSize(self): 
                return self.GetSize()
 
@@ -1388,6 +1403,9 @@
        Position = property(_getPosition, _setPosition, None, 
                        _("The (x,y) position of the object. (tuple)") )
 
+       RegID = property(_getRegID, _setRegID, None, 
+                       _("A unique identifier used for referencing by other 
objects. (str)") )
+
        Size = property(_getSize, _setSize, None,
                        _("The size of the object. (tuple)") )
 




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to