dabo Commit
Revision 4358
Date: 2008-08-04 13:07:58 -0700 (Mon, 04 Aug 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4358

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

Log:
I found the filt argument to setAll() to be hard to use: the expression
has to be written so that the leftmost word is a member of the current
child object being evaluated, and any names in the expression need to 
be local to dPemMixin, not the caller. So the simple case in the docstring
works, but how to evaluate if the child is an instance of my special 
subclass?

I couldn't do filt="'TxtFraction' in str(BaseClass)" because of the 
requirement that the left-most word must be an attribute or member of the
child being evaluated.

I couldn't do filt="BaseClass == TxtFraction" because TxtFraction
doesn't exist in dPemMixin's namespace.

So, I added a instancesOf argument, that accepts a single or sequence
of class(es), and added logic to setAll() to handle this. It shouldn't
have any effect on current uses of filt, but I feel this better satisfies
the common case of wanting to call setAll() only on instances of 
specific classes.

Perhaps an improvement to filt would be to add a placeholder, instead
of it being fixed to the left. Another improvement could be to pass in 
the locals and/or globals to setAll(), so the eval() takes place in 
the environment of the caller.


Diff:
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py     2008-08-04 18:39:01 UTC (rev 4357)
+++ trunk/dabo/ui/uiwx/dPemMixin.py     2008-08-04 20:07:58 UTC (rev 4358)
@@ -1072,7 +1072,7 @@
                return dabo.ui.getPositionInSizer(self)
        
        
-       def setAll(self, prop, val, recurse=True, filt=None):
+       def setAll(self, prop, val, recurse=True, filt=None, instancesOf=None):
                """Set all child object properties to the passed value.
 
                No bad effects will happen if the property doesn't apply to a 
child - only
@@ -1086,6 +1086,9 @@
                affect objects that are instances of dButton, you'd call:
 
                form.setAll("FontBold", True, filt="BaseClass == 
dabo.ui.dButton")
+
+               If the instancesOf sequence is passed, the property will only 
be set if
+               the child object is an instance of one of the passed classes.
                """
                if isinstance(self, dabo.ui.dGrid):
                        kids = self.Columns
@@ -1098,8 +1101,14 @@
                        return
                if isinstance(filt, basestring):
                        filt = (filt, )
+
+               if isinstance(instancesOf, basestring):
+                       instancesOf = (instancesOf,)
+               if instancesOf is None:
+                       instancesOf = tuple()
+               
                for kid in kids:
-                       ok = hasattr(kid, prop)
+                       ok = hasattr(kid, prop) and (not instancesOf or 
isinstance(kid, instancesOf))
                        if ok:
                                if filt:
                                        for ff in filt:




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

Reply via email to