Changeset 4047

Show
Ignore:
Timestamp:
04/17/08 14:15:04 (3 months ago)
Author:
paul
Message:

Changed behavior of dControlItemMixin to show a blank value in the
control if the specified key doesn't exist, and the appdev didn't
set a key for None.

Files:

Legend:

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

    r3664 r4047  
    207207                if keysAreDict: 
    208208                    if not self.Keys.has_key(key): 
    209                         # self.Keys does not have the requested key. This could happen, for 
    210                         # example, if the bound field is a foreign key, and we are just adding 
    211                         # a new record. In my case, the iclientid field is ''. I want the list 
    212                         # to display "< None >" and map that to a value of None, so I set up a 
    213                         # Choice and a Key for that in my app code. 
    214      
    215                         # setting key to None here will result in an exception if there is no 
    216                         # key on None (user code must set their Keys to have a None key). But 
    217                         # the effect this has is that if the control is getting set to a value 
    218                         # that doesn't exist in self.Keys, we'll set the list to select the  
    219                         # item that is matched to None, if available. Else, it's a runtime 
    220                         # exception. 
     209                        # If the appdev set up a key for None, use it. 
    221210                        key = None 
    222                     self.setSelection(self.Keys[key]) 
     211                    try: 
     212                        self.setSelection(self.Keys[key]) 
     213                    except KeyError: 
     214                        # The specified key isn't found, and there's no None key. We  
     215                        # can't cope but wxPython can set a blank value: 
     216                        self._setSelection(-1) 
     217                         
    223218                else: 
    224219                    # we are using a tuple/list of keys. Find its position