Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
authorlaurent
Tue, 20 Dec 2011 23:34:19 +0100
changeset 610 430d029beed6
parent 609 768820a948e2
child 611 9d24fa46523f
Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
DataTypeEditor.py
--- a/DataTypeEditor.py	Fri Dec 16 22:50:11 2011 +0100
+++ b/DataTypeEditor.py	Tue Dec 20 23:34:19 2011 +0100
@@ -363,7 +363,7 @@
         self.EnumeratedValues = CustomEditableListBox(id=ID_DATATYPEEDITORENUMERATEDVALUES, 
               name='EnumeratedValues', parent=self.EnumeratedPanel, label=_("Values:"), pos=wx.Point(0, 0),
               size=wx.Size(0, 0), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
-        self.EnumeratedValues.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEnumeratedValuesChanged)
+        self.EnumeratedValues.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEnumeratedValueEndEdit)
         for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
             setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged)
         
@@ -632,12 +632,13 @@
                 message.ShowModal()
                 message.Destroy()
             else:
-                wx.CallAfter(self.RefreshEnumeratedValues)
+                initial_selected = None
+                if self.EnumeratedInitialValue.GetStringSelection() == values[index]:
+                    initial_selected = text
+                wx.CallAfter(self.RefreshEnumeratedValues, initial_selected)
                 wx.CallAfter(self.RefreshTypeInfos)
                 event.Skip()
         else:
-            wx.CallAfter(self.RefreshEnumeratedValues)
-            wx.CallAfter(self.RefreshTypeInfos)
             event.Skip()
     
     def OnEnumeratedValuesChanged(self, event):
@@ -752,13 +753,14 @@
                 self.StructurePanel.Show()
             self.MainSizer.Layout()
 
-    def RefreshEnumeratedValues(self):
-        selected = self.EnumeratedInitialValue.GetStringSelection()
+    def RefreshEnumeratedValues(self, initial_selected=None):
+        if initial_selected is None:
+            initial_selected = self.EnumeratedInitialValue.GetStringSelection()
         self.EnumeratedInitialValue.Clear()
         self.EnumeratedInitialValue.Append("")
         for value in self.EnumeratedValues.GetStrings():
             self.EnumeratedInitialValue.Append(value)
-        self.EnumeratedInitialValue.SetStringSelection(selected)
+        self.EnumeratedInitialValue.SetStringSelection(initial_selected)
 
     def RefreshBoundsRange(self):
         range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())