28 class CustomEditableListBox(wx.gizmos.EditableListBox): |
28 class CustomEditableListBox(wx.gizmos.EditableListBox): |
29 |
29 |
30 def __init__(self, *args, **kwargs): |
30 def __init__(self, *args, **kwargs): |
31 wx.gizmos.EditableListBox.__init__(self, *args, **kwargs) |
31 wx.gizmos.EditableListBox.__init__(self, *args, **kwargs) |
32 |
32 |
33 self.GetListCtrl().Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
33 listbox = self.GetListCtrl() |
|
34 listbox.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
|
35 listbox.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnLabelBeginEdit) |
|
36 listbox.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnLabelEndEdit) |
34 |
37 |
35 for button, tooltip, call_function in [(self.GetEditButton(), _("Edit item"), "_OnEditButton"), |
38 for button, tooltip, call_function in [(self.GetEditButton(), _("Edit item"), "_OnEditButton"), |
36 (self.GetNewButton(), _("New item"), "_OnNewButton"), |
39 (self.GetNewButton(), _("New item"), "_OnNewButton"), |
37 (self.GetDelButton(), _("Delete item"), "_OnDelButton"), |
40 (self.GetDelButton(), _("Delete item"), "_OnDelButton"), |
38 (self.GetUpButton(), _("Move up"), "_OnUpButton"), |
41 (self.GetUpButton(), _("Move up"), "_OnUpButton"), |
39 (self.GetDownButton(), _("Move down"), "_OnDownButton")]: |
42 (self.GetDownButton(), _("Move down"), "_OnDownButton")]: |
40 button.SetToolTipString(tooltip) |
43 button.SetToolTipString(tooltip) |
41 button.Bind(wx.EVT_BUTTON, self.GetButtonPressedFunction(call_function)) |
44 button.Bind(wx.EVT_BUTTON, self.GetButtonPressedFunction(call_function)) |
42 |
45 |
|
46 self.Editing = False |
|
47 |
43 def EnsureCurrentItemVisible(self): |
48 def EnsureCurrentItemVisible(self): |
44 listctrl = self.GetListCtrl() |
49 listctrl = self.GetListCtrl() |
45 listctrl.EnsureVisible(listctrl.GetFocusedItem()) |
50 listctrl.EnsureVisible(listctrl.GetFocusedItem()) |
46 |
51 |
|
52 def OnLabelBeginEdit(self, event): |
|
53 self.Editing = True |
|
54 func = getattr(self, "_OnLabelBeginEdit", None) |
|
55 if func is not None: |
|
56 func(event) |
|
57 else: |
|
58 event.Skip() |
|
59 |
|
60 def OnLabelEndEdit(self, event): |
|
61 self.Editing = False |
|
62 func = getattr(self, "_OnLabelEndEdit", None) |
|
63 if func is not None: |
|
64 func(event) |
|
65 else: |
|
66 event.Skip() |
|
67 |
47 def GetButtonPressedFunction(self, call_function): |
68 def GetButtonPressedFunction(self, call_function): |
48 def OnButtonPressed(event): |
69 def OnButtonPressed(event): |
49 func = getattr(self, call_function, None) |
70 if wx.Platform != '__WXMSW__' or not self.Editing: |
50 if func is not None: |
71 func = getattr(self, call_function, None) |
51 wx.CallAfter(func, event) |
72 if func is not None: |
52 wx.CallAfter(self.EnsureCurrentItemVisible) |
73 func(event) |
53 event.Skip() |
74 wx.CallAfter(self.EnsureCurrentItemVisible) |
|
75 else: |
|
76 wx.CallAfter(self.EnsureCurrentItemVisible) |
|
77 event.Skip() |
54 return OnButtonPressed |
78 return OnButtonPressed |
55 |
79 |
56 def OnKeyDown(self, event): |
80 def OnKeyDown(self, event): |
57 button = None |
81 button = None |
58 keycode = event.GetKeyCode() |
82 keycode = event.GetKeyCode() |