Changeset 4080

Show
Ignore:
Timestamp:
05/12/08 06:42:49 (2 months ago)
Author:
ed
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dFormMixin.py

    r4058 r4080  
    465465 
    466466    def saveSizeAndPosition(self): 
    467         """ Save the current size and position of this form. 
    468         """ 
     467        """ Save the current size and position of this form.""" 
    469468        if self.Application: 
    470469            if self.SaveRestorePosition and not self.TempForm: 
     
    473472                self.Application.setUserSetting("%s.windowstate" % name, state) 
    474473 
    475                 if state == 'Normal'
     474                if state == "Normal"
    476475                    # Don't save size and position when the window 
    477476                    # is minimized, maximized or fullscreen because 
    478477                    # windows doesn't supply correct value if the window 
    479                     # is in one of these staes. 
     478                    # is in one of these states. 
    480479                    pos = self.Position 
    481480                    size = self.Size 
    482  
    483481                    self.Application.setUserSetting("%s.left" % name, pos[0]) 
    484482                    self.Application.setUserSetting("%s.top" % name, pos[1]) 
  • trunk/dabo/ui/uiwx/dPemMixin.py

    r4072 r4080  
    16751675 
    16761676 
     1677    def _uniqueNameForParent(self, name, parent=None): 
     1678        """Takes a given name and ensures that it is unique among the existing child 
     1679        objects of the specified parent container. If no parent is specified, self.Parent 
     1680        is assumed. Returns either the original name, if it is unique, or the name with 
     1681        a numeric suffix that will make it unique. 
     1682        """ 
     1683        if parent is None: 
     1684            parent = self.Parent 
     1685        i = 0 
     1686        nameError = True 
     1687        candidate = name 
     1688        while nameError: 
     1689            if i: 
     1690                candidate = "%s%s" % (name, i) 
     1691            nameError = hasattr(parent, candidate) \ 
     1692                    and type(getattr(parent, candidate)) != wx._core._wxPyDeadObject \ 
     1693                    and getattr(parent, candidate) != self \ 
     1694                    and [win for win in parent.GetChildren() 
     1695                        if win != self and win.GetName() == candidate] 
     1696            i += 1 
     1697        return candidate 
     1698 
     1699 
    16771700    # The following 3 flag functions are used in some of the property 
    16781701    # get/set functions. 
     
    22492272                    # Dabo is setting the name implicitly, in which case we want to mangle 
    22502273                    # the name if necessary to make it unique (we don't want a NameError). 
    2251                     i = 0 
    2252                     while True: 
    2253                         if i == 0: 
    2254                             candidate = name 
    2255                         else: 
    2256                             candidate = "%s%s" % (name, i) 
    2257                         nameError = hasattr(parent, candidate) \ 
    2258                                 and type(getattr(parent, candidate)) != wx._core._wxPyDeadObject \ 
    2259                                 and getattr(parent, candidate) != self 
    2260                         if not nameError: 
    2261                             badNames = [win for win in parent.GetChildren() 
    2262                                     if win != self and win.GetName() == candidate] 
    2263                             if badNames: 
    2264                                 nameError = True 
    2265                         if nameError: 
    2266                             i += 1 
    2267                         else: 
    2268                             name = candidate 
    2269                             break 
     2274                    name = self._uniqueNameForParent(name) 
    22702275                else: 
    22712276                    # the user is explicitly setting the Name. If another object already