author | Edouard Tisserant |
Thu, 22 Nov 2018 23:39:54 +0100 | |
changeset 2428 | e0f16317668e |
parent 1881 | 091005ec69c4 |
child 2439 | f0a040f1de1b |
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 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
24 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
25 |
from __future__ import absolute_import |
814 | 26 |
import re |
27 |
from types import TupleType |
|
28 |
||
29 |
import wx |
|
30 |
||
31 |
from controls import CustomEditableListBox |
|
32 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
33 |
# ------------------------------------------------------------------------------- |
814 | 34 |
# Helpers |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
35 |
# ------------------------------------------------------------------------------- |
814 | 36 |
|
37 |
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
|
38 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
39 |
# ------------------------------------------------------------------------------- |
814 | 40 |
# Array Type Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
41 |
# ------------------------------------------------------------------------------- |
814 | 42 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
43 |
|
814 | 44 |
class ArrayTypeDialog(wx.Dialog): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
45 |
|
814 | 46 |
def __init__(self, parent, datatypes, infos): |
1694
acb767d6ac85
make adjustable size of ArrayTypeDialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
47 |
wx.Dialog.__init__(self, parent, title=_('Edit array type properties')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
48 |
|
814 | 49 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
50 |
main_sizer.AddGrowableCol(0) |
|
51 |
main_sizer.AddGrowableRow(1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
52 |
|
814 | 53 |
top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
54 |
main_sizer.AddSizer(top_sizer, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
55 |
flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
56 |
|
814 | 57 |
basetype_label = wx.StaticText(self, label=_('Base Type:')) |
58 |
top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
59 |
|
814 | 60 |
self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) |
61 |
top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
62 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
63 |
self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
64 |
style=(wx.gizmos.EL_ALLOW_NEW | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
65 |
wx.gizmos.EL_ALLOW_EDIT | |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
66 |
wx.gizmos.EL_ALLOW_DELETE)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
67 |
for func in ["_OnLabelEndEdit", |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
68 |
"_OnAddButton", |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
69 |
"_OnDelButton", |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
70 |
"_OnUpButton", |
814 | 71 |
"_OnDownButton"]: |
72 |
setattr(self.Dimensions, func, self.OnDimensionsChanged) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
73 |
main_sizer.AddSizer(self.Dimensions, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
74 |
flag=wx.GROW | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
75 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
76 |
button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
814 | 77 |
self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
78 |
main_sizer.AddSizer(button_sizer, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
79 |
flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
80 |
|
814 | 81 |
self.SetSizer(main_sizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
82 |
|
814 | 83 |
for datatype in datatypes: |
84 |
self.BaseType.Append(datatype) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
85 |
|
814 | 86 |
if isinstance(infos, TupleType) and infos[0] == "array": |
87 |
self.BaseType.SetStringSelection(infos[1]) |
|
1833
2269739dd098
fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
88 |
self.Dimensions.SetStrings(map("..".join, infos[2])) |
814 | 89 |
elif infos in datatypes: |
90 |
self.BaseType.SetStringSelection(infos) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
91 |
|
814 | 92 |
self.BaseType.SetFocus() |
1694
acb767d6ac85
make adjustable size of ArrayTypeDialog
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
93 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
94 |
|
814 | 95 |
def GetDimensions(self): |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
96 |
message = None |
814 | 97 |
dimensions_list = [] |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
98 |
dimension_strings = self.Dimensions.GetStrings() |
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
99 |
if len(dimension_strings) == 0: |
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
100 |
message = _("Empty dimension isn't allowed.") |
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
101 |
|
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
102 |
for dimensions in dimension_strings: |
814 | 103 |
result = DIMENSION_MODEL.match(dimensions) |
104 |
if result is None: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
105 |
message = _("\"%s\" value isn't a valid array dimension!") % dimensions |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
106 |
break |
814 | 107 |
bounds = result.groups() |
108 |
if int(bounds[0]) >= int(bounds[1]): |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
109 |
message = _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.") % dimensions |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
110 |
break |
814 | 111 |
dimensions_list.append(bounds) |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
112 |
|
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
113 |
if message is not None: |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
114 |
dlg = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
1726
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
115 |
dlg.ShowModal() |
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
116 |
dlg.Destroy() |
d51af006fa6b
don't allow empty dimension for ARRAY types
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1694
diff
changeset
|
117 |
return None |
814 | 118 |
return dimensions_list |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
119 |
|
814 | 120 |
def OnDimensionsChanged(self, event): |
121 |
wx.CallAfter(self.GetDimensions) |
|
122 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
123 |
|
814 | 124 |
def OnOK(self, event): |
125 |
if self.GetDimensions() is not None: |
|
126 |
self.EndModal(wx.ID_OK) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1726
diff
changeset
|
127 |
|
814 | 128 |
def GetValue(self): |
129 |
return "array", self.BaseType.GetStringSelection(), self.GetDimensions() |