author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 07 Aug 2017 14:28:29 +0300 | |
changeset 1722 | 89824afffef2 |
parent 1571 | 486f94a8032c |
child 1735 | c02818d7e29f |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
26 |
import wx.gizmos |
|
27 |
||
28 |
class CustomEditableListBox(wx.gizmos.EditableListBox): |
|
29 |
||
30 |
def __init__(self, *args, **kwargs): |
|
31 |
wx.gizmos.EditableListBox.__init__(self, *args, **kwargs) |
|
32 |
||
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) |
|
37 |
||
38 |
for button, tooltip, call_function in [ |
|
39 |
(self.GetEditButton(), _("Edit item"), "_OnEditButton"), |
|
40 |
(self.GetNewButton(), _("New item"), "_OnNewButton"), |
|
41 |
(self.GetDelButton(), _("Delete item"), "_OnDelButton"), |
|
42 |
(self.GetUpButton(), _("Move up"), "_OnUpButton"), |
|
43 |
(self.GetDownButton(), _("Move down"), "_OnDownButton")]: |
|
44 |
button.SetToolTipString(tooltip) |
|
45 |
button.Bind(wx.EVT_BUTTON, self.GetButtonPressedFunction(call_function)) |
|
46 |
||
47 |
self.Editing = False |
|
48 |
||
49 |
def EnsureCurrentItemVisible(self): |
|
50 |
listctrl = self.GetListCtrl() |
|
51 |
listctrl.EnsureVisible(listctrl.GetFocusedItem()) |
|
52 |
||
53 |
def OnLabelBeginEdit(self, event): |
|
54 |
self.Editing = True |
|
55 |
func = getattr(self, "_OnLabelBeginEdit", None) |
|
56 |
if func is not None: |
|
57 |
func(event) |
|
58 |
else: |
|
59 |
event.Skip() |
|
60 |
||
61 |
def OnLabelEndEdit(self, event): |
|
62 |
self.Editing = False |
|
63 |
func = getattr(self, "_OnLabelEndEdit", None) |
|
64 |
if func is not None: |
|
65 |
func(event) |
|
66 |
else: |
|
67 |
event.Skip() |
|
68 |
||
69 |
def GetButtonPressedFunction(self, call_function): |
|
70 |
def OnButtonPressed(event): |
|
71 |
if wx.Platform != '__WXMSW__' or not self.Editing: |
|
72 |
func = getattr(self, call_function, None) |
|
73 |
if func is not None: |
|
74 |
func(event) |
|
75 |
wx.CallAfter(self.EnsureCurrentItemVisible) |
|
76 |
else: |
|
77 |
wx.CallAfter(self.EnsureCurrentItemVisible) |
|
78 |
event.Skip() |
|
79 |
return OnButtonPressed |
|
80 |
||
81 |
def OnKeyDown(self, event): |
|
82 |
button = None |
|
83 |
keycode = event.GetKeyCode() |
|
84 |
if keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD): |
|
85 |
button = self.GetNewButton() |
|
86 |
elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): |
|
87 |
button = self.GetDelButton() |
|
88 |
elif keycode == wx.WXK_UP and event.ShiftDown(): |
|
89 |
button = self.GetUpButton() |
|
90 |
elif keycode == wx.WXK_DOWN and event.ShiftDown(): |
|
91 |
button = self.GetDownButton() |
|
92 |
elif keycode == wx.WXK_SPACE: |
|
93 |
button = self.GetEditButton() |
|
94 |
if button is not None and button.IsEnabled(): |
|
95 |
button.ProcessEvent(wx.CommandEvent(wx.EVT_BUTTON.typeId, button.GetId())) |
|
96 |
else: |
|
97 |
event.Skip() |