Changeset 3055

Show
Ignore:
Timestamp:
04/12/2007 11:02:11 AM (2 years ago)
Author:
nate
Message:

Fixed the problem with the memory leak error if you set some properties in the constructor or initProperties. The problem was actually the TextLength? code I submitted a while back. I went back and updated some of the properties in dSearchBox and the dTextBoxMixin to fix the compliancy issue with initProperties. They should be working now.

I will see about getting unit tests for testing property setting in initProperties as soon as I can.

Made I slight change to the dSearchBox tests to reflect a change in behavior with the Menu property.

I overrode the Menu property in dSearchBox and turned it into a get-only property to keep it synced with List. What I still need to do is add a menu event so that users shouldn't have to deal with Menu at all. That will be for a further enhancement.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/NateBranch/dabo/ui/uiwx/dEditBox.py

    r3053 r3055  
    7474Its the Love Boat  
    7575""" 
    76          
     76        self.TextLength = 50 
    7777        self.ForceCase = "u" 
    7878 
  • branches/NateBranch/dabo/ui/uiwx/dSearchBox.py

    r3050 r3055  
    1717        self._cancelVisible = False 
    1818        self._searchVisible = True 
    19         self._outOfInit = False #Remedies a problem with the memory leak for the wx  
    20                                 #ShowCancelButton and ShowSearchButton properties 
    21                                 #when called in constructor or initProperties 
    2219         
    2320        preClass = wx.PreSearchCtrl 
     
    3027        self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.__onWxCancelBtnPressed) 
    3128     
    32     def _afterInit(self): 
    33         self._outOfInit = True 
    34         self.ShowCancelButton(self._cancelVisible) 
    35         self.ShowSearchButton(self._searchVisible) 
    36         tbm.dTextBoxMixin._afterInit(self) 
    3729     
    3830    #handle events 
     
    5345                menu.append(value) 
    5446         
    55         self.Menu = menu 
     47        self.SetMenu(menu) 
    5648     
    5749     
     
    6153     
    6254    def _setCancelButtonVisible(self, val): 
    63         if val: 
    64             self._cancelVisible = True 
     55        if self._constructed(): 
     56            if val: 
     57                self._cancelVisible = True 
     58            else: 
     59                self._cancelVisible = False 
     60         
     61            self.ShowCancelButton(self._cancelVisible) 
    6562        else: 
    66             self._cancelVisible = False 
    67          
    68         if self._outOfInit: 
    69             self.ShowCancelButton(self._cancelVisible) 
     63            self._properties["CancelButtonVisible"] = val 
    7064     
    7165     
     
    7670     
    7771    def _setList(self, val): 
    78         if val == None or val == [] or val == (): 
    79             val = [] 
    80             self.SetMenu(None) 
    81         elif type(val) in (list, tuple): 
    82             self._setupMenuFromList(val) 
    83             self._list = val 
     72        if self._constructed(): 
     73            if val == None or val == [] or val == (): 
     74                self._list = [] 
     75                self.SetMenu(None) 
     76            elif type(val) in (list, tuple): 
     77                self._setupMenuFromList(val) 
     78                self._list = val 
     79            else: 
     80                raise TypeError, "List must be either a tuple, list, or None" 
    8481        else: 
    85             raise TypeError, "List must be either a tuple, list, or None" 
     82            self._properties["List"] = val 
     83     
     84    def _getMenu(self): 
     85        return self.GetMenu() 
    8686     
    8787     
     
    9090     
    9191    def _setSearchButtonVisible(self, val): 
    92         if val: 
    93             self._searchVisible = True 
     92        if self._constructed(): 
     93            if val: 
     94                self._searchVisible = True 
     95            else: 
     96                self._searchVisible = False 
     97         
     98            self.ShowSearchButton(self._searchVisible) 
    9499        else: 
    95             self._searchVisible = False 
    96          
    97         if self._outOfInit: 
    98             self.ShowSearchButton(self._searchVisible) 
     100            self._properties["SearchButtonVisible"] = val 
    99101     
    100102     
     
    105107    List = property(_getList, _setList, None, 
    106108        _("A dropdown list that appears right below the search button (list)")) 
     109     
     110    Menu = property(_getMenu, None, None, 
     111        _("Menu used to display the controls.  Generated by List (dMenu)")) 
    107112     
    108113    SearchButtonVisible = property(_getSearchButtonVisible, _setSearchButtonVisible, None, 
     
    122127            self.CancelButtonVisible = True 
    123128            self.SearchButtonVisible = True 
     129            self.List = ("item 1", "item 2", "item 3") 
    124130         
    125131        def onValueChanged(self, evt): 
     
    143149        def afterInit(self): 
    144150            self.Value = 23.5 
    145             self.List = ['item 1', 'item 2'] 
     151            self.List = ['changed item 1', 'changed item 2'] 
    146152     
    147153    class BoolText(TestBase): 
  • branches/NateBranch/dabo/ui/uiwx/dTextBoxMixin.py

    r3053 r3055  
    232232     
    233233    def _setTextLength(self, val): 
    234         if val == None: 
    235             self._textLength = None 
    236         else: 
    237             val = int(val) 
    238             if val < 1: 
    239                 raise ValueError, 'TextLength must be a positve Integer' 
    240             self._textLength = val 
    241         self._checkTextLength() 
    242          
    243         self.unbindEvent(dEvents.KeyChar, self.__onKeyChar) 
    244         if self._forceCase or self._textLength: 
    245             self.bindEvent(dEvents.KeyChar, self.__onKeyChar) 
     234        if self._constructed(): 
     235            if val == None: 
     236                self._textLength = None 
     237            else: 
     238                val = int(val) 
     239                if val < 1: 
     240                    raise ValueError, 'TextLength must be a positve Integer' 
     241                self._textLength = val 
     242            self._checkTextLength() 
     243             
     244            self.unbindEvent(dEvents.KeyChar, self.__onKeyChar) 
     245            if self._forceCase or self._textLength: 
     246                self.bindEvent(dEvents.KeyChar, self.__onKeyChar) 
     247        else: 
     248            self._properties["TextLength"] = val 
    246249     
    247250     
     
    255258        # string value of the control: 
    256259        strVal = self.GetValue() 
    257  
     260         
    258261        if _value is None: 
    259262            if strVal == self.Application.NoneDisplay: 
     
    271274            else: 
    272275                dabo.ui.callAfter(self._checkForceCase) 
     276             
     277            if self._inTextLength: 
     278                # Value is changing internally. Don't update the oldval 
     279                # setting or change the type; just set the value. 
     280                self.SetValue(val) 
     281                return 
     282            else: 
     283                dabo.ui.callAfter(self._checkTextLength) 
    273284         
    274285            if val is None: 
     
    285296         
    286297            if type(_oldVal) != type(val) or _oldVal != val: 
    287                 self._afterValueChanged() 
     298                self._afterValueChanged()       
    288299        else: 
    289300            self._properties["Value"] = val 
    290          
    291         self._checkTextLength() 
     301 
    292302     
    293303     
  • branches/NateBranch/tests/unitTests/ui/UIwx/Test_dSearchBox.py

    r3050 r3055  
    8080        """List should accept lists of all lengths and properly input each element as a dMenuItem in Menu""" 
    8181        testList = [] 
    82         testMenu = dabo.ui.dMenu() 
    8382        for num in range(5): 
    8483            testList.append("item %s" % (num,)) 
     
    9493        typeList = ([], None, ()) 
    9594        for value in typeList: 
    96             self.testSearchBox.Menu = dabo.ui.dMenu() 
     95            self.testSearchBox.List = ["some", "items"] 
     96            self.assertNotEquals(self.testSearchBox.Menu, None) 
    9797            self.testSearchBox.List = value 
    9898            self.assertEquals(self.testSearchBox.List, [])