author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 09 Aug 2017 14:11:20 +0300 | |
changeset 1723 | e0cefb1d5206 |
parent 1694 | acb767d6ac85 |
child 1726 | d51af006fa6b |
permissions | -rw-r--r-- |
814 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
3 |
# 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:
1487
diff
changeset
|
4 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 5 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 7 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
8 |
# See COPYING file for copyrights details. |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
10 |
# 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:
1487
diff
changeset
|
11 |
# 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:
1487
diff
changeset
|
12 |
# 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:
1487
diff
changeset
|
13 |
# of the License, or (at your option) any later version. |
814 | 14 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
15 |
# 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:
1487
diff
changeset
|
16 |
# 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:
1487
diff
changeset
|
17 |
# 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:
1487
diff
changeset
|
18 |
# GNU General Public License for more details. |
814 | 19 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
20 |
# 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:
1487
diff
changeset
|
21 |
# 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:
1487
diff
changeset
|
22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 23 |
|
24 |
import re |
|
25 |
from types import TupleType |
|
26 |
||
27 |
import wx |
|
28 |
||
29 |
from controls import CustomEditableListBox |
|
30 |
||
31 |
#------------------------------------------------------------------------------- |
|
32 |
# Helpers |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
||
35 |
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
|
36 |
||
37 |
#------------------------------------------------------------------------------- |
|
38 |
# Array Type Dialog |
|
39 |
#------------------------------------------------------------------------------- |
|
40 |
||
41 |
class ArrayTypeDialog(wx.Dialog): |
|
42 |
||
43 |
def __init__(self, parent, datatypes, infos): |
|
1694
acb767d6ac85
make adjustable size of ArrayTypeDialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
44 |
wx.Dialog.__init__(self, parent, title=_('Edit array type properties')) |
814 | 45 |
|
46 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
|
47 |
main_sizer.AddGrowableCol(0) |
|
48 |
main_sizer.AddGrowableRow(1) |
|
49 |
||
50 |
top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
51 |
main_sizer.AddSizer(top_sizer, border=20, |
|
52 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
53 |
||
54 |
basetype_label = wx.StaticText(self, label=_('Base Type:')) |
|
55 |
top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) |
|
56 |
||
57 |
self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) |
|
58 |
top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) |
|
59 |
||
60 |
self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), |
|
61 |
style=wx.gizmos.EL_ALLOW_NEW| |
|
62 |
wx.gizmos.EL_ALLOW_EDIT| |
|
63 |
wx.gizmos.EL_ALLOW_DELETE) |
|
64 |
for func in ["_OnLabelEndEdit", |
|
65 |
"_OnAddButton", |
|
66 |
"_OnDelButton", |
|
67 |
"_OnUpButton", |
|
68 |
"_OnDownButton"]: |
|
69 |
setattr(self.Dimensions, func, self.OnDimensionsChanged) |
|
70 |
main_sizer.AddSizer(self.Dimensions, border=20, |
|
71 |
flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
72 |
||
73 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
|
74 |
self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
|
75 |
main_sizer.AddSizer(button_sizer, border=20, |
|
76 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
77 |
||
78 |
self.SetSizer(main_sizer) |
|
79 |
||
80 |
for datatype in datatypes: |
|
81 |
self.BaseType.Append(datatype) |
|
82 |
||
83 |
if isinstance(infos, TupleType) and infos[0] == "array": |
|
84 |
self.BaseType.SetStringSelection(infos[1]) |
|
85 |
self.Dimensions.SetStrings(map(lambda x : "..".join(x), infos[2])) |
|
86 |
elif infos in datatypes: |
|
87 |
self.BaseType.SetStringSelection(infos) |
|
88 |
||
89 |
self.BaseType.SetFocus() |
|
1694
acb767d6ac85
make adjustable size of ArrayTypeDialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
90 |
self.Fit() |
814 | 91 |
|
92 |
def GetDimensions(self): |
|
93 |
dimensions_list = [] |
|
94 |
for dimensions in self.Dimensions.GetStrings(): |
|
95 |
result = DIMENSION_MODEL.match(dimensions) |
|
96 |
if result is None: |
|
97 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
|
98 |
message.ShowModal() |
|
99 |
message.Destroy() |
|
100 |
return None |
|
101 |
bounds = result.groups() |
|
102 |
if int(bounds[0]) >= int(bounds[1]): |
|
103 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
|
104 |
message.ShowModal() |
|
105 |
message.Destroy() |
|
106 |
return None |
|
107 |
dimensions_list.append(bounds) |
|
108 |
return dimensions_list |
|
109 |
||
110 |
def OnDimensionsChanged(self, event): |
|
111 |
wx.CallAfter(self.GetDimensions) |
|
112 |
event.Skip() |
|
113 |
||
114 |
def OnOK(self, event): |
|
115 |
if self.GetDimensions() is not None: |
|
116 |
self.EndModal(wx.ID_OK) |
|
117 |
||
118 |
def GetValue(self): |
|
119 |
return "array", self.BaseType.GetStringSelection(), self.GetDimensions() |