Changeset 4172
- Timestamp:
- 06/20/2008 11:10:55 AM (2 months ago)
- Files:
-
- trunk/dabo/ui/uiwx/__init__.py (modified) (1 diff)
- trunk/dabo/ui/uiwx/dPemMixin.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/ui/uiwx/__init__.py
r4164 r4172 1241 1241 1242 1242 1243 def getPositionInSizer(obj): 1244 """ Returns the current position of this control in its containing 1245 sizer. This is useful for when a control needs to be re-created in place. 1246 If the containing sizer is a box sizer, the integer position will be returned. 1247 If it is a grid sizer, a row,col tuple will be returned. If the object is 1248 not contained in a sizer, None will be returned. 1249 """ 1250 sz = obj.GetContainingSizer() 1251 if not sz: 1252 return None 1253 if isinstance(sz, wx.BoxSizer): 1254 chil = sz.GetChildren() 1255 for pos in range(len(chil)): 1256 # Yeah, normally we'd just iterate over the children, but 1257 # we want the position, so... 1258 szitem = chil[pos] 1259 if szitem.IsWindow(): 1260 if szitem.GetWindow() == obj: 1261 return pos 1262 # If we reached here, something's wrong! 1263 dabo.errorLog.write(_("Containing sizer did not match item %s") % obj.Name) 1264 return None 1265 elif isinstance(sz, wx.GridBagSizer): 1266 # Return a row,col tuple 1267 row, col = sz.GetItemPosition(obj) 1268 return (row, col) 1269 else: 1270 return None 1271 1272 1273 1243 1274 def fontMetricFromFont(txt, font): 1244 1275 if isinstance(font, dabo.ui.dFont): trunk/dabo/ui/uiwx/dPemMixin.py
r4159 r4172 1066 1066 1067 1067 def getPositionInSizer(self): 1068 """ Returns the current position of this control in its containing sizer. 1069 1070 This is useful for when a control needs to be re-created in place. If the 1071 containing sizer is a box sizer, the integer position will be returned. 1072 If it is a grid sizer, a row,col tuple will be returned. If the object is 1073 not contained in a sizer, None will be returned. 1074 """ 1075 sz = self.GetContainingSizer() 1076 if not sz: 1077 return None 1078 if isinstance(sz, wx.BoxSizer): 1079 chil = sz.GetChildren() 1080 for pos in range(len(chil)): 1081 # Yeah, normally we'd just iterate over the children, but 1082 # we want the position, so... 1083 szitem = chil[pos] 1084 if szitem.IsWindow(): 1085 if szitem.GetWindow() == self: 1086 return pos 1087 # If we reached here, something's wrong! 1088 dabo.errorLog.write(_("Containing sizer did not match item %s") % self.Name) 1089 return None 1090 elif isinstance(sz, wx.GridBagSizer): 1091 # Return a row,col tuple 1092 row, col = sz.GetItemPosition(self) 1093 return (row, col) 1094 else: 1095 return None 1068 """Convenience method to let you call this directly on the object.""" 1069 return dabo.ui.getPositionInSizer(self) 1096 1070 1097 1071
