dabo Commit
Revision 4172
Date: 2008-06-20 11:10:55 -0700 (Fri, 20 Jun 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4172
Changed:
U trunk/dabo/ui/uiwx/__init__.py
U trunk/dabo/ui/uiwx/dPemMixin.py
Log:
Moved the 'getPositionInSizer()' method to the module level, allowing it to be
called for any object, even a non-Dabo item. Changed the version in dPemMixin
to call the module method.
Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2008-06-20 16:49:43 UTC (rev 4171)
+++ trunk/dabo/ui/uiwx/__init__.py 2008-06-20 18:10:55 UTC (rev 4172)
@@ -1240,6 +1240,37 @@
return parent, grd
+def getPositionInSizer(obj):
+ """ Returns the current position of this control in its containing
+ sizer. This is useful for when a control needs to be re-created in
place.
+ If the containing sizer is a box sizer, the integer position will be
returned.
+ If it is a grid sizer, a row,col tuple will be returned. If the object
is
+ not contained in a sizer, None will be returned.
+ """
+ sz = obj.GetContainingSizer()
+ if not sz:
+ return None
+ if isinstance(sz, wx.BoxSizer):
+ chil = sz.GetChildren()
+ for pos in range(len(chil)):
+ # Yeah, normally we'd just iterate over the children,
but
+ # we want the position, so...
+ szitem = chil[pos]
+ if szitem.IsWindow():
+ if szitem.GetWindow() == obj:
+ return pos
+ # If we reached here, something's wrong!
+ dabo.errorLog.write(_("Containing sizer did not match item %s")
% obj.Name)
+ return None
+ elif isinstance(sz, wx.GridBagSizer):
+ # Return a row,col tuple
+ row, col = sz.GetItemPosition(obj)
+ return (row, col)
+ else:
+ return None
+
+
+
def fontMetricFromFont(txt, font):
if isinstance(font, dabo.ui.dFont):
font = font._nativeFont
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2008-06-20 16:49:43 UTC (rev 4171)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2008-06-20 18:10:55 UTC (rev 4172)
@@ -1065,34 +1065,8 @@
def getPositionInSizer(self):
- """ Returns the current position of this control in its
containing sizer.
-
- This is useful for when a control needs to be re-created in
place. If the
- containing sizer is a box sizer, the integer position will be
returned.
- If it is a grid sizer, a row,col tuple will be returned. If the
object is
- not contained in a sizer, None will be returned.
- """
- sz = self.GetContainingSizer()
- if not sz:
- return None
- if isinstance(sz, wx.BoxSizer):
- chil = sz.GetChildren()
- for pos in range(len(chil)):
- # Yeah, normally we'd just iterate over the
children, but
- # we want the position, so...
- szitem = chil[pos]
- if szitem.IsWindow():
- if szitem.GetWindow() == self:
- return pos
- # If we reached here, something's wrong!
- dabo.errorLog.write(_("Containing sizer did not match
item %s") % self.Name)
- return None
- elif isinstance(sz, wx.GridBagSizer):
- # Return a row,col tuple
- row, col = sz.GetItemPosition(self)
- return (row, col)
- else:
- return None
+ """Convenience method to let you call this directly on the
object."""
+ return dabo.ui.getPositionInSizer(self)
def setAll(self, prop, val, recurse=True, filt=None):
_______________________________________________
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]