diff -r 1334238d4863 -r c32c169b8f63 controls/CustomEditableListBox.py --- 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):