author | Laurent Bessard |
Fri, 27 Jul 2012 15:44:42 +0200 | |
changeset 731 | 4e30c1c0922d |
parent 714 | 131ea7f237b9 |
permissions | -rw-r--r-- |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
2 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
3 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
4 |
#based on the plcopen standard. |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
5 |
# |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
6 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
7 |
# |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
8 |
#See COPYING file for copyrights details. |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
9 |
# |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
10 |
#This library is free software; you can redistribute it and/or |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
11 |
#modify it under the terms of the GNU General Public |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
12 |
#License as published by the Free Software Foundation; either |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
14 |
# |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
15 |
#This library is distributed in the hope that it will be useful, |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
18 |
#General Public License for more details. |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
19 |
# |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
20 |
#You should have received a copy of the GNU General Public |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
21 |
#License along with this library; if not, write to the Free Software |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
23 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
24 |
import re |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
25 |
from types import TupleType |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
26 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
27 |
import wx |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
534
diff
changeset
|
28 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
534
diff
changeset
|
29 |
from controls import CustomEditableListBox |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
30 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
31 |
#------------------------------------------------------------------------------- |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
32 |
# Helpers |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
33 |
#------------------------------------------------------------------------------- |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
34 |
|
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
35 |
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
36 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
37 |
#------------------------------------------------------------------------------- |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
38 |
# Array Type Dialog |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
39 |
#------------------------------------------------------------------------------- |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
40 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
41 |
class ArrayTypeDialog(wx.Dialog): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
42 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
43 |
def __init__(self, parent, datatypes, infos): |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
44 |
wx.Dialog.__init__(self, parent, |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
45 |
size=wx.Size(500, 300), title=_('Edit array type properties')) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
46 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
47 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
48 |
main_sizer.AddGrowableCol(0) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
49 |
main_sizer.AddGrowableRow(1) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
50 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
51 |
top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
52 |
main_sizer.AddSizer(top_sizer, border=20, |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
53 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
54 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
55 |
basetype_label = wx.StaticText(self, label=_('Base Type:')) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
56 |
top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
57 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
58 |
self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
59 |
top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
60 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
61 |
self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
62 |
style=wx.gizmos.EL_ALLOW_NEW| |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
63 |
wx.gizmos.EL_ALLOW_EDIT| |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
64 |
wx.gizmos.EL_ALLOW_DELETE) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
65 |
for func in ["_OnLabelEndEdit", |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
66 |
"_OnAddButton", |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
67 |
"_OnDelButton", |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
68 |
"_OnUpButton", |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
69 |
"_OnDownButton"]: |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
70 |
setattr(self.Dimensions, func, self.OnDimensionsChanged) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
71 |
main_sizer.AddSizer(self.Dimensions, border=20, |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
72 |
flag=wx.GROW|wx.LEFT|wx.RIGHT) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
73 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
74 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
75 |
self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
76 |
main_sizer.AddSizer(button_sizer, border=20, |
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
77 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
78 |
|
714
131ea7f237b9
Replacing buttons with text by buttons with icons
Laurent Bessard
parents:
640
diff
changeset
|
79 |
self.SetSizer(main_sizer) |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
80 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
81 |
for datatype in datatypes: |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
82 |
self.BaseType.Append(datatype) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
83 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
84 |
if isinstance(infos, TupleType) and infos[0] == "array": |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
85 |
self.BaseType.SetStringSelection(infos[1]) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
86 |
self.Dimensions.SetStrings(map(lambda x : "..".join(x), infos[2])) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
87 |
elif infos in datatypes: |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
88 |
self.BaseType.SetStringSelection(infos) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
89 |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
534
diff
changeset
|
90 |
self.BaseType.SetFocus() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
534
diff
changeset
|
91 |
|
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
92 |
def GetDimensions(self): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
93 |
dimensions_list = [] |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
94 |
for dimensions in self.Dimensions.GetStrings(): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
95 |
result = DIMENSION_MODEL.match(dimensions) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
96 |
if result is None: |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
97 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
98 |
message.ShowModal() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
99 |
message.Destroy() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
100 |
return None |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
101 |
bounds = result.groups() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
102 |
if int(bounds[0]) >= int(bounds[1]): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
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) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
104 |
message.ShowModal() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
105 |
message.Destroy() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
106 |
return None |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
107 |
dimensions_list.append(bounds) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
108 |
return dimensions_list |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
109 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
110 |
def OnDimensionsChanged(self, event): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
111 |
wx.CallAfter(self.GetDimensions) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
112 |
event.Skip() |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
113 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
114 |
def OnOK(self, event): |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
115 |
if self.GetDimensions() is not None: |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
116 |
self.EndModal(wx.ID_OK) |
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
117 |
|
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
diff
changeset
|
118 |
def GetValue(self): |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
534
diff
changeset
|
119 |
return "array", self.BaseType.GetStringSelection(), self.GetDimensions() |