Changeset 4278

Show
Ignore:
Timestamp:
07/13/08 16:49:48 (1 month ago)
Author:
ed
Message:

Added the ability to specify additional properties, such as Dynamic*, in an .mnxml file.

Updated propertyHelperMixin to accommodate an optional context parameter for evaluating attProperty strings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/lib/propertyHelperMixin.py

    r4238 r4278  
    214214 
    215215             
    216     def setPropertiesFromAtts(self, propDict={}, ignoreExtra=True): 
     216    def setPropertiesFromAtts(self, propDict={}, ignoreExtra=True, context=None): 
    217217        """ Sets a group of properties on the object all at once. This 
    218218        is different from the regular setProperties() method because 
     
    220220        assumes that the value is always a string. It will convert 
    221221        the value to the correct type for the property, and then set 
    222         the property to that converted value. 
     222        the property to that converted value. If the value needs to be evaluated  
     223        in a specific namespace, pass that as the 'context' parameter. 
    223224        """ 
    224225        for prop, val in propDict.items(): 
     
    230231                else: 
    231232                    raise AttributeError, "'%s' is not a property." % prop 
    232             setattr(self, prop, val) 
     233            try: 
     234                valToSet = eval(val, context) 
     235            except NameError: 
     236                valToSet = val 
     237            setattr(self, prop, valToSet) 
    233238         
    234239     
  • trunk/dabo/ui/uiwx/__init__.py

    r4265 r4278  
    11611161            else: 
    11621162                itmatts = itm["attributes"] 
    1163                 cap = itmatts["Caption"] 
    1164                 hk = itmatts["HotKey"] 
    1165                 pic = itmatts["Picture"] 
    1166                 special = itmatts.get("special", None) 
     1163                cap = menu._extractKey(itmatts, "Caption") 
     1164                hk = menu._extractKey(itmatts, "HotKey") 
     1165                pic = menu._extractKey(itmatts, "Picture") 
     1166                special = menu._extractKey(itmatts, "special", None) 
    11671167                binding = previewFunc 
    1168                 fnc = "" 
    1169                 useFunc = ("Action" in itmatts) and (itmatts["Action"]) 
    1170                 if useFunc: 
    1171                     fnc = itmatts["Action"] 
     1168                fnc = menu._extractKey(itmatts, "Action", "") 
    11721169                if (binding is None) and fnc: 
    11731170                    try: 
     
    11751172                    except NameError: 
    11761173                        binding = fnc 
    1177                 help = itmatts["HelpText"] 
     1174                help = menu._extractKey(itmatts, "HelpText") 
    11781175                menuItem = menu.append(cap, OnHit=binding, help=help, 
    11791176                        picture=pic, special=special, HotKey=hk) 
     1177                if itmatts: 
     1178                    menuItem.setPropertiesFromAtts(itmatts,  
     1179                            context={"form": form, "app": dabo.dAppRef}) 
    11801180 
    11811181    try: