dabo Commit
Revision 2322
Date: 2006-10-09 16:06:58 -0700 (Mon, 09 Oct 2006)
Author: paul

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

Log:
Moved the code in setSelection() in dRadioList and dControlItemMixin to new
function _setSelection(), because this is wrapper code for the backend ui
library, and only does half the job of actually setting the selection when
called by user code. Made new setSelection() function that is just a thin
wrapper around setting the PositionValue property.

Fixed a problem in dRadioList where the saving and restoring of the old value
when changing the Choices property: if there were previously no choices, and
the KeyValue was tried, an exception would be raised. Just skip the restore if
there weren't any prior values.





Diff:
Modified: trunk/dabo/ui/uiwx/dControlItemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dControlItemMixin.py     2006-10-09 22:12:01 UTC (rev 
2321)
+++ trunk/dabo/ui/uiwx/dControlItemMixin.py     2006-10-09 23:06:58 UTC (rev 
2322)
@@ -55,6 +55,12 @@
                
 
        def setSelection(self, index):
+               """Same as setting property PositionValue."""
+               self.PositionValue = index
+
+
+       def _setSelection(self, index):
+               """Backend UI wrapper."""
                if self.Count > index:
                        self.SetSelection(index)
                else:
@@ -228,7 +234,7 @@
                                if index is None:
                                        continue
                                try:
-                                       self.setSelection(index)
+                                       self._setSelection(index)
                                except: pass
                        self._afterValueChanged()
                else:

Modified: trunk/dabo/ui/uiwx/dRadioList.py
===================================================================
--- trunk/dabo/ui/uiwx/dRadioList.py    2006-10-09 22:12:01 UTC (rev 2321)
+++ trunk/dabo/ui/uiwx/dRadioList.py    2006-10-09 23:06:58 UTC (rev 2322)
@@ -63,7 +63,6 @@
                                break
                                        
                if canMove:
-                       #self.Parent.setSelection(positionValue)
                        self.Parent.PositionValue = positionValue
 
 
@@ -116,8 +115,8 @@
                except:
                        pass
        
-       
-       def setSelection(self, val):
+
+       def _setSelection(self, val):
                """Set the selected state of the buttons to match this
                control's Value.
                """
@@ -237,6 +236,7 @@
                if self._constructed():
                        self._checkSizer()
                        # Save the current values for possible re-setting 
afterwards.
+                       old_length = len(self.Choices)
                        sv = (self.StringValue, self.KeyValue, 
self.PositionValue)
                        [itm.release() for itm in self._items]
                        self._choices = choices
@@ -253,15 +253,20 @@
                                btn = _dRadioButton(self, Caption=itm, 
style=style)
                                self.Sizer.append(btn)
                                self._items.append(btn)
-                       # Try each saved value
-                       self.StringValue = sv[0]
-                       if self.StringValue != sv[0]:
-                               self.KeyValue = sv[1]
-                               if self.KeyValue != sv[1]:
-                                       self.PositionValue = sv[2]
-                                       if self.PositionValue != sv[2]:
-                                               # Bail!
-                                               self.PositionValue = 0
+
+                       if old_length:
+                               # Try each saved value
+                               self.StringValue = sv[0]
+                               if self.StringValue != sv[0]:
+                                       self.KeyValue = sv[1]
+                                       if self.KeyValue != sv[1]:
+                                               self.PositionValue = sv[2]
+                                               if self.PositionValue != sv[2]:
+                                                       # Bail!
+                                                       self.PositionValue = 0
+                       else:
+                               self.PositionValue = 0
+
                        try:
                                self.Parent.layout()
                        except:
@@ -289,7 +294,7 @@
        def _setPositionValue(self, val):
                if self._constructed():
                        self._selpos = val
-                       self.setSelection(val)
+                       self._setSelection(val)
                else:
                        self._properties["PositionValue"] = val
 
@@ -305,8 +310,7 @@
                if self._constructed():
                        try:
                                itm = [btn for btn in self._items if 
btn.Caption == val][0]
-                               self._selpos = self._items.index(itm)
-                               self.setSelection(self._selpos)
+                               self.PositionValue = itm
                        except IndexError:
                                if val is not None:
                                        # No such string.




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to