Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
authorlaurent
Thu, 02 Feb 2012 16:12:26 +0100
changeset 640 c32c169b8f63
parent 639 1334238d4863
child 641 e9295622ce9b
Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
DataTypeEditor.py
GraphicViewer.py
controls/CustomEditableListBox.py
dialogs/ArrayTypeDialog.py
--- a/DataTypeEditor.py	Thu Feb 02 01:08:57 2012 +0100
+++ b/DataTypeEditor.py	Thu Feb 02 16:12:26 2012 +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.OnEnumeratedValueEndEdit)
+        setattr(self.EnumeratedValues, "_OnLabelEndEdit", self.OnEnumeratedValueEndEdit)
         for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
             setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged)
         
@@ -394,8 +394,7 @@
         self.ArrayDimensions = CustomEditableListBox(id=ID_DATATYPEEDITORARRAYDIMENSIONS, 
               name='ArrayDimensions', parent=self.ArrayPanel, label=_("Dimensions:"), pos=wx.Point(0, 0),
               size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
-        self.ArrayDimensions.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnDimensionsChanged)
-        for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
+        for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
             setattr(self.EnumeratedValues, func, self.OnDimensionsChanged)
         
         self.staticText10 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT10,
--- a/GraphicViewer.py	Thu Feb 02 01:08:57 2012 +0100
+++ b/GraphicViewer.py	Thu Feb 02 16:12:26 2012 +0100
@@ -41,7 +41,7 @@
 HOUR = 60 * MINUTE
 
 RANGE_VALUES = [(str(25 * 2 ** i), 25 * 2 ** i) for i in xrange(6)]
-TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (10, 20, 30)] + \
+TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
                     [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
                     [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
 
@@ -114,9 +114,8 @@
         
         self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE,
               name='CanvasRange', parent=self.Editor, pos=wx.Point(0, 0),
-              size=wx.Size(100, 28), style=0)
+              size=wx.Size(100, 28), style=wx.CB_READONLY)
         self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
-        self.Bind(wx.EVT_TEXT_ENTER, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
         
         self.staticText2 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT2,
               label=_('Position:'), name='staticText2', parent=self.Editor,
--- a/controls/CustomEditableListBox.py	Thu Feb 02 01:08:57 2012 +0100
+++ b/controls/CustomEditableListBox.py	Thu Feb 02 16:12:26 2012 +0100
@@ -30,7 +30,10 @@
     def __init__(self, *args, **kwargs):
         wx.gizmos.EditableListBox.__init__(self, *args, **kwargs)
         
-        self.GetListCtrl().Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+        listbox = self.GetListCtrl()
+        listbox.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+        listbox.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnLabelBeginEdit)
+        listbox.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnLabelEndEdit)
         
         for button, tooltip, call_function in [(self.GetEditButton(), _("Edit item"), "_OnEditButton"),
                                                (self.GetNewButton(), _("New item"), "_OnNewButton"),
@@ -40,17 +43,38 @@
             button.SetToolTipString(tooltip)
             button.Bind(wx.EVT_BUTTON, self.GetButtonPressedFunction(call_function))
     
+        self.Editing = False
+    
     def EnsureCurrentItemVisible(self):
         listctrl = self.GetListCtrl()
         listctrl.EnsureVisible(listctrl.GetFocusedItem())
     
+    def OnLabelBeginEdit(self, event):
+        self.Editing = True
+        func = getattr(self, "_OnLabelBeginEdit", None)
+        if func is not None:
+            func(event)
+        else:
+            event.Skip()
+        
+    def OnLabelEndEdit(self, event):
+        self.Editing = False
+        func = getattr(self, "_OnLabelEndEdit", None)
+        if func is not None:
+            func(event)
+        else:
+            event.Skip()
+    
     def GetButtonPressedFunction(self, call_function):
         def OnButtonPressed(event):
-            func = getattr(self, call_function, None)
-            if func is not None:
-                wx.CallAfter(func, event)
-            wx.CallAfter(self.EnsureCurrentItemVisible)
-            event.Skip()
+            if wx.Platform != '__WXMSW__' or not self.Editing:
+                func = getattr(self, call_function, None)
+                if func is not None:
+                    func(event)
+                    wx.CallAfter(self.EnsureCurrentItemVisible)
+                else:
+                    wx.CallAfter(self.EnsureCurrentItemVisible)
+                    event.Skip()
         return OnButtonPressed
     
     def OnKeyDown(self, event):
--- a/dialogs/ArrayTypeDialog.py	Thu Feb 02 01:08:57 2012 +0100
+++ b/dialogs/ArrayTypeDialog.py	Thu Feb 02 16:12:26 2012 +0100
@@ -84,9 +84,7 @@
         self.Dimensions = CustomEditableListBox(id=ID_ARRAYTYPEDIALOGDIMENSIONS, 
               name='ArrayDimensions', parent=self, label=_("Dimensions:"), pos=wx.Point(0, 0),
               size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
-        list_ctrl = self.Dimensions.GetListCtrl()
-        list_ctrl.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnDimensionsChanged)
-        for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
+        for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
             setattr(self.Dimensions, func, self.OnDimensionsChanged)
         
         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)