dabo Commit
Revision 4080
Date: 2008-05-12 06:42:49 -0700 (Mon, 12 May 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4080
Changed:
U trunk/dabo/ui/uiwx/dFormMixin.py
U trunk/dabo/ui/uiwx/dPemMixin.py
Log:
Refactored the code that determines a unique name among siblings, so that it
can be called independently.
Corrected a typo in a docstring in dFormMixin.
Diff:
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2008-05-12 13:39:42 UTC (rev 4079)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2008-05-12 13:42:49 UTC (rev 4080)
@@ -464,22 +464,20 @@
def saveSizeAndPosition(self):
- """ Save the current size and position of this form.
- """
+ """ Save the current size and position of this form."""
if self.Application:
if self.SaveRestorePosition and not self.TempForm:
name = self.getAbsoluteName()
state = self.WindowState
self.Application.setUserSetting("%s.windowstate" % name, state)
- if state == 'Normal':
+ if state == "Normal":
# Don't save size and position when the
window
# is minimized, maximized or fullscreen
because
# windows doesn't supply correct value
if the window
- # is in one of these staes.
+ # is in one of these states.
pos = self.Position
size = self.Size
-
self.Application.setUserSetting("%s.left" % name, pos[0])
self.Application.setUserSetting("%s.top" % name, pos[1])
self.Application.setUserSetting("%s.width" % name, size[0])
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2008-05-12 13:39:42 UTC (rev 4079)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2008-05-12 13:42:49 UTC (rev 4080)
@@ -1674,6 +1674,29 @@
self.raiseEvent(dEvents.FontPropertiesChanged)
+ def _uniqueNameForParent(self, name, parent=None):
+ """Takes a given name and ensures that it is unique among the
existing child
+ objects of the specified parent container. If no parent is
specified, self.Parent
+ is assumed. Returns either the original name, if it is unique,
or the name with
+ a numeric suffix that will make it unique.
+ """
+ if parent is None:
+ parent = self.Parent
+ i = 0
+ nameError = True
+ candidate = name
+ while nameError:
+ if i:
+ candidate = "%s%s" % (name, i)
+ nameError = hasattr(parent, candidate) \
+ and type(getattr(parent, candidate)) !=
wx._core._wxPyDeadObject \
+ and getattr(parent, candidate) != self \
+ and [win for win in parent.GetChildren()
+ if win != self and
win.GetName() == candidate]
+ i += 1
+ return candidate
+
+
# The following 3 flag functions are used in some of the property
# get/set functions.
def _hasWindowStyleFlag(self, flag):
@@ -2248,25 +2271,7 @@
if not _userExplicit:
# Dabo is setting the name implicitly,
in which case we want to mangle
# the name if necessary to make it
unique (we don't want a NameError).
- i = 0
- while True:
- if i == 0:
- candidate = name
- else:
- candidate = "%s%s" %
(name, i)
- nameError = hasattr(parent,
candidate) \
- and
type(getattr(parent, candidate)) != wx._core._wxPyDeadObject \
- and
getattr(parent, candidate) != self
- if not nameError:
- badNames = [win for win
in parent.GetChildren()
- if win
!= self and win.GetName() == candidate]
- if badNames:
- nameError = True
- if nameError:
- i += 1
- else:
- name = candidate
- break
+ name = self._uniqueNameForParent(name)
else:
# the user is explicitly setting the
Name. If another object already
# has the name, we must raise an
exception immediately.
_______________________________________________
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]