author | lbessard |
Thu, 19 Jul 2007 15:04:41 +0200 | |
changeset 46 | 4379e98a30aa |
parent 45 | 42637f721b5b |
child 56 | 7187e1c00975 |
permissions | -rw-r--r-- |
27 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#Lesser General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from wxPython.wx import * |
|
26 |
from wxPython.grid import * |
|
27 |
import wx |
|
28 |
||
45 | 29 |
from graphics import * |
27 | 30 |
|
31 |
#------------------------------------------------------------------------------- |
|
32 |
# Create New Block Dialog |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
||
35 |
[wxID_BLOCKPROPERTIESDIALOG, wxID_BLOCKPROPERTIESDIALOGMAINPANEL, |
|
36 |
wxID_BLOCKPROPERTIESDIALOGNAME, wxID_BLOCKPROPERTIESDIALOGTYPETREE, |
|
37 |
wxID_BLOCKPROPERTIESDIALOGTYPEDESC, wxID_BLOCKPROPERTIESDIALOGINPUTS, |
|
38 |
wxID_BLOCKPROPERTIESDIALOGPREVIEW, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1, |
|
39 |
wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT3, |
|
40 |
wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, |
|
41 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
42 |
||
43 |
[CATEGORY, BLOCK] = range(2) |
|
44 |
||
45 |
class BlockPropertiesDialog(wx.Dialog): |
|
46 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
47 |
# generated method, don't edit |
|
48 |
||
49 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
50 |
||
51 |
def _init_sizers(self): |
|
52 |
# generated method, don't edit |
|
53 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
54 |
||
55 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
56 |
||
57 |
self.SetSizer(self.flexGridSizer1) |
|
58 |
||
59 |
def _init_ctrls(self, prnt): |
|
60 |
# generated method, don't edit |
|
61 |
wx.Dialog.__init__(self, id=wxID_BLOCKPROPERTIESDIALOG, |
|
62 |
name='BlockPropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
63 |
size=wx.Size(600, 360), style=wx.DEFAULT_DIALOG_STYLE, |
|
64 |
title='Block Properties') |
|
65 |
self.SetClientSize(wx.Size(600, 360)) |
|
66 |
||
67 |
self.MainPanel = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGMAINPANEL, |
|
68 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
69 |
size=wx.Size(600, 320), style=wx.TAB_TRAVERSAL) |
|
70 |
self.MainPanel.SetAutoLayout(True) |
|
71 |
||
72 |
self.staticbox1 = wx.StaticBox(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1, |
|
73 |
label='Type:', name='staticBox1', parent=self.MainPanel, |
|
74 |
pos=wx.Point(24, 24), size=wx.Size(245, 280), style=0) |
|
75 |
||
76 |
self.staticText2 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, |
|
77 |
label='Name:', name='staticText2', parent=self.MainPanel, |
|
78 |
pos=wx.Point(274, 24), size=wx.Size(70, 17), style=0) |
|
79 |
||
80 |
self.staticText3 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, |
|
81 |
label='Inputs:', name='staticText4', parent=self.MainPanel, |
|
82 |
pos=wx.Point(424, 24), size=wx.Size(70, 17), style=0) |
|
83 |
||
84 |
self.staticText4 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, |
|
85 |
label='Preview:', name='staticText4', parent=self.MainPanel, |
|
86 |
pos=wx.Point(274, 80), size=wx.Size(100, 17), style=0) |
|
87 |
||
88 |
self.TypeTree = wx.TreeCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPETREE, |
|
89 |
name='TypeTree', parent=self.MainPanel, pos=wx.Point(34, 44), |
|
90 |
size=wx.Size(225, 180), style=wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
91 |
EVT_TREE_SEL_CHANGED(self, wxID_BLOCKPROPERTIESDIALOGTYPETREE, self.OnTypeTreeItemSelected) |
|
92 |
||
93 |
self.TypeDesc = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPEDESC, |
|
94 |
name='TypeDesc', parent=self.MainPanel, pos=wx.Point(34, 230), |
|
95 |
size=wx.Size(225, 65), style=wx.TE_READONLY|wx.TE_MULTILINE) |
|
96 |
||
97 |
self.Name = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGNAME, value='', |
|
98 |
name='Name', parent=self.MainPanel, pos=wx.Point(274, 48), |
|
99 |
size=wx.Size(145, 24), style=0) |
|
100 |
EVT_TEXT(self, wxID_BLOCKPROPERTIESDIALOGNAME, self.OnNameChanged) |
|
101 |
||
102 |
self.Inputs = wx.SpinCtrl(id=wxID_BLOCKPROPERTIESDIALOGINPUTS, |
|
103 |
name='Inputs', parent=self.MainPanel, pos=wx.Point(424, 48), |
|
104 |
size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=2, max=20) |
|
105 |
EVT_SPINCTRL(self, wxID_BLOCKPROPERTIESDIALOGINPUTS, self.OnInputsChanged) |
|
106 |
||
107 |
self.Preview = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGPREVIEW, |
|
108 |
name='Preview', parent=self.MainPanel, pos=wx.Point(274, 104), |
|
109 |
size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
110 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 111 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 112 |
|
113 |
self._init_sizers() |
|
114 |
||
115 |
def __init__(self, parent): |
|
116 |
self._init_ctrls(parent) |
|
117 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
118 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
119 |
self.Name.SetValue("") |
|
120 |
self.Name.Enable(False) |
|
121 |
self.Inputs.Enable(False) |
|
122 |
self.Block = None |
|
123 |
self.MinBlockSize = None |
|
124 |
||
125 |
EVT_PAINT(self, self.OnPaint) |
|
126 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
127 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
128 |
def FindTreeItem(self, root, name, inputs = None): |
27 | 129 |
if root.IsOk(): |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
130 |
pydata = self.TypeTree.GetPyData(root) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
131 |
if inputs and "inputs" in pydata: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
132 |
same_inputs = pydata["inputs"] == inputs |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
133 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
134 |
same_inputs = True |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
135 |
if self.TypeTree.GetItemText(root) == name and same_inputs: |
27 | 136 |
return root |
137 |
else: |
|
138 |
item, root_cookie = self.TypeTree.GetFirstChild(root) |
|
139 |
while item.IsOk(): |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
140 |
result = self.FindTreeItem(item, name, inputs) |
27 | 141 |
if result: |
142 |
return result |
|
143 |
item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie) |
|
144 |
return None |
|
145 |
||
146 |
def OnOK(self, event): |
|
147 |
error = [] |
|
148 |
selected = self.TypeTree.GetSelection() |
|
149 |
if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem(): |
|
150 |
message = wxMessageDialog(self, "Form isn't complete. Valid block type must be selected!", "Error", wxOK|wxICON_ERROR) |
|
151 |
message.ShowModal() |
|
152 |
message.Destroy() |
|
153 |
elif self.Name.IsEnabled() and self.Name.GetValue() == "": |
|
154 |
message = wxMessageDialog(self, "Form isn't complete. Name must be filled!", "Error", wxOK|wxICON_ERROR) |
|
155 |
message.ShowModal() |
|
156 |
message.Destroy() |
|
157 |
else: |
|
158 |
self.EndModal(wxID_OK) |
|
159 |
||
160 |
def SetBlockList(self, blocktypes): |
|
161 |
root = self.TypeTree.AddRoot("") |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
162 |
self.TypeTree.SetPyData(root, {"type" : CATEGORY}) |
27 | 163 |
for category in blocktypes: |
164 |
category_item = self.TypeTree.AppendItem(root, category["name"]) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
165 |
self.TypeTree.SetPyData(category_item, {"type" : CATEGORY}) |
27 | 166 |
for blocktype in category["list"]: |
167 |
blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"]) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
168 |
self.TypeTree.SetPyData(blocktype_item, {"type" : BLOCK, "inputs" : tuple([type for name, type, modifier in blocktype["inputs"]])}) |
27 | 169 |
|
170 |
def SetMinBlockSize(self, size): |
|
171 |
self.MinBlockSize = size |
|
172 |
||
173 |
def SetValues(self, values): |
|
174 |
for name, value in values.items(): |
|
175 |
if name == "type": |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
176 |
inputs = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
177 |
if "inputs" in values: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
178 |
inputs = values["inputs"] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
179 |
item = self.FindTreeItem(self.TypeTree.GetRootItem(), value, inputs) |
27 | 180 |
if item: |
181 |
self.TypeTree.SelectItem(item) |
|
182 |
elif name == "name": |
|
183 |
self.Name.SetValue(value) |
|
184 |
elif name == "extension": |
|
185 |
self.Inputs.SetValue(value) |
|
186 |
self.RefreshPreview() |
|
187 |
||
188 |
def GetValues(self): |
|
189 |
values = {} |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
190 |
item = self.TypeTree.GetSelection() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
191 |
values["type"] = self.TypeTree.GetItemText(item) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
192 |
values["inputs"] = self.TypeTree.GetPyData(item)["inputs"] |
27 | 193 |
if self.Name.GetValue() != "": |
194 |
values["name"] = self.Name.GetValue() |
|
195 |
values["width"], values["height"] = self.Block.GetSize() |
|
196 |
values["extension"] = self.Inputs.GetValue() |
|
197 |
return values |
|
198 |
||
199 |
def OnTypeTreeItemSelected(self, event): |
|
200 |
self.Name.SetValue("") |
|
201 |
selected = event.GetItem() |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
202 |
pydata = self.TypeTree.GetPyData(selected) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
203 |
if pydata["type"] != CATEGORY: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
204 |
blocktype = GetBlockType(self.TypeTree.GetItemText(selected), pydata["inputs"]) |
27 | 205 |
if blocktype: |
206 |
self.Inputs.SetValue(len(blocktype["inputs"])) |
|
207 |
self.Inputs.Enable(blocktype["extensible"]) |
|
208 |
self.Name.Enable(blocktype["type"] != "function") |
|
209 |
self.TypeDesc.SetValue(blocktype["comment"]) |
|
210 |
wxCallAfter(self.RefreshPreview) |
|
211 |
else: |
|
212 |
self.Name.Enable(False) |
|
213 |
self.Inputs.Enable(False) |
|
214 |
self.Inputs.SetValue(2) |
|
215 |
self.TypeDesc.SetValue("") |
|
216 |
wxCallAfter(self.ErasePreview) |
|
217 |
else: |
|
218 |
self.Name.Enable(False) |
|
219 |
self.Inputs.Enable(False) |
|
220 |
self.Inputs.SetValue(2) |
|
221 |
self.TypeDesc.SetValue("") |
|
222 |
wxCallAfter(self.ErasePreview) |
|
223 |
event.Skip() |
|
224 |
||
225 |
def OnNameChanged(self, event): |
|
226 |
if self.Name.IsEnabled(): |
|
227 |
self.RefreshPreview() |
|
228 |
event.Skip() |
|
229 |
||
230 |
def OnInputsChanged(self, event): |
|
231 |
if self.Inputs.IsEnabled(): |
|
232 |
self.RefreshPreview() |
|
233 |
event.Skip() |
|
234 |
||
235 |
def ErasePreview(self): |
|
236 |
dc = wxClientDC(self.Preview) |
|
237 |
dc.Clear() |
|
238 |
self.Block = None |
|
239 |
||
240 |
def RefreshPreview(self): |
|
241 |
dc = wxClientDC(self.Preview) |
|
242 |
dc.Clear() |
|
243 |
item = self.TypeTree.GetSelection() |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
244 |
pydata = self.TypeTree.GetPyData(item) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
245 |
if pydata["type"] == CATEGORY: |
27 | 246 |
self.Block = None |
247 |
else: |
|
248 |
blocktype = self.TypeTree.GetItemText(item) |
|
249 |
if blocktype: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
250 |
self.Block = FBD_Block(self.Preview, blocktype, self.Name.GetValue(), extension = self.Inputs.GetValue(), inputs = pydata["inputs"]) |
27 | 251 |
width, height = self.MinBlockSize |
252 |
min_width, min_height = self.Block.GetMinSize() |
|
253 |
width, height = max(min_width, width), max(min_height, height) |
|
254 |
self.Block.SetSize(width, height) |
|
255 |
clientsize = self.Preview.GetClientSize() |
|
256 |
x = (clientsize.width - width) / 2 |
|
257 |
y = (clientsize.height - height) / 2 |
|
258 |
self.Block.SetPosition(x, y) |
|
259 |
self.Block.Draw(dc) |
|
260 |
else: |
|
261 |
self.Block = None |
|
262 |
||
263 |
def OnPaint(self, event): |
|
264 |
if self.Block: |
|
265 |
self.RefreshPreview() |
|
266 |
||
267 |
||
268 |
#------------------------------------------------------------------------------- |
|
269 |
# Create New Variable Dialog |
|
270 |
#------------------------------------------------------------------------------- |
|
271 |
||
272 |
[wxID_VARIABLEPROPERTIESDIALOG, wxID_VARIABLEPROPERTIESDIALOGMAINPANEL, |
|
273 |
wxID_VARIABLEPROPERTIESDIALOGNAME, wxID_VARIABLEPROPERTIESDIALOGCLASS, |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
274 |
wxID_VARIABLEPROPERTIESDIALOGPREVIEW, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
275 |
wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
276 |
wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
277 |
] = [wx.NewId() for _init_ctrls in range(10)] |
27 | 278 |
|
279 |
class VariablePropertiesDialog(wx.Dialog): |
|
280 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
281 |
# generated method, don't edit |
|
282 |
||
283 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
284 |
||
285 |
def _init_sizers(self): |
|
286 |
# generated method, don't edit |
|
287 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
288 |
||
289 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
290 |
||
291 |
self.SetSizer(self.flexGridSizer1) |
|
292 |
||
293 |
def _init_ctrls(self, prnt): |
|
294 |
# generated method, don't edit |
|
295 |
wx.Dialog.__init__(self, id=wxID_VARIABLEPROPERTIESDIALOG, |
|
296 |
name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
297 |
size=wx.Size(400, 380), style=wx.DEFAULT_DIALOG_STYLE, |
27 | 298 |
title='Variable Properties') |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
299 |
self.SetClientSize(wx.Size(400, 380)) |
27 | 300 |
|
301 |
self.MainPanel = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGMAINPANEL, |
|
302 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
303 |
size=wx.Size(400, 280), style=wx.TAB_TRAVERSAL) |
|
304 |
self.MainPanel.SetAutoLayout(True) |
|
305 |
||
306 |
self.staticText1 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, |
|
307 |
label='Class:', name='staticText1', parent=self.MainPanel, |
|
308 |
pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) |
|
309 |
||
310 |
self.staticText2 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
311 |
label='Expression:', name='staticText2', parent=self.MainPanel, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
312 |
pos=wx.Point(24, 90), size=wx.Size(100, 17), style=0) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
313 |
|
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
314 |
self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
315 |
label='Name:', name='staticText3', parent=self.MainPanel, |
27 | 316 |
pos=wx.Point(204, 24), size=wx.Size(70, 17), style=0) |
317 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
318 |
self.staticText4 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
319 |
label='Preview:', name='staticText4', parent=self.MainPanel, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
320 |
pos=wx.Point(24, 144), size=wx.Size(100, 17), style=0) |
27 | 321 |
|
322 |
self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS, |
|
323 |
name='Class', parent=self.MainPanel, pos=wx.Point(24, 48), |
|
324 |
size=wx.Size(145, 24), style=0) |
|
325 |
EVT_CHOICE(self, wxID_VARIABLEPROPERTIESDIALOGCLASS, self.OnClassChanged) |
|
326 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
327 |
self.Name = wx.ListBox(id=wxID_VARIABLEPROPERTIESDIALOGNAME, |
27 | 328 |
name='Name', parent=self.MainPanel, pos=wx.Point(204, 48), |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
329 |
size=wx.Size(145, 90), style=wx.LB_SINGLE) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
330 |
EVT_LISTBOX(self, wxID_VARIABLEPROPERTIESDIALOGNAME, self.OnNameChanged) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
331 |
|
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
332 |
self.Expression = wx.TextCtrl(id=wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
333 |
name='Expression', parent=self.MainPanel, pos=wx.Point(24, 114), |
27 | 334 |
size=wx.Size(145, 24), style=0) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
335 |
EVT_TEXT(self, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, self.OnExpressionChanged) |
27 | 336 |
|
337 |
self.Preview = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGPREVIEW, |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
338 |
name='Preview', parent=self.MainPanel, pos=wx.Point(24, 170), |
27 | 339 |
size=wx.Size(350, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
340 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 341 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 342 |
|
343 |
self._init_sizers() |
|
344 |
||
345 |
def __init__(self, parent): |
|
346 |
self._init_ctrls(parent) |
|
347 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
348 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
349 |
self.Variable = None |
|
350 |
self.VarList = [] |
|
351 |
self.MinVariableSize = None |
|
352 |
self.RefreshNameList() |
|
353 |
||
354 |
for choice in ["Input", "Output", "InOut"]: |
|
355 |
self.Class.Append(choice) |
|
356 |
self.Class.SetStringSelection("Input") |
|
357 |
||
358 |
EVT_PAINT(self, self.OnPaint) |
|
359 |
||
360 |
def RefreshNameList(self): |
|
361 |
selected = self.Name.GetStringSelection() |
|
362 |
self.Name.Clear() |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
363 |
self.Name.Append("") |
27 | 364 |
for name, var_type, value_type in self.VarList: |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
365 |
if var_type in ["Local","Temp","Global","External"]: |
27 | 366 |
self.Name.Append(name) |
367 |
elif var_type == "Input" and self.Class.GetStringSelection() == "Input": |
|
368 |
self.Name.Append(name) |
|
369 |
elif var_type == "Output" and self.Class.GetStringSelection() == "Output": |
|
370 |
self.Name.Append(name) |
|
371 |
elif var_type == "InOut" and self.Class.GetStringSelection() == "InOut": |
|
372 |
self.Name.Append(name) |
|
373 |
if self.Name.FindString(selected) != wxNOT_FOUND: |
|
374 |
self.Name.SetStringSelection(selected) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
375 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
376 |
self.Name.SetStringSelection("") |
27 | 377 |
self.Name.Enable(self.Name.GetCount() > 0) |
378 |
||
379 |
def SetMinVariableSize(self, size): |
|
380 |
self.MinVariableSize = size |
|
381 |
||
382 |
def SetVariables(self, vars): |
|
383 |
self.VarList = vars |
|
384 |
self.RefreshNameList() |
|
385 |
||
386 |
def SetValues(self, values): |
|
387 |
for name, value in values.items(): |
|
388 |
if name == "type": |
|
389 |
if value == INPUT: |
|
390 |
self.Class.SetStringSelection("Input") |
|
391 |
if value == OUTPUT: |
|
392 |
self.Class.SetStringSelection("Output") |
|
393 |
if value == INOUT: |
|
394 |
self.Class.SetStringSelection("InOut") |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
395 |
elif name == "name" and value != "": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
396 |
if self.Name.FindString(value) != wxNOT_FOUND: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
397 |
self.Name.SetStringSelection(value) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
398 |
self.Expression.Enable(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
399 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
400 |
self.Expression.SetValue(value) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
401 |
self.Name.Enable(False) |
27 | 402 |
self.RefreshPreview() |
403 |
||
404 |
def GetValues(self): |
|
405 |
values = {} |
|
406 |
classtype = self.Class.GetStringSelection() |
|
407 |
if classtype == "Input": |
|
408 |
values["type"] = INPUT |
|
409 |
elif classtype == "Output": |
|
410 |
values["type"] = OUTPUT |
|
411 |
elif classtype == "InOut": |
|
412 |
values["type"] = INOUT |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
413 |
expression = self.Expression.GetValue() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
414 |
if self.Expression.IsEnabled() and expression != "": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
415 |
values["name"] = expression |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
416 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
417 |
values["name"] = self.Name.GetStringSelection() |
27 | 418 |
values["value_type"] = "" |
419 |
for var_name, var_type, value_type in self.VarList: |
|
420 |
if var_name == values["name"]: |
|
421 |
values["value_type"] = value_type |
|
422 |
values["width"], values["height"] = self.Variable.GetSize() |
|
423 |
return values |
|
424 |
||
425 |
def OnClassChanged(self, event): |
|
426 |
self.RefreshNameList() |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
427 |
if self.Class.GetStringSelection() == "Input": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
428 |
self.Expression.Enable(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
429 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
430 |
self.Expression.Enable(False) |
27 | 431 |
self.RefreshPreview() |
432 |
event.Skip() |
|
433 |
||
434 |
def OnNameChanged(self, event): |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
435 |
if self.Name.GetStringSelection() != "": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
436 |
self.Expression.Enable(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
437 |
elif self.Class.GetStringSelection() == "Input": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
438 |
self.Expression.Enable(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
439 |
self.RefreshPreview() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
440 |
event.Skip() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
441 |
|
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
442 |
def OnExpressionChanged(self, event): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
443 |
if self.Expression.GetValue() != "": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
444 |
self.Name.Enable(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
445 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
446 |
self.Name.Enable(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
447 |
self.RefreshPreview() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
448 |
event.Skip() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
449 |
|
27 | 450 |
def RefreshPreview(self): |
451 |
dc = wxClientDC(self.Preview) |
|
452 |
dc.Clear() |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
453 |
expression = self.Expression.GetValue() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
454 |
if self.Expression.IsEnabled() and expression != "": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
455 |
name = expression |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
456 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
457 |
name = self.Name.GetStringSelection() |
27 | 458 |
type = "" |
459 |
for var_name, var_type, value_type in self.VarList: |
|
460 |
if var_name == name: |
|
461 |
type = value_type |
|
462 |
classtype = self.Class.GetStringSelection() |
|
463 |
if classtype == "Input": |
|
464 |
self.Variable = FBD_Variable(self.Preview, INPUT, name, type) |
|
465 |
elif classtype == "Output": |
|
466 |
self.Variable = FBD_Variable(self.Preview, OUTPUT, name, type) |
|
467 |
elif classtype == "InOut": |
|
468 |
self.Variable = FBD_Variable(self.Preview, INOUT, name, type) |
|
469 |
width, height = self.MinVariableSize |
|
470 |
min_width, min_height = self.Variable.GetMinSize() |
|
471 |
width, height = max(min_width, width), max(min_height, height) |
|
472 |
self.Variable.SetSize(width, height) |
|
473 |
clientsize = self.Preview.GetClientSize() |
|
474 |
x = (clientsize.width - width) / 2 |
|
475 |
y = (clientsize.height - height) / 2 |
|
476 |
self.Variable.SetPosition(x, y) |
|
477 |
self.Variable.Draw(dc) |
|
478 |
||
479 |
def OnPaint(self, event): |
|
480 |
self.RefreshPreview() |
|
481 |
||
482 |
#------------------------------------------------------------------------------- |
|
483 |
# Create New Connection Dialog |
|
484 |
#------------------------------------------------------------------------------- |
|
485 |
||
486 |
[wxID_CONNECTIONPROPERTIESDIALOG, wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL, |
|
487 |
wxID_CONNECTIONPROPERTIESDIALOGNAME, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, |
|
488 |
wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, wxID_CONNECTIONPROPERTIESDIALOGPREVIEW, |
|
489 |
wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, |
|
490 |
wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, |
|
491 |
] = [wx.NewId() for _init_ctrls in range(9)] |
|
492 |
||
493 |
class ConnectionPropertiesDialog(wx.Dialog): |
|
494 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
495 |
# generated method, don't edit |
|
496 |
||
497 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
498 |
||
499 |
def _init_sizers(self): |
|
500 |
# generated method, don't edit |
|
501 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
502 |
||
503 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
504 |
||
505 |
self.SetSizer(self.flexGridSizer1) |
|
506 |
||
507 |
def _init_ctrls(self, prnt): |
|
508 |
# generated method, don't edit |
|
509 |
wx.Dialog.__init__(self, id=wxID_CONNECTIONPROPERTIESDIALOG, |
|
510 |
name='ConnectionPropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
511 |
size=wx.Size(350, 220), style=wx.DEFAULT_DIALOG_STYLE, |
|
512 |
title='Connection Properties') |
|
513 |
self.SetClientSize(wx.Size(350, 220)) |
|
514 |
||
515 |
self.MainPanel = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL, |
|
516 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
517 |
size=wx.Size(340, 360), style=wx.TAB_TRAVERSAL) |
|
518 |
self.MainPanel.SetAutoLayout(True) |
|
519 |
||
520 |
self.staticText1 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, |
|
521 |
label='Type:', name='staticText1', parent=self.MainPanel, |
|
522 |
pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) |
|
523 |
||
524 |
self.staticText2 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, |
|
525 |
label='Name:', name='staticText2', parent=self.MainPanel, |
|
526 |
pos=wx.Point(24, 104), size=wx.Size(70, 17), style=0) |
|
527 |
||
528 |
self.staticText3 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, |
|
529 |
label='Preview:', name='staticText3', parent=self.MainPanel, |
|
530 |
pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) |
|
531 |
||
532 |
self.radioButton1 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, |
|
533 |
label='Connector', name='radioButton1', parent=self.MainPanel, |
|
534 |
pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) |
|
535 |
EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
536 |
self.radioButton1.SetValue(True) |
|
537 |
||
538 |
self.radioButton2 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, |
|
539 |
label='Continuation', name='radioButton2', parent=self.MainPanel, |
|
540 |
pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) |
|
541 |
EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
542 |
self.radioButton2.SetValue(False) |
|
543 |
||
544 |
self.Name = wx.TextCtrl(id=wxID_CONNECTIONPROPERTIESDIALOGNAME, |
|
545 |
name='Name', parent=self.MainPanel, pos=wx.Point(24, 130), |
|
546 |
size=wx.Size(145, 24), style=0) |
|
547 |
EVT_TEXT(self, wxID_CONNECTIONPROPERTIESDIALOGNAME, self.OnNameChanged) |
|
548 |
||
549 |
self.Preview = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGPREVIEW, |
|
550 |
name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), |
|
551 |
size=wx.Size(150, 100), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
552 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 553 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 554 |
|
555 |
self._init_sizers() |
|
556 |
||
557 |
def __init__(self, parent): |
|
558 |
self._init_ctrls(parent) |
|
559 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
560 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
561 |
self.Connection = None |
|
562 |
self.MinConnectionSize = None |
|
563 |
||
564 |
EVT_PAINT(self, self.OnPaint) |
|
565 |
||
566 |
def SetMinConnectionSize(self, size): |
|
567 |
self.MinConnectionSize = size |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
568 |
|
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
569 |
def SetValues(self, values): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
570 |
for name, value in values.items(): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
571 |
if name == "type": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
572 |
if value == CONNECTOR: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
573 |
self.radioButton1.SetValue(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
574 |
elif value == CONTINUATION: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
575 |
self.radioButton2.SetValue(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
576 |
elif name == "name": |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
577 |
self.Name.SetValue(value) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
578 |
self.RefreshPreview() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
579 |
|
27 | 580 |
def GetValues(self): |
581 |
values = {} |
|
582 |
if self.radioButton1.GetValue(): |
|
583 |
values["type"] = CONNECTOR |
|
584 |
else: |
|
585 |
values["type"] = CONTINUATION |
|
586 |
values["name"] = self.Name.GetValue() |
|
587 |
values["width"], values["height"] = self.Connection.GetSize() |
|
588 |
return values |
|
589 |
||
590 |
def OnTypeChanged(self, event): |
|
591 |
self.RefreshPreview() |
|
592 |
event.Skip() |
|
593 |
||
594 |
def OnNameChanged(self, event): |
|
595 |
self.RefreshPreview() |
|
596 |
event.Skip() |
|
597 |
||
598 |
def RefreshPreview(self): |
|
599 |
dc = wxClientDC(self.Preview) |
|
600 |
dc.Clear() |
|
601 |
if self.radioButton1.GetValue(): |
|
602 |
self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.Name.GetValue()) |
|
603 |
else: |
|
604 |
self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.Name.GetValue()) |
|
605 |
width, height = self.MinConnectionSize |
|
606 |
min_width, min_height = self.Connection.GetMinSize() |
|
607 |
width, height = max(min_width, width), max(min_height, height) |
|
608 |
self.Connection.SetSize(width, height) |
|
609 |
clientsize = self.Preview.GetClientSize() |
|
610 |
x = (clientsize.width - width) / 2 |
|
611 |
y = (clientsize.height - height) / 2 |
|
612 |
self.Connection.SetPosition(x, y) |
|
613 |
self.Connection.Draw(dc) |
|
614 |
||
615 |
def OnPaint(self, event): |
|
616 |
self.RefreshPreview() |
|
617 |
||
618 |
||
619 |
#------------------------------------------------------------------------------- |
|
620 |
# Edit Ladder Element Properties Dialog |
|
621 |
#------------------------------------------------------------------------------- |
|
622 |
||
623 |
||
624 |
[wxID_LDELEMENTDIALOG, wxID_LDELEMENTDIALOGMAINPANEL, |
|
625 |
wxID_LDELEMENTDIALOGNAME, wxID_LDELEMENTDIALOGRADIOBUTTON1, |
|
626 |
wxID_LDELEMENTDIALOGRADIOBUTTON2, wxID_LDELEMENTDIALOGRADIOBUTTON3, |
|
627 |
wxID_LDELEMENTDIALOGRADIOBUTTON4, wxID_LDELEMENTDIALOGPREVIEW, |
|
628 |
wxID_LDELEMENTDIALOGSTATICTEXT1, wxID_LDELEMENTDIALOGSTATICTEXT2, |
|
629 |
wxID_LDELEMENTDIALOGSTATICTEXT3, |
|
630 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
631 |
||
632 |
class LDElementDialog(wx.Dialog): |
|
633 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
634 |
# generated method, don't edit |
|
635 |
||
636 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
637 |
||
638 |
def _init_sizers(self): |
|
639 |
# generated method, don't edit |
|
640 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
641 |
||
642 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
643 |
||
644 |
self.SetSizer(self.flexGridSizer1) |
|
645 |
||
646 |
def _init_ctrls(self, prnt, title, labels): |
|
647 |
# generated method, don't edit |
|
648 |
wx.Dialog.__init__(self, id=wxID_LDELEMENTDIALOG, |
|
649 |
name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
650 |
size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE, |
|
651 |
title=title) |
|
652 |
self.SetClientSize(wx.Size(350, 260)) |
|
653 |
||
654 |
self.MainPanel = wx.Panel(id=wxID_LDELEMENTDIALOGMAINPANEL, |
|
655 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
656 |
size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL) |
|
657 |
self.MainPanel.SetAutoLayout(True) |
|
658 |
||
659 |
self.staticText1 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT1, |
|
660 |
label='Modifier:', name='staticText1', parent=self.MainPanel, |
|
661 |
pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) |
|
662 |
||
663 |
self.staticText2 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT2, |
|
664 |
label='Name:', name='staticText2', parent=self.MainPanel, |
|
665 |
pos=wx.Point(24, 150), size=wx.Size(70, 17), style=0) |
|
666 |
||
667 |
self.staticText3 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT3, |
|
668 |
label='Preview:', name='staticText3', parent=self.MainPanel, |
|
669 |
pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) |
|
670 |
||
671 |
self.radioButton1 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON1, |
|
672 |
label=labels[0], name='radioButton1', parent=self.MainPanel, |
|
673 |
pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) |
|
674 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
675 |
self.radioButton1.SetValue(True) |
|
676 |
||
677 |
self.radioButton2 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON2, |
|
678 |
label=labels[1], name='radioButton2', parent=self.MainPanel, |
|
679 |
pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) |
|
680 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
681 |
||
682 |
self.radioButton3 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON3, |
|
683 |
label=labels[2], name='radioButton3', parent=self.MainPanel, |
|
684 |
pos=wx.Point(24, 96), size=wx.Size(114, 24), style=0) |
|
685 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON3, self.OnTypeChanged) |
|
686 |
||
687 |
self.radioButton4 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON4, |
|
688 |
label=labels[3], name='radioButton4', parent=self.MainPanel, |
|
689 |
pos=wx.Point(24, 120), size=wx.Size(128, 24), style=0) |
|
690 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON4, self.OnTypeChanged) |
|
691 |
||
692 |
self.Name = wx.Choice(id=wxID_LDELEMENTDIALOGNAME, |
|
693 |
name='Name', parent=self.MainPanel, pos=wx.Point(24, 174), |
|
694 |
size=wx.Size(145, 24), style=0) |
|
695 |
EVT_CHOICE(self, wxID_LDELEMENTDIALOGNAME, self.OnNameChanged) |
|
696 |
||
697 |
self.Preview = wx.Panel(id=wxID_LDELEMENTDIALOGPREVIEW, |
|
698 |
name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), |
|
699 |
size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
700 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 701 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 702 |
|
703 |
self._init_sizers() |
|
704 |
||
705 |
def __init__(self, parent, type): |
|
706 |
self.Type = type |
|
707 |
if type == "contact": |
|
708 |
self._init_ctrls(parent, "Edit Contact Values", ['Normal','Negate','Rising Edge','Falling Edge']) |
|
709 |
self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "") |
|
710 |
elif type == "coil": |
|
711 |
self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset']) |
|
712 |
self.Element = LD_Coil(self.Preview, COIL_NORMAL, "") |
|
713 |
self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2) |
|
714 |
||
715 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
716 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
717 |
||
718 |
EVT_PAINT(self, self.OnPaint) |
|
719 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
720 |
def SetElementSize(self, size): |
27 | 721 |
min_width, min_height = self.Element.GetMinSize() |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
722 |
width, height = max(min_width, size[0]), max(min_height, size[1]) |
27 | 723 |
self.Element.SetSize(width, height) |
724 |
self.Element.SetPosition((150 - width) / 2, (150 - height) / 2) |
|
725 |
||
726 |
def SetVariables(self, vars): |
|
727 |
self.Name.Clear() |
|
728 |
for name in vars: |
|
729 |
self.Name.Append(name) |
|
730 |
self.Name.Enable(self.Name.GetCount() > 0) |
|
731 |
||
732 |
def SetValues(self, values): |
|
733 |
for name, value in values.items(): |
|
734 |
if name == "name": |
|
735 |
self.Element.SetName(value) |
|
736 |
self.Name.SetStringSelection(value) |
|
737 |
elif name == "type": |
|
738 |
self.Element.SetType(value) |
|
739 |
if self.Type == "contact": |
|
740 |
if value == CONTACT_NORMAL: |
|
741 |
self.radioButton1.SetValue(True) |
|
742 |
elif value == CONTACT_REVERSE: |
|
743 |
self.radioButton2.SetValue(True) |
|
744 |
elif value == CONTACT_RISING: |
|
745 |
self.radioButton3.SetValue(True) |
|
746 |
elif value == CONTACT_FALLING: |
|
747 |
self.radioButton4.SetValue(True) |
|
748 |
elif self.Type == "coil": |
|
749 |
if value == COIL_NORMAL: |
|
750 |
self.radioButton1.SetValue(True) |
|
751 |
elif value == COIL_REVERSE: |
|
752 |
self.radioButton2.SetValue(True) |
|
753 |
elif value == COIL_SET: |
|
754 |
self.radioButton3.SetValue(True) |
|
755 |
elif value == COIL_RESET: |
|
756 |
self.radioButton4.SetValue(True) |
|
757 |
||
758 |
def GetValues(self): |
|
759 |
values = {} |
|
760 |
values["name"] = self.Element.GetName() |
|
761 |
values["type"] = self.Element.GetType() |
|
762 |
values["width"], values["height"] = self.Element.GetSize() |
|
763 |
return values |
|
764 |
||
765 |
def OnTypeChanged(self, event): |
|
766 |
if self.Type == "contact": |
|
767 |
if self.radioButton1.GetValue(): |
|
768 |
self.Element.SetType(CONTACT_NORMAL) |
|
769 |
elif self.radioButton2.GetValue(): |
|
770 |
self.Element.SetType(CONTACT_REVERSE) |
|
771 |
elif self.radioButton3.GetValue(): |
|
772 |
self.Element.SetType(CONTACT_RISING) |
|
773 |
elif self.radioButton4.GetValue(): |
|
774 |
self.Element.SetType(CONTACT_FALLING) |
|
775 |
elif self.Type == "coil": |
|
776 |
if self.radioButton1.GetValue(): |
|
777 |
self.Element.SetType(COIL_NORMAL) |
|
778 |
elif self.radioButton2.GetValue(): |
|
779 |
self.Element.SetType(COIL_REVERSE) |
|
780 |
elif self.radioButton3.GetValue(): |
|
781 |
self.Element.SetType(COIL_SET) |
|
782 |
elif self.radioButton4.GetValue(): |
|
783 |
self.Element.SetType(COIL_RESET) |
|
784 |
self.RefreshPreview() |
|
785 |
event.Skip() |
|
786 |
||
787 |
def OnNameChanged(self, event): |
|
788 |
self.Element.SetName(self.Name.GetStringSelection()) |
|
789 |
self.RefreshPreview() |
|
790 |
event.Skip() |
|
791 |
||
792 |
def RefreshPreview(self): |
|
793 |
dc = wxClientDC(self.Preview) |
|
794 |
dc.Clear() |
|
795 |
self.Element.Draw(dc) |
|
796 |
||
797 |
def OnPaint(self, event): |
|
798 |
self.RefreshPreview() |
|
799 |
event.Skip() |
|
800 |
||
801 |
||
802 |
#------------------------------------------------------------------------------- |
|
803 |
# Edit Ladder Power Rail Properties Dialog |
|
804 |
#------------------------------------------------------------------------------- |
|
805 |
||
806 |
||
807 |
[wxID_LDPOWERRAILDIALOG, wxID_LDPOWERRAILDIALOGMAINPANEL, |
|
808 |
wxID_LDPOWERRAILDIALOGTYPE, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, |
|
809 |
wxID_LDPOWERRAILDIALOGRADIOBUTTON2, wxID_LDPOWERRAILDIALOGPREVIEW, |
|
810 |
wxID_LDPOWERRAILDIALOGSTATICTEXT1, wxID_LDPOWERRAILDIALOGSTATICTEXT2, |
|
811 |
wxID_LDPOWERRAILDIALOGSTATICTEXT3, wxID_LDPOWERRAILDIALOGPINNUMBER, |
|
812 |
] = [wx.NewId() for _init_ctrls in range(10)] |
|
813 |
||
814 |
class LDPowerRailDialog(wx.Dialog): |
|
815 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
816 |
# generated method, don't edit |
|
817 |
||
818 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
819 |
||
820 |
def _init_sizers(self): |
|
821 |
# generated method, don't edit |
|
822 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
823 |
||
824 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
825 |
||
826 |
self.SetSizer(self.flexGridSizer1) |
|
827 |
||
828 |
def _init_ctrls(self, prnt): |
|
829 |
# generated method, don't edit |
|
830 |
wx.Dialog.__init__(self, id=wxID_LDPOWERRAILDIALOG, |
|
831 |
name='PowerRailDialog', parent=prnt, pos=wx.Point(376, 223), |
|
832 |
size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE, |
|
833 |
title='Power Rail Properties') |
|
834 |
self.SetClientSize(wx.Size(350, 260)) |
|
835 |
||
836 |
self.MainPanel = wx.Panel(id=wxID_LDPOWERRAILDIALOGMAINPANEL, |
|
837 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
838 |
size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL) |
|
839 |
self.MainPanel.SetAutoLayout(True) |
|
840 |
||
841 |
self.staticText1 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT1, |
|
842 |
label='Type:', name='staticText1', parent=self.MainPanel, |
|
843 |
pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) |
|
844 |
||
845 |
self.staticText2 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT2, |
|
846 |
label='Pin number:', name='staticText2', parent=self.MainPanel, |
|
847 |
pos=wx.Point(24, 100), size=wx.Size(70, 17), style=0) |
|
848 |
||
849 |
self.staticText3 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT3, |
|
850 |
label='Preview:', name='staticText3', parent=self.MainPanel, |
|
851 |
pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) |
|
852 |
||
853 |
self.radioButton1 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON1, |
|
854 |
label='Left PowerRail', name='radioButton1', parent=self.MainPanel, |
|
855 |
pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) |
|
856 |
EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
857 |
self.radioButton1.SetValue(True) |
|
858 |
||
859 |
self.radioButton2 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON2, |
|
860 |
label='Right PowerRail', name='radioButton2', parent=self.MainPanel, |
|
861 |
pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) |
|
862 |
EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
863 |
||
864 |
self.PinNumber = wx.SpinCtrl(id=wxID_LDPOWERRAILDIALOGPINNUMBER, |
|
865 |
name='PinNumber', parent=self.MainPanel, pos=wx.Point(24, 124), |
|
866 |
size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=1, max=20) |
|
867 |
EVT_SPINCTRL(self, wxID_LDPOWERRAILDIALOGPINNUMBER, self.OnPinNumberChanged) |
|
868 |
||
869 |
self.Preview = wx.Panel(id=wxID_LDPOWERRAILDIALOGPREVIEW, |
|
870 |
name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), |
|
871 |
size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
872 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 873 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 874 |
|
875 |
self._init_sizers() |
|
876 |
||
877 |
def __init__(self, parent, type = LEFTRAIL, number = 1): |
|
878 |
self._init_ctrls(parent) |
|
879 |
self.Type = type |
|
880 |
if type == LEFTRAIL: |
|
881 |
self.radioButton1.SetValue(True) |
|
882 |
elif type == RIGHTRAIL: |
|
883 |
self.radioButton2.SetValue(True) |
|
884 |
self.PinNumber.SetValue(number) |
|
885 |
||
886 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
887 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
888 |
||
889 |
self.PowerRailMinSize = (0, 0) |
|
890 |
self.PowerRail = None |
|
891 |
||
892 |
EVT_PAINT(self, self.OnPaint) |
|
893 |
||
894 |
def SetMinSize(self, size): |
|
895 |
self.PowerRailMinSize = size |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
896 |
self.RefreshPreview() |
27 | 897 |
|
898 |
def GetValues(self): |
|
899 |
values = {} |
|
900 |
values["type"] = self.Type |
|
901 |
values["number"] = self.PinNumber.GetValue() |
|
902 |
values["width"], values["height"] = self.PowerRail.GetSize() |
|
903 |
return values |
|
904 |
||
905 |
def OnTypeChanged(self, event): |
|
906 |
if self.radioButton1.GetValue(): |
|
907 |
self.Type = LEFTRAIL |
|
908 |
elif self.radioButton2.GetValue(): |
|
909 |
self.Type = RIGHTRAIL |
|
910 |
self.RefreshPreview() |
|
911 |
event.Skip() |
|
912 |
||
913 |
def OnPinNumberChanged(self, event): |
|
914 |
self.RefreshPreview() |
|
915 |
event.Skip() |
|
916 |
||
917 |
def RefreshPreview(self): |
|
918 |
dc = wxClientDC(self.Preview) |
|
919 |
dc.Clear() |
|
920 |
self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = [True for i in xrange(self.PinNumber.GetValue())]) |
|
921 |
min_width, min_height = self.PowerRail.GetMinSize() |
|
922 |
width, height = max(min_width, self.PowerRailMinSize[0]), max(min_height, self.PowerRailMinSize[1]) |
|
923 |
self.PowerRail.SetSize(width, height) |
|
924 |
self.PowerRail.RefreshConnectors() |
|
925 |
self.PowerRail.SetPosition((150 - width) / 2, (150 - height) / 2) |
|
926 |
self.PowerRail.Draw(dc) |
|
927 |
||
928 |
def OnPaint(self, event): |
|
929 |
self.RefreshPreview() |
|
930 |
event.Skip() |
|
931 |
||
932 |
||
933 |
#------------------------------------------------------------------------------- |
|
934 |
# Edit Transition Content Dialog |
|
935 |
#------------------------------------------------------------------------------- |
|
936 |
||
937 |
[wxID_TRANSITIONCONTENTDIALOG, wxID_TRANSITIONCONTENTDIALOGMAINPANEL, |
|
938 |
wxID_TRANSITIONCONTENTDIALOGREFERENCE, wxID_TRANSITIONCONTENTDIALOGINLINE, |
|
939 |
wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, |
|
940 |
] = [wx.NewId() for _init_ctrls in range(6)] |
|
941 |
||
942 |
class TransitionContentDialog(wx.Dialog): |
|
943 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
944 |
# generated method, don't edit |
|
945 |
||
946 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
947 |
||
948 |
def _init_sizers(self): |
|
949 |
# generated method, don't edit |
|
950 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
951 |
||
952 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
953 |
||
954 |
self.SetSizer(self.flexGridSizer1) |
|
955 |
||
956 |
def _init_ctrls(self, prnt): |
|
957 |
# generated method, don't edit |
|
958 |
wx.Dialog.__init__(self, id=wxID_TRANSITIONCONTENTDIALOG, |
|
959 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
|
960 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
|
961 |
title='Edit transition') |
|
962 |
self.SetClientSize(wx.Size(300, 200)) |
|
963 |
||
964 |
self.MainPanel = wx.Panel(id=wxID_TRANSITIONCONTENTDIALOGMAINPANEL, |
|
965 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
966 |
size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) |
|
967 |
self.MainPanel.SetAutoLayout(True) |
|
968 |
||
969 |
self.radioButton1 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, |
|
970 |
label='Reference', name='radioButton1', parent=self.MainPanel, |
|
971 |
pos=wx.Point(24, 24), size=wx.Size(114, 24), style=0) |
|
972 |
EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
973 |
self.radioButton1.SetValue(True) |
|
974 |
||
975 |
self.Reference = wx.Choice(id=wxID_TRANSITIONCONTENTDIALOGREFERENCE, |
|
976 |
name='Reference', parent=self.MainPanel, pos=wx.Point(48, 48), |
|
977 |
size=wx.Size(200, 24), style=0) |
|
978 |
||
979 |
self.radioButton2 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, |
|
980 |
label='Inline', name='radioButton2', parent=self.MainPanel, |
|
981 |
pos=wx.Point(24, 72), size=wx.Size(114, 24), style=0) |
|
982 |
EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
983 |
self.radioButton2.SetValue(False) |
|
984 |
||
985 |
self.Inline = wx.TextCtrl(id=wxID_TRANSITIONCONTENTDIALOGINLINE, |
|
986 |
name='Inline', parent=self.MainPanel, pos=wx.Point(48, 96), |
|
987 |
size=wx.Size(200, 24), style=0) |
|
988 |
||
989 |
self._init_sizers() |
|
990 |
||
991 |
def __init__(self, parent): |
|
992 |
self._init_ctrls(parent) |
|
993 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
994 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
995 |
||
996 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
997 |
||
998 |
def OnOK(self, event): |
|
999 |
error = [] |
|
1000 |
if self.radioButton1.GetValue() and self.Reference.GetStringSelection() == "": |
|
1001 |
error.append("Reference") |
|
1002 |
if self.radioButton2.GetValue() and self.Inline.GetValue() == "": |
|
1003 |
error.append("Inline") |
|
1004 |
if len(error) > 0: |
|
1005 |
text = "" |
|
1006 |
for i, item in enumerate(error): |
|
1007 |
if i == 0: |
|
1008 |
text += item |
|
1009 |
elif i == len(error) - 1: |
|
1010 |
text += " and %s"%item |
|
1011 |
else: |
|
1012 |
text += ", %s"%item |
|
1013 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1014 |
message.ShowModal() |
|
1015 |
message.Destroy() |
|
1016 |
else: |
|
1017 |
self.EndModal(wxID_OK) |
|
1018 |
||
1019 |
def OnTypeChanged(self, event): |
|
1020 |
if self.radioButton1.GetValue(): |
|
1021 |
self.Reference.Enable(True) |
|
1022 |
self.Inline.Enable(False) |
|
1023 |
else: |
|
1024 |
self.Reference.Enable(False) |
|
1025 |
self.Inline.Enable(True) |
|
1026 |
event.Skip() |
|
1027 |
||
1028 |
def SetTransitions(self, transitions): |
|
1029 |
for transition in transitions: |
|
1030 |
self.Reference.Append(transition) |
|
1031 |
||
1032 |
def SetValues(self, values): |
|
1033 |
if values["type"] == "reference": |
|
1034 |
self.radioButton1.SetValue(True) |
|
1035 |
self.radioButton2.SetValue(False) |
|
1036 |
self.Reference.Enable(True) |
|
1037 |
self.Inline.Enable(False) |
|
1038 |
self.Reference.SetStringSelection(values["value"]) |
|
1039 |
elif values["type"] == "inline": |
|
1040 |
self.radioButton1.SetValue(False) |
|
1041 |
self.radioButton2.SetValue(True) |
|
1042 |
self.Reference.Enable(False) |
|
1043 |
self.Inline.Enable(True) |
|
1044 |
self.Inline.SetValue(values["value"]) |
|
1045 |
||
1046 |
def GetValues(self): |
|
1047 |
values = {} |
|
1048 |
if self.radioButton1.GetValue(): |
|
1049 |
values["type"] = "reference" |
|
1050 |
values["value"] = self.Reference.GetStringSelection() |
|
1051 |
else: |
|
1052 |
values["type"] = "inline" |
|
1053 |
values["value"] = self.Inline.GetValue() |
|
1054 |
return values |
|
1055 |
||
1056 |
#------------------------------------------------------------------------------- |
|
1057 |
# Create New Divergence Dialog |
|
1058 |
#------------------------------------------------------------------------------- |
|
1059 |
||
1060 |
[wxID_DIVERGENCECREATEDIALOG, wxID_DIVERGENCECREATEDIALOGMAINPANEL, |
|
1061 |
wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, |
|
1062 |
wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, |
|
1063 |
wxID_DIVERGENCECREATEDIALOGSEQUENCES, wxID_DIVERGENCECREATEDIALOGPREVIEW, |
|
1064 |
wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, |
|
1065 |
wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, |
|
1066 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
1067 |
||
1068 |
class DivergenceCreateDialog(wx.Dialog): |
|
1069 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1070 |
# generated method, don't edit |
|
1071 |
||
1072 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1073 |
||
1074 |
def _init_sizers(self): |
|
1075 |
# generated method, don't edit |
|
1076 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1077 |
||
1078 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1079 |
||
1080 |
self.SetSizer(self.flexGridSizer1) |
|
1081 |
||
1082 |
def _init_ctrls(self, prnt): |
|
1083 |
# generated method, don't edit |
|
1084 |
wx.Dialog.__init__(self, id=wxID_DIVERGENCECREATEDIALOG, |
|
1085 |
name='DivergencePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1086 |
size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
1087 |
title='Create a new divergence or convergence') |
|
1088 |
self.SetClientSize(wx.Size(500, 260)) |
|
1089 |
||
1090 |
self.MainPanel = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGMAINPANEL, |
|
1091 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1092 |
size=wx.Size(600, 220), style=wx.TAB_TRAVERSAL) |
|
1093 |
self.MainPanel.SetAutoLayout(True) |
|
1094 |
||
1095 |
self.staticText1 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, |
|
1096 |
label='Type:', name='staticText1', parent=self.MainPanel, |
|
1097 |
pos=wx.Point(24, 24), size=wx.Size(200, 17), style=0) |
|
1098 |
||
1099 |
self.radioButton1 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, |
|
1100 |
label='Selection Divergence', name='radioButton1', parent=self.MainPanel, |
|
1101 |
pos=wx.Point(24, 48), size=wx.Size(200, 24), style=0) |
|
1102 |
EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
1103 |
self.radioButton1.SetValue(True) |
|
1104 |
||
1105 |
self.radioButton2 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, |
|
1106 |
label='Selection Convergence', name='radioButton2', parent=self.MainPanel, |
|
1107 |
pos=wx.Point(24, 72), size=wx.Size(200, 24), style=0) |
|
1108 |
EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
1109 |
self.radioButton2.SetValue(False) |
|
1110 |
||
1111 |
self.radioButton3 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, |
|
1112 |
label='Simultaneous Divergence', name='radioButton3', parent=self.MainPanel, |
|
1113 |
pos=wx.Point(24, 96), size=wx.Size(200, 24), style=0) |
|
1114 |
EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, self.OnTypeChanged) |
|
1115 |
self.radioButton3.SetValue(False) |
|
1116 |
||
1117 |
self.radioButton4 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, |
|
1118 |
label='Simultaneous Convergence', name='radioButton4', parent=self.MainPanel, |
|
1119 |
pos=wx.Point(24, 120), size=wx.Size(200, 24), style=0) |
|
1120 |
EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, self.OnTypeChanged) |
|
1121 |
self.radioButton4.SetValue(False) |
|
1122 |
||
1123 |
self.staticText2 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, |
|
1124 |
label='Number of sequences:', name='staticText2', parent=self.MainPanel, |
|
1125 |
pos=wx.Point(24, 150), size=wx.Size(200, 17), style=0) |
|
1126 |
||
1127 |
self.Sequences = wx.SpinCtrl(id=wxID_DIVERGENCECREATEDIALOGSEQUENCES, |
|
1128 |
name='Sequences', parent=self.MainPanel, pos=wx.Point(24, 174), |
|
1129 |
size=wx.Size(200, 24), style=0, min=2, max=20) |
|
1130 |
EVT_SPINCTRL(self, wxID_DIVERGENCECREATEDIALOGSEQUENCES, self.OnSequencesChanged) |
|
1131 |
||
1132 |
self.staticText3 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, |
|
1133 |
label='Preview:', name='staticText3', parent=self.MainPanel, |
|
1134 |
pos=wx.Point(250, 24), size=wx.Size(100, 17), style=0) |
|
1135 |
||
1136 |
self.Preview = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGPREVIEW, |
|
1137 |
name='Preview', parent=self.MainPanel, pos=wx.Point(250, 48), |
|
1138 |
size=wx.Size(225, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
1139 |
self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
42 | 1140 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
27 | 1141 |
|
1142 |
self._init_sizers() |
|
1143 |
||
1144 |
def __init__(self, parent): |
|
1145 |
self._init_ctrls(parent) |
|
1146 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
1147 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
1148 |
||
1149 |
self.Divergence = None |
|
1150 |
self.MinSize = (0, 0) |
|
1151 |
||
1152 |
EVT_PAINT(self, self.OnPaint) |
|
1153 |
||
1154 |
def GetValues(self): |
|
1155 |
values = {} |
|
1156 |
if self.radioButton1.GetValue(): |
|
1157 |
values["type"] = SELECTION_DIVERGENCE |
|
1158 |
elif self.radioButton2.GetValue(): |
|
1159 |
values["type"] = SELECTION_CONVERGENCE |
|
1160 |
elif self.radioButton3.GetValue(): |
|
1161 |
values["type"] = SIMULTANEOUS_DIVERGENCE |
|
1162 |
else: |
|
1163 |
values["type"] = SIMULTANEOUS_CONVERGENCE |
|
1164 |
values["number"] = self.Sequences.GetValue() |
|
1165 |
return values |
|
1166 |
||
1167 |
def SetMinSize(self, size): |
|
1168 |
self.MinSize = size |
|
1169 |
||
1170 |
def OnTypeChanged(self, event): |
|
1171 |
self.RefreshPreview() |
|
1172 |
event.Skip() |
|
1173 |
||
1174 |
def OnSequencesChanged(self, event): |
|
1175 |
self.RefreshPreview() |
|
1176 |
event.Skip() |
|
1177 |
||
1178 |
def RefreshPreview(self): |
|
1179 |
dc = wxClientDC(self.Preview) |
|
1180 |
dc.Clear() |
|
1181 |
if self.radioButton1.GetValue(): |
|
1182 |
self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue()) |
|
1183 |
elif self.radioButton2.GetValue(): |
|
1184 |
self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue()) |
|
1185 |
elif self.radioButton3.GetValue(): |
|
1186 |
self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue()) |
|
1187 |
else: |
|
1188 |
self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue()) |
|
1189 |
width, height = self.Divergence.GetSize() |
|
1190 |
min_width, min_height = max(width, self.MinSize[0]), max(height, self.MinSize[1]) |
|
1191 |
self.Divergence.SetSize(min_width, min_height) |
|
1192 |
clientsize = self.Preview.GetClientSize() |
|
1193 |
x = (clientsize.width - min_width) / 2 |
|
1194 |
y = (clientsize.height - min_height) / 2 |
|
1195 |
self.Divergence.SetPosition(x, y) |
|
1196 |
self.Divergence.Draw(dc) |
|
1197 |
||
1198 |
def OnPaint(self, event): |
|
1199 |
self.RefreshPreview() |
|
1200 |
||
1201 |
||
1202 |
#------------------------------------------------------------------------------- |
|
1203 |
# Action Block Dialog |
|
1204 |
#------------------------------------------------------------------------------- |
|
1205 |
||
1206 |
class ActionTable(wxPyGridTableBase): |
|
1207 |
||
1208 |
""" |
|
1209 |
A custom wxGrid Table using user supplied data |
|
1210 |
""" |
|
1211 |
def __init__(self, parent, data, colnames): |
|
1212 |
# The base class must be initialized *first* |
|
1213 |
wxPyGridTableBase.__init__(self) |
|
1214 |
self.data = data |
|
1215 |
self.colnames = colnames |
|
1216 |
self.Parent = parent |
|
1217 |
# XXX |
|
1218 |
# we need to store the row length and collength to |
|
1219 |
# see if the table has changed size |
|
1220 |
self._rows = self.GetNumberRows() |
|
1221 |
self._cols = self.GetNumberCols() |
|
1222 |
||
1223 |
def GetNumberCols(self): |
|
1224 |
return len(self.colnames) |
|
1225 |
||
1226 |
def GetNumberRows(self): |
|
1227 |
return len(self.data) |
|
1228 |
||
1229 |
def GetColLabelValue(self, col): |
|
1230 |
if col < len(self.colnames): |
|
1231 |
return self.colnames[col] |
|
1232 |
||
1233 |
def GetRowLabelValues(self, row): |
|
1234 |
return row |
|
1235 |
||
1236 |
def GetValue(self, row, col): |
|
1237 |
if row < self.GetNumberRows(): |
|
1238 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
1239 |
return name |
|
1240 |
||
1241 |
def GetValueByName(self, row, colname): |
|
1242 |
return self.data[row].get(colname) |
|
1243 |
||
1244 |
def SetValue(self, row, col, value): |
|
1245 |
if col < len(self.colnames): |
|
1246 |
self.data[row][self.GetColLabelValue(col)] = value |
|
1247 |
||
1248 |
def ResetView(self, grid): |
|
1249 |
""" |
|
1250 |
(wxGrid) -> Reset the grid view. Call this to |
|
1251 |
update the grid if rows and columns have been added or deleted |
|
1252 |
""" |
|
1253 |
grid.BeginBatch() |
|
1254 |
for current, new, delmsg, addmsg in [ |
|
1255 |
(self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
1256 |
(self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
1257 |
]: |
|
1258 |
if new < current: |
|
1259 |
msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
1260 |
grid.ProcessTableMessage(msg) |
|
1261 |
elif new > current: |
|
1262 |
msg = wxGridTableMessage(self,addmsg,new-current) |
|
1263 |
grid.ProcessTableMessage(msg) |
|
1264 |
self.UpdateValues(grid) |
|
1265 |
grid.EndBatch() |
|
1266 |
||
1267 |
self._rows = self.GetNumberRows() |
|
1268 |
self._cols = self.GetNumberCols() |
|
1269 |
# update the column rendering scheme |
|
1270 |
self._updateColAttrs(grid) |
|
1271 |
||
1272 |
# update the scrollbars and the displayed part of the grid |
|
1273 |
grid.AdjustScrollbars() |
|
1274 |
grid.ForceRefresh() |
|
1275 |
||
1276 |
def UpdateValues(self, grid): |
|
1277 |
"""Update all displayed values""" |
|
1278 |
# This sends an event to the grid table to update all of the values |
|
1279 |
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
1280 |
grid.ProcessTableMessage(msg) |
|
1281 |
||
1282 |
def _updateColAttrs(self, grid): |
|
1283 |
""" |
|
1284 |
wxGrid -> update the column attributes to add the |
|
1285 |
appropriate renderer given the column name. |
|
1286 |
||
1287 |
Otherwise default to the default renderer. |
|
1288 |
""" |
|
1289 |
||
1290 |
for col in range(self.GetNumberCols()): |
|
1291 |
attr = wxGridCellAttr() |
|
1292 |
attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) |
|
1293 |
grid.SetColAttr(col, attr) |
|
1294 |
grid.SetColSize(col, self.Parent.ColSizes[col]) |
|
1295 |
||
1296 |
typelist = None |
|
1297 |
accesslist = None |
|
1298 |
for row in range(self.GetNumberRows()): |
|
1299 |
for col in range(self.GetNumberCols()): |
|
1300 |
editor = None |
|
1301 |
renderer = None |
|
1302 |
readonly = False |
|
1303 |
colname = self.GetColLabelValue(col) |
|
1304 |
if colname == "Qualifier": |
|
1305 |
editor = wxGridCellChoiceEditor() |
|
1306 |
editor.SetParameters(self.Parent.QualifierList) |
|
1307 |
if colname == "Duration": |
|
1308 |
editor = wxGridCellTextEditor() |
|
1309 |
renderer = wxGridCellStringRenderer() |
|
1310 |
if self.Parent.DurationList[self.data[row]["Qualifier"]]: |
|
1311 |
readonly = False |
|
1312 |
else: |
|
1313 |
readonly = True |
|
1314 |
self.data[row]["Duration"] = "" |
|
1315 |
elif colname == "Type": |
|
1316 |
editor = wxGridCellChoiceEditor() |
|
1317 |
editor.SetParameters(self.Parent.TypeList) |
|
1318 |
elif colname == "Value": |
|
1319 |
type = self.data[row]["Type"] |
|
1320 |
if type == "Action": |
|
1321 |
editor = wxGridCellChoiceEditor() |
|
1322 |
editor.SetParameters(self.Parent.ActionList) |
|
1323 |
elif type == "Variable": |
|
1324 |
editor = wxGridCellChoiceEditor() |
|
1325 |
editor.SetParameters(self.Parent.VariableList) |
|
1326 |
elif type == "Inline": |
|
1327 |
editor = wxGridCellTextEditor() |
|
1328 |
renderer = wxGridCellStringRenderer() |
|
1329 |
elif colname == "Indicator": |
|
1330 |
editor = wxGridCellChoiceEditor() |
|
1331 |
editor.SetParameters(self.Parent.VariableList) |
|
1332 |
||
1333 |
grid.SetCellEditor(row, col, editor) |
|
1334 |
grid.SetCellRenderer(row, col, renderer) |
|
1335 |
grid.SetReadOnly(row, col, readonly) |
|
1336 |
||
1337 |
grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
1338 |
||
1339 |
def SetData(self, data): |
|
1340 |
self.data = data |
|
1341 |
||
1342 |
def GetData(self): |
|
1343 |
return self.data |
|
1344 |
||
1345 |
def GetCurrentIndex(self): |
|
1346 |
return self.CurrentIndex |
|
1347 |
||
1348 |
def SetCurrentIndex(self, index): |
|
1349 |
self.CurrentIndex = index |
|
1350 |
||
1351 |
def AppendRow(self, row_content): |
|
1352 |
self.data.append(row_content) |
|
1353 |
||
1354 |
def RemoveRow(self, row_index): |
|
1355 |
self.data.pop(row_index) |
|
1356 |
||
1357 |
def MoveRow(self, row_index, move, grid): |
|
1358 |
new_index = max(0, min(row_index + move, len(self.data) - 1)) |
|
1359 |
if new_index != row_index: |
|
1360 |
self.data.insert(new_index, self.data.pop(row_index)) |
|
1361 |
grid.SetGridCursor(new_index, grid.GetGridCursorCol()) |
|
1362 |
||
1363 |
def Empty(self): |
|
1364 |
self.data = [] |
|
1365 |
self.editors = [] |
|
1366 |
||
1367 |
[wxID_ACTIONBLOCKDIALOG, wxID_ACTIONBLOCKDIALOGMAINPANEL, |
|
1368 |
wxID_ACTIONBLOCKDIALOGVARIABLESGRID, wxID_ACTIONBLOCKDIALOGSTATICTEXT1, |
|
1369 |
wxID_ACTIONBLOCKDIALOGADDBUTTON,wxID_ACTIONBLOCKDIALOGDELETEBUTTON, |
|
1370 |
wxID_ACTIONBLOCKDIALOGUPBUTTON, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, |
|
1371 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
1372 |
||
1373 |
class ActionBlockDialog(wx.Dialog): |
|
1374 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1375 |
# generated method, don't edit |
|
1376 |
||
1377 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1378 |
||
1379 |
def _init_sizers(self): |
|
1380 |
# generated method, don't edit |
|
1381 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1382 |
||
1383 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1384 |
||
1385 |
self.SetSizer(self.flexGridSizer1) |
|
1386 |
||
1387 |
def _init_ctrls(self, prnt): |
|
1388 |
# generated method, don't edit |
|
1389 |
wx.Dialog.__init__(self, id=wxID_ACTIONBLOCKDIALOG, |
|
1390 |
name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1391 |
size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
1392 |
title='Edit action block properties') |
|
1393 |
self.SetClientSize(wx.Size(500, 300)) |
|
1394 |
||
1395 |
self.MainPanel = wx.Panel(id=wxID_ACTIONBLOCKDIALOGMAINPANEL, |
|
1396 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1397 |
size=wx.Size(500, 300), style=wx.TAB_TRAVERSAL) |
|
1398 |
self.MainPanel.SetAutoLayout(True) |
|
1399 |
||
1400 |
self.staticText1 = wx.StaticText(id=wxID_ACTIONBLOCKDIALOGSTATICTEXT1, |
|
1401 |
label='Actions:', name='staticText1', parent=self.MainPanel, |
|
1402 |
pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) |
|
1403 |
||
1404 |
self.ActionsGrid = wx.grid.Grid(id=wxID_ACTIONBLOCKDIALOGVARIABLESGRID, |
|
1405 |
name='ActionsGrid', parent=self.MainPanel, pos=wx.Point(24, 44), |
|
1406 |
size=wx.Size(450, 150), style=wxVSCROLL) |
|
1407 |
self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
1408 |
'Sans')) |
|
1409 |
self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
1410 |
False, 'Sans')) |
|
1411 |
self.ActionsGrid.DisableDragGridSize() |
|
1412 |
self.ActionsGrid.EnableScrolling(False, True) |
|
1413 |
EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange) |
|
1414 |
||
1415 |
self.AddButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGADDBUTTON, label='Add', |
|
1416 |
name='AddButton', parent=self.MainPanel, pos=wx.Point(245, 204), |
|
1417 |
size=wx.Size(72, 32), style=0) |
|
1418 |
EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGADDBUTTON, self.OnAddButton) |
|
1419 |
||
1420 |
self.DeleteButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete', |
|
1421 |
name='DeleteButton', parent=self.MainPanel, pos=wx.Point(325, 204), |
|
1422 |
size=wx.Size(72, 32), style=0) |
|
1423 |
EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDELETEBUTTON, self.OnDeleteButton) |
|
1424 |
||
1425 |
self.UpButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGUPBUTTON, label='^', |
|
1426 |
name='UpButton', parent=self.MainPanel, pos=wx.Point(405, 204), |
|
1427 |
size=wx.Size(32, 32), style=0) |
|
1428 |
EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGUPBUTTON, self.OnUpButton) |
|
1429 |
||
1430 |
self.DownButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', |
|
1431 |
name='DownButton', parent=self.MainPanel, pos=wx.Point(445, 204), |
|
1432 |
size=wx.Size(32, 32), style=0) |
|
1433 |
EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, self.OnDownButton) |
|
1434 |
||
1435 |
self._init_sizers() |
|
1436 |
||
1437 |
def __init__(self, parent): |
|
1438 |
self._init_ctrls(parent) |
|
1439 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
1440 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
1441 |
||
1442 |
self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} |
|
1443 |
self.Table = ActionTable(self, [], ["Qualifier","Duration","Type","Value","Indicator"]) |
|
1444 |
self.TypeList = "Action,Variable,Inline" |
|
1445 |
self.ColSizes = [60, 90, 80, 110, 80] |
|
1446 |
self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT] |
|
1447 |
||
1448 |
self.ActionsGrid.SetTable(self.Table) |
|
1449 |
self.ActionsGrid.SetRowLabelSize(0) |
|
1450 |
||
1451 |
self.Table.ResetView(self.ActionsGrid) |
|
1452 |
||
1453 |
def OnAddButton(self, event): |
|
1454 |
self.Table.AppendRow(self.DefaultValue.copy()) |
|
1455 |
self.Table.ResetView(self.ActionsGrid) |
|
1456 |
event.Skip() |
|
1457 |
||
1458 |
def OnDeleteButton(self, event): |
|
1459 |
row = self.ActionsGrid.GetGridCursorRow() |
|
1460 |
self.Table.RemoveRow(row) |
|
1461 |
self.Table.ResetView(self.ActionsGrid) |
|
1462 |
event.Skip() |
|
1463 |
||
1464 |
def OnUpButton(self, event): |
|
1465 |
row = self.ActionsGrid.GetGridCursorRow() |
|
1466 |
self.Table.MoveRow(row, -1, self.ActionsGrid) |
|
1467 |
self.Table.ResetView(self.ActionsGrid) |
|
1468 |
event.Skip() |
|
1469 |
||
1470 |
def OnDownButton(self, event): |
|
1471 |
row = self.ActionsGrid.GetGridCursorRow() |
|
1472 |
self.Table.MoveRow(row, 1, self.ActionsGrid) |
|
1473 |
self.Table.ResetView(self.ActionsGrid) |
|
1474 |
event.Skip() |
|
1475 |
||
1476 |
def OnActionsGridCellChange(self, event): |
|
1477 |
self.Table.ResetView(self.ActionsGrid) |
|
1478 |
event.Skip() |
|
1479 |
||
1480 |
def SetQualifierList(self, list): |
|
1481 |
self.QualifierList = "" |
|
1482 |
sep = "" |
|
1483 |
for qualifier in list.keys(): |
|
1484 |
self.QualifierList += "%s%s"%(sep, qualifier) |
|
1485 |
sep = "," |
|
1486 |
self.DurationList = list |
|
1487 |
||
1488 |
def SetVariableList(self, list): |
|
1489 |
self.VariableList = "" |
|
1490 |
sep = "" |
|
1491 |
for variable in list: |
|
1492 |
self.VariableList += "%s%s"%(sep, variable["Name"]) |
|
1493 |
sep = "," |
|
1494 |
||
1495 |
def SetActionList(self, list): |
|
1496 |
self.ActionList = "" |
|
1497 |
sep = "" |
|
1498 |
for action in list: |
|
1499 |
self.ActionList += "%s%s"%(sep, action) |
|
1500 |
sep = "," |
|
1501 |
||
1502 |
def SetValues(self, actions): |
|
1503 |
for action in actions: |
|
1504 |
row = {"Qualifier" : action["qualifier"], "Value" : action["value"]} |
|
1505 |
if action["type"] == "reference": |
|
1506 |
if action["value"] in self.ActionList: |
|
1507 |
row["Type"] = "Action" |
|
1508 |
elif action["value"] in self.VariableList: |
|
1509 |
row["Type"] = "Variable" |
|
1510 |
else: |
|
1511 |
row["Type"] = "Inline" |
|
1512 |
else: |
|
1513 |
row["Type"] = "Inline" |
|
1514 |
if "duration" in action: |
|
1515 |
row["Duration"] = action["duration"] |
|
1516 |
else: |
|
1517 |
row["Duration"] = "" |
|
1518 |
if "indicator" in action: |
|
1519 |
row["Indicator"] = action["indicator"] |
|
1520 |
else: |
|
1521 |
row["Indicator"] = "" |
|
1522 |
self.Table.AppendRow(row) |
|
1523 |
self.Table.ResetView(self.ActionsGrid) |
|
1524 |
||
1525 |
def GetValues(self): |
|
1526 |
values = [] |
|
1527 |
for data in self.Table.GetData(): |
|
1528 |
action = {"qualifier" : data["Qualifier"], "value" : data["Value"]} |
|
1529 |
if data["Type"] in ["Action", "Variable"]: |
|
1530 |
action["type"] = "reference" |
|
1531 |
else: |
|
1532 |
action["type"] = "inline" |
|
1533 |
if data["Duration"] != "": |
|
1534 |
action["duration"] = data["Duration"] |
|
1535 |
if data["Indicator"] != "": |
|
1536 |
action["indicator"] = data["Indicator"] |
|
1537 |
values.append(action) |
|
1538 |
return values |
|
1539 |
||
1540 |
||
1541 |
#------------------------------------------------------------------------------- |
|
1542 |
# Edit Step Name Dialog |
|
1543 |
#------------------------------------------------------------------------------- |
|
1544 |
||
1545 |
class StepNameDialog(wxTextEntryDialog): |
|
1546 |
||
1547 |
def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
|
1548 |
style = wxOK|wxCANCEL|wxCENTRE, pos = wxDefaultPosition): |
|
1549 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
1550 |
||
1551 |
self.PouNames = [] |
|
1552 |
self.Variables = [] |
|
1553 |
self.StepNames = [] |
|
1554 |
||
1555 |
EVT_BUTTON(self, self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId(), self.OnOK) |
|
1556 |
||
1557 |
def OnOK(self, event): |
|
1558 |
step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
1559 |
if step_name == "": |
|
1560 |
message = wxMessageDialog(self, "You must type a name!", "Error", wxOK|wxICON_ERROR) |
|
1561 |
message.ShowModal() |
|
1562 |
message.Destroy() |
|
1563 |
elif not TestIdentifier(step_name): |
|
1564 |
message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1565 |
message.ShowModal() |
|
1566 |
message.Destroy() |
|
1567 |
elif step_name.upper() in IEC_KEYWORDS: |
|
1568 |
message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1569 |
message.ShowModal() |
|
1570 |
message.Destroy() |
|
1571 |
elif step_name.upper() in self.PouNames: |
|
1572 |
message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1573 |
message.ShowModal() |
|
1574 |
message.Destroy() |
|
1575 |
elif step_name.upper() in self.Variables: |
|
1576 |
message = wxMessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1577 |
message.ShowModal() |
|
1578 |
message.Destroy() |
|
1579 |
elif step_name.upper() in self.StepNames: |
|
1580 |
message = wxMessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1581 |
message.ShowModal() |
|
1582 |
message.Destroy() |
|
1583 |
else: |
|
1584 |
self.EndModal(wxID_OK) |
|
1585 |
||
1586 |
def SetPouNames(self, pou_names): |
|
1587 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1588 |
||
1589 |
def SetVariables(self, variables): |
|
1590 |
self.Variables = [var["Name"].upper() for var in variables] |
|
1591 |
||
1592 |
def SetStepNames(self, step_names): |
|
1593 |
self.StepNames = [step_name.upper() for step_name in step_names] |
|
1594 |
||
42 | 1595 |
def GetValue(self): |
1596 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |