author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 12 Sep 2017 14:18:50 +0300 | |
changeset 1798 | 7ec48bdc7a57 |
parent 1736 | 7e61baa047f0 |
child 1881 | 091005ec69c4 |
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 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
28 |
|
814 | 29 |
class CustomEditableListBox(wx.gizmos.EditableListBox): |
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
30 |
|
814 | 31 |
def __init__(self, *args, **kwargs): |
32 |
wx.gizmos.EditableListBox.__init__(self, *args, **kwargs) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
33 |
|
814 | 34 |
listbox = self.GetListCtrl() |
35 |
listbox.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
|
36 |
listbox.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnLabelBeginEdit) |
|
37 |
listbox.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnLabelEndEdit) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
38 |
|
814 | 39 |
for button, tooltip, call_function in [ |
40 |
(self.GetEditButton(), _("Edit item"), "_OnEditButton"), |
|
41 |
(self.GetNewButton(), _("New item"), "_OnNewButton"), |
|
42 |
(self.GetDelButton(), _("Delete item"), "_OnDelButton"), |
|
43 |
(self.GetUpButton(), _("Move up"), "_OnUpButton"), |
|
44 |
(self.GetDownButton(), _("Move down"), "_OnDownButton")]: |
|
45 |
button.SetToolTipString(tooltip) |
|
46 |
button.Bind(wx.EVT_BUTTON, self.GetButtonPressedFunction(call_function)) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
47 |
|
814 | 48 |
self.Editing = False |
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
49 |
|
814 | 50 |
def EnsureCurrentItemVisible(self): |
51 |
listctrl = self.GetListCtrl() |
|
52 |
listctrl.EnsureVisible(listctrl.GetFocusedItem()) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
53 |
|
814 | 54 |
def OnLabelBeginEdit(self, event): |
55 |
self.Editing = True |
|
56 |
func = getattr(self, "_OnLabelBeginEdit", None) |
|
57 |
if func is not None: |
|
58 |
func(event) |
|
59 |
else: |
|
60 |
event.Skip() |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
61 |
|
814 | 62 |
def OnLabelEndEdit(self, event): |
63 |
self.Editing = False |
|
64 |
func = getattr(self, "_OnLabelEndEdit", None) |
|
65 |
if func is not None: |
|
66 |
func(event) |
|
67 |
else: |
|
68 |
event.Skip() |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
69 |
|
814 | 70 |
def GetButtonPressedFunction(self, call_function): |
71 |
def OnButtonPressed(event): |
|
72 |
if wx.Platform != '__WXMSW__' or not self.Editing: |
|
73 |
func = getattr(self, call_function, None) |
|
74 |
if func is not None: |
|
75 |
func(event) |
|
76 |
wx.CallAfter(self.EnsureCurrentItemVisible) |
|
77 |
else: |
|
78 |
wx.CallAfter(self.EnsureCurrentItemVisible) |
|
79 |
event.Skip() |
|
80 |
return OnButtonPressed |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
81 |
|
814 | 82 |
def OnKeyDown(self, event): |
83 |
button = None |
|
84 |
keycode = event.GetKeyCode() |
|
85 |
if keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD): |
|
86 |
button = self.GetNewButton() |
|
87 |
elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): |
|
88 |
button = self.GetDelButton() |
|
89 |
elif keycode == wx.WXK_UP and event.ShiftDown(): |
|
90 |
button = self.GetUpButton() |
|
91 |
elif keycode == wx.WXK_DOWN and event.ShiftDown(): |
|
92 |
button = self.GetDownButton() |
|
93 |
elif keycode == wx.WXK_SPACE: |
|
94 |
button = self.GetEditButton() |
|
95 |
if button is not None and button.IsEnabled(): |
|
96 |
button.ProcessEvent(wx.CommandEvent(wx.EVT_BUTTON.typeId, button.GetId())) |
|
97 |
else: |
|
98 |
event.Skip() |