dabo Commit
Revision 4423
Date: 2008-08-18 18:37:59 -0700 (Mon, 18 Aug 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4423

Changed:
U   trunk/dabo/ui/uiwx/dControlItemMixin.py

Log:
Changed KeyValue in subclasses of dControlItemMixin to raise a ValueError if you
try to set the Value to a non-existent key.


Diff:
Modified: trunk/dabo/ui/uiwx/dControlItemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dControlItemMixin.py     2008-08-18 21:34:01 UTC (rev 
4422)
+++ trunk/dabo/ui/uiwx/dControlItemMixin.py     2008-08-19 01:37:59 UTC (rev 
4423)
@@ -101,6 +101,12 @@
                        sortFunction = self._sortFunction
                self._choices.sort(sortFunction)
 
+       def _resetChoices(self):
+               self.Clear()
+               self._setSelection(-1)
+               if self._sorted:
+                       self.sort()
+               self.AppendItems(self._choices)
                
        # Property get/set/del methods follow. Scroll to bottom to see the 
property
        # definitions themselves.
@@ -117,11 +123,8 @@
                        self.lockDisplay()
                        vm = self.ValueMode
                        oldVal = self.Value
-                       self.Clear()
                        self._choices = list(choices)
-                       if self._sorted:
-                               self.sort()
-                       self.AppendItems(self._choices)
+                       self._resetChoices()
                        if oldVal is not None:
                                # Try to get back to the same row:
                                try:
@@ -202,30 +205,27 @@
                        # Clear all current selections:
                        self.clearSelections()
                        
-                       validSelections = []
+                       invalidSelections = []
                        # Select items that match indices in value:
                        for key in value:
                                if isinstance(self.Keys, dict):
                                        try:
-                                               
validSelections.append(self.Keys[key])
+                                               
self.setSelection(self.Keys[key])
                                        except KeyError:
-                                               pass
+                                               invalidSelections.append(key)
                                else:
                                        try:
-                                               
validSelections.append(self.Keys.index(key))
+                                               
self.setSelection(self.Keys.index(key))
                                        except ValueError:
-                                               pass
+                                               invalidSelections.append(key)
 
-                       if validSelections:
-                               for selection in validSelections:
-                                       self.setSelection(selection)
-                       else:
-                               # No valid selections: tell wxPython not to 
select anything:
-                               self._setSelection(-1)
-                               chc = self.Choices
-                               self.Choices = []
-                               self.Choices = chc
+                       if invalidSelections:
+                               raise ValueError, _("Trying to set %s.Value to 
these invalid selections: %s") % (self.Name, invalidSelections)
 
+                       if len(value) == 0:
+                               # Value being set to an empty tuple, list, or 
dict, which means "nothing is selected":
+                               self._resetChoices()
+
                        self._afterValueChanged()
                else:
                        self._properties["KeyValue"] = value




_______________________________________________
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]

Reply via email to