author | lbessard |
Wed, 08 Aug 2007 14:54:48 +0200 | |
changeset 5 | 9565bb5facf7 |
parent 4 | e9d061c23e83 |
child 6 | 97d73990053d |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
0 | 6 |
# |
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 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 |
|
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
19 |
#General Public License for more details. |
0 | 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 |
import wx |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
26 |
|
0 | 27 |
from time import localtime |
28 |
from datetime import datetime |
|
29 |
||
1 | 30 |
import os, re, platform, sys, time, traceback, getopt, commands |
0 | 31 |
base_folder = os.path.split(sys.path[0])[0] |
32 |
sys.path.append(os.path.join(base_folder, "plcopeneditor")) |
|
33 |
sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
34 |
||
35 |
from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
|
36 |
from PLCControler import PLCControler |
|
37 |
||
38 |
from networkedit import networkedit |
|
39 |
from nodelist import NodeList |
|
40 |
from nodemanager import NodeManager |
|
1 | 41 |
import config_utils, gen_cfile |
0 | 42 |
|
43 |
__version__ = "$Revision$" |
|
44 |
||
45 |
def create(parent): |
|
46 |
return Beremiz(parent) |
|
47 |
||
48 |
def usage(): |
|
49 |
print "\nUsage of Beremiz.py :" |
|
50 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
|
51 |
||
52 |
try: |
|
53 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
54 |
except getopt.GetoptError: |
|
55 |
# print help information and exit: |
|
56 |
usage() |
|
57 |
sys.exit(2) |
|
58 |
||
59 |
for o, a in opts: |
|
60 |
if o in ("-h", "--help"): |
|
61 |
usage() |
|
62 |
sys.exit() |
|
63 |
||
64 |
projectOpen = None |
|
65 |
if len(args) > 1: |
|
66 |
usage() |
|
67 |
sys.exit() |
|
68 |
elif len(args) == 1: |
|
69 |
projectOpen = args[0] |
|
70 |
CWD = sys.path[0] |
|
71 |
||
1 | 72 |
re_texts = {} |
73 |
re_texts["letter"] = "[A-Za-z]" |
|
74 |
re_texts["digit"] = "[0-9]" |
|
75 |
LOCATED_MODEL = re.compile("__LOCATED_VAR\(([A-Z]*),([_A-Za-z0-9]*)\)") |
|
76 |
||
77 |
||
78 |
class LogPseudoFile: |
|
79 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
80 |
def __init__(self, output = None): |
|
81 |
self.output = output |
|
82 |
||
83 |
def writelines(self, l): |
|
84 |
map(self.write, l) |
|
85 |
||
86 |
def write(self, s): |
|
87 |
self.output.SetValue(self.output.GetValue() + s) |
|
88 |
||
89 |
def flush(self): |
|
90 |
self.output.SetValue("") |
|
91 |
||
92 |
def isatty(self): |
|
93 |
return false |
|
94 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
95 |
[ID_BEREMIZ, ID_BEREMIZLOGCONSOLE, ID_BEREMIZEDITPLCBUTTON, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
96 |
ID_BEREMIZBUILDBUTTON, ID_BEREMIZSIMULATEBUTTON, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
97 |
ID_BEREMIZRUNBUTTON, ID_BEREMIZBUSLIST, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
98 |
ID_BEREMIZADDBUSBUTTON, ID_BEREMIZDELETEBUSBUTTON, |
0 | 99 |
] = [wx.NewId() for _init_ctrls in range(9)] |
100 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
101 |
[ID_BEREMIZFILEMENUITEMS0, ID_BEREMIZFILEMENUITEMS1, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
102 |
ID_BEREMIZFILEMENUITEMS2, ID_BEREMIZFILEMENUITEMS3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
103 |
ID_BEREMIZFILEMENUITEMS5, ID_BEREMIZFILEMENUITEMS7, |
0 | 104 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)] |
105 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
106 |
[ID_BEREMIZEDITMENUITEMS0, ID_BEREMIZEDITMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
107 |
ID_BEREMIZEDITMENUITEMS3, |
0 | 108 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(3)] |
109 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
110 |
[ID_BEREMIZRUNMENUITEMS0, ID_BEREMIZRUNMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
111 |
ID_BEREMIZRUNMENUITEMS3, ID_BEREMIZRUNMENUITEMS5, |
0 | 112 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
113 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
114 |
[ID_BEREMIZHELPMENUITEMS0, ID_BEREMIZHELPMENUITEMS1, |
0 | 115 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
116 |
||
117 |
class Beremiz(wx.Frame): |
|
118 |
||
119 |
def _init_coll_FileMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
120 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS0, |
0 | 121 |
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
122 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS1, |
0 | 123 |
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
124 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS2, |
0 | 125 |
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
126 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS3, |
0 | 127 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
128 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
129 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS5, |
0 | 130 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
131 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
132 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS7, |
0 | 133 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
134 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
135 |
id=ID_BEREMIZFILEMENUITEMS0) |
0 | 136 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
137 |
id=ID_BEREMIZFILEMENUITEMS1) |
0 | 138 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
139 |
id=ID_BEREMIZFILEMENUITEMS2) |
0 | 140 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
141 |
id=ID_BEREMIZFILEMENUITEMS3) |
0 | 142 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
143 |
id=ID_BEREMIZFILEMENUITEMS5) |
0 | 144 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
145 |
id=ID_BEREMIZFILEMENUITEMS7) |
0 | 146 |
|
147 |
def _init_coll_EditMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
148 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS0, |
0 | 149 |
kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R') |
150 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
151 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS2, |
0 | 152 |
kind=wx.ITEM_NORMAL, text=u'Add Bus') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
153 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS3, |
0 | 154 |
kind=wx.ITEM_NORMAL, text=u'Delete Bus') |
155 |
self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
156 |
id=ID_BEREMIZEDITMENUITEMS0) |
0 | 157 |
self.Bind(wx.EVT_MENU, self.OnAddBusMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
158 |
id=ID_BEREMIZEDITMENUITEMS2) |
0 | 159 |
self.Bind(wx.EVT_MENU, self.OnDeleteBusMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
160 |
id=ID_BEREMIZEDITMENUITEMS3) |
0 | 161 |
|
162 |
def _init_coll_RunMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
163 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS0, |
0 | 164 |
kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R') |
165 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
166 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS2, |
0 | 167 |
kind=wx.ITEM_NORMAL, text=u'Simulate') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
168 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS3, |
0 | 169 |
kind=wx.ITEM_NORMAL, text=u'Run') |
170 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
171 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS5, |
0 | 172 |
kind=wx.ITEM_NORMAL, text=u'Save Log') |
1 | 173 |
self.Bind(wx.EVT_MENU, self.OnBuildMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
174 |
id=ID_BEREMIZRUNMENUITEMS0) |
0 | 175 |
self.Bind(wx.EVT_MENU, self.OnSimulateMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
176 |
id=ID_BEREMIZRUNMENUITEMS2) |
0 | 177 |
self.Bind(wx.EVT_MENU, self.OnRunMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
178 |
id=ID_BEREMIZRUNMENUITEMS3) |
0 | 179 |
self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
180 |
id=ID_BEREMIZRUNMENUITEMS5) |
0 | 181 |
|
182 |
def _init_coll_HelpMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
183 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS0, |
0 | 184 |
kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
185 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS1, |
0 | 186 |
kind=wx.ITEM_NORMAL, text=u'About') |
187 |
self.Bind(wx.EVT_MENU, self.OnBeremizMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
188 |
id=ID_BEREMIZHELPMENUITEMS0) |
0 | 189 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
190 |
id=ID_BEREMIZHELPMENUITEMS1) |
0 | 191 |
|
192 |
def _init_coll_menuBar1_Menus(self, parent): |
|
193 |
parent.Append(menu=self.FileMenu, title=u'File') |
|
194 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
|
195 |
parent.Append(menu=self.RunMenu, title=u'Run') |
|
196 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
197 |
||
198 |
def _init_utils(self): |
|
199 |
self.menuBar1 = wx.MenuBar() |
|
200 |
self.FileMenu = wx.Menu(title=u'') |
|
201 |
self.EditMenu = wx.Menu(title=u'') |
|
202 |
self.RunMenu = wx.Menu(title=u'') |
|
203 |
self.HelpMenu = wx.Menu(title=u'') |
|
204 |
||
205 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
206 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
207 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
208 |
self._init_coll_RunMenu_Items(self.RunMenu) |
|
209 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
210 |
||
211 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
212 |
parent.AddSizer(self.ControlPanelSizer, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
213 |
parent.AddWindow(self.LogConsole, 0, border=0, flag=wx.GROW) |
0 | 214 |
|
215 |
def _init_coll_MainGridSizer_Growables(self, parent): |
|
216 |
parent.AddGrowableCol(0) |
|
217 |
parent.AddGrowableRow(1) |
|
218 |
||
219 |
def _init_coll_ControlPanelSizer_Items(self, parent): |
|
220 |
parent.AddSizer(self.ControlButtonSizer, 0, border=0, flag=0) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
221 |
parent.AddWindow(self.BusList, 0, border=0, flag=wx.GROW) |
0 | 222 |
parent.AddSizer(self.BusButtonSizer, 0, border=0, flag=0) |
223 |
||
224 |
||
225 |
def _init_coll_ControlPanelSizer_Growables(self, parent): |
|
226 |
parent.AddGrowableCol(1) |
|
227 |
parent.AddGrowableRow(0) |
|
228 |
||
229 |
def _init_coll_ControlButtonSizer_Items(self, parent): |
|
230 |
parent.AddWindow(self.EditPLCButton, 0, border=0, flag=0) |
|
231 |
parent.AddWindow(self.BuildButton, 0, border=0, flag=0) |
|
232 |
parent.AddWindow(self.SimulateButton, 0, border=0, flag=0) |
|
233 |
parent.AddWindow(self.RunButton, 0, border=0, flag=0) |
|
234 |
||
235 |
def _init_coll_BusButtonSizer_Items(self, parent): |
|
236 |
parent.AddWindow(self.AddBusButton, 0, border=0, flag=0) |
|
237 |
parent.AddWindow(self.DeleteBusButton, 0, border=0, flag=0) |
|
238 |
||
239 |
def _init_sizers(self): |
|
240 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
|
241 |
self.ControlPanelSizer = wx.FlexGridSizer(cols=3, hgap=2, rows=1, vgap=2) |
|
242 |
self.ControlButtonSizer = wx.GridSizer(cols=2, hgap=2, rows=2, vgap=2) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
243 |
self.BusButtonSizer = wx.BoxSizer(wx.VERTICAL) |
0 | 244 |
|
245 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
|
246 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
247 |
self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer) |
|
248 |
self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer) |
|
249 |
self._init_coll_ControlButtonSizer_Items(self.ControlButtonSizer) |
|
250 |
self._init_coll_BusButtonSizer_Items(self.BusButtonSizer) |
|
251 |
||
252 |
self.SetSizer(self.MainGridSizer) |
|
253 |
||
254 |
def _init_ctrls(self, prnt): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
255 |
wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz', |
0 | 256 |
parent=prnt, pos=wx.Point(0, 0), size=wx.Size(600, 300), |
257 |
style=wx.DEFAULT_FRAME_STYLE, title=u'Beremiz') |
|
258 |
self._init_utils() |
|
259 |
self.SetClientSize(wx.Size(600, 300)) |
|
260 |
self.SetMenuBar(self.menuBar1) |
|
261 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
262 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
0 | 263 |
name='LogConsole', parent=self, pos=wx.Point(0, 0), |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
264 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
265 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
266 |
self.EditPLCButton = wx.Button(id=ID_BEREMIZEDITPLCBUTTON, label='Edit\nPLC', |
0 | 267 |
name='EditPLCButton', parent=self, pos=wx.Point(0, 0), |
268 |
size=wx.Size(48, 48), style=0) |
|
269 |
self.EditPLCButton.Bind(wx.EVT_BUTTON, self.OnEditPLCButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
270 |
id=ID_BEREMIZEDITPLCBUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
271 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
272 |
self.BuildButton = wx.Button(id=ID_BEREMIZBUILDBUTTON, label='Build', |
0 | 273 |
name='BuildButton', parent=self, pos=wx.Point(0, 0), |
274 |
size=wx.Size(48, 48), style=0) |
|
275 |
self.BuildButton.Bind(wx.EVT_BUTTON, self.OnBuildButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
276 |
id=ID_BEREMIZBUILDBUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
277 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
278 |
self.SimulateButton = wx.Button(id=ID_BEREMIZSIMULATEBUTTON, label='Simul', |
0 | 279 |
name='SimulateButton', parent=self, pos=wx.Point(0, 0), |
280 |
size=wx.Size(48, 48), style=0) |
|
281 |
self.EditPLCButton.Bind(wx.EVT_BUTTON, self.OnSimulateButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
282 |
id=ID_BEREMIZSIMULATEBUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
283 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
284 |
self.RunButton = wx.Button(id=ID_BEREMIZRUNBUTTON, label='Run', |
0 | 285 |
name='RunButton', parent=self, pos=wx.Point(0, 0), |
286 |
size=wx.Size(48, 48), style=0) |
|
287 |
self.RunButton.Bind(wx.EVT_BUTTON, self.OnRunButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
288 |
id=ID_BEREMIZRUNBUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
289 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
290 |
self.BusList = wx.ListBox(choices=[], id=ID_BEREMIZBUSLIST, |
0 | 291 |
name='BusList', parent=self, pos=wx.Point(0, 0), |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
292 |
size=wx.Size(-1, -1), style=wx.LB_SINGLE|wx.LB_NEEDED_SB) |
1 | 293 |
self.BusList.Bind(wx.EVT_LISTBOX_DCLICK, self.OnBusListDClick, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
294 |
id=ID_BEREMIZBUSLIST) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
295 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
296 |
self.AddBusButton = wx.Button(id=ID_BEREMIZADDBUSBUTTON, label='Add', |
0 | 297 |
name='AddBusButton', parent=self, pos=wx.Point(0, 0), |
298 |
size=wx.Size(48, 48), style=0) |
|
299 |
self.AddBusButton.Bind(wx.EVT_BUTTON, self.OnAddBusButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
300 |
id=ID_BEREMIZADDBUSBUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
301 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
302 |
self.DeleteBusButton = wx.Button(id=ID_BEREMIZDELETEBUSBUTTON, label='Delete', |
0 | 303 |
name='DeleteBusButton', parent=self, pos=wx.Point(0, 0), |
304 |
size=wx.Size(48, 48), style=0) |
|
305 |
self.DeleteBusButton.Bind(wx.EVT_BUTTON, self.OnDeleteBusButton, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
306 |
id=ID_BEREMIZDELETEBUSBUTTON) |
0 | 307 |
|
308 |
self._init_sizers() |
|
309 |
||
310 |
def __init__(self, parent): |
|
311 |
self._init_ctrls(parent) |
|
312 |
||
313 |
self.CurrentProjectPath = "" |
|
314 |
||
315 |
self.PLCManager = None |
|
316 |
self.PLCEditor = None |
|
317 |
self.BusManagers = {} |
|
318 |
||
1 | 319 |
self.Log = LogPseudoFile(self.LogConsole) |
320 |
||
0 | 321 |
self.RefreshButtons() |
322 |
self.RefreshMainMenu() |
|
323 |
||
324 |
def RefreshButtons(self): |
|
325 |
if self.CurrentProjectPath == "": |
|
326 |
self.LogConsole.Enable(False) |
|
327 |
self.EditPLCButton.Enable(False) |
|
328 |
self.BuildButton.Enable(False) |
|
329 |
self.SimulateButton.Enable(False) |
|
330 |
self.RunButton.Enable(False) |
|
331 |
self.BusList.Enable(False) |
|
332 |
self.AddBusButton.Enable(False) |
|
333 |
self.DeleteBusButton.Enable(False) |
|
334 |
else: |
|
335 |
self.LogConsole.Enable(True) |
|
336 |
self.EditPLCButton.Enable(True) |
|
337 |
self.BuildButton.Enable(True) |
|
338 |
self.SimulateButton.Enable(True) |
|
339 |
self.RunButton.Enable(True) |
|
340 |
self.BusList.Enable(True) |
|
341 |
self.AddBusButton.Enable(True) |
|
342 |
self.DeleteBusButton.Enable(True) |
|
343 |
||
344 |
def RefreshBusList(self): |
|
345 |
selected = self.BusList.GetStringSelection() |
|
346 |
self.BusList.Clear() |
|
347 |
busidlist = self.BusManagers.keys() |
|
348 |
busidlist.sort() |
|
349 |
for id in busidlist: |
|
350 |
bus_infos = self.BusManagers[id] |
|
351 |
self.BusList.Append("0x%2.2X\t%s\t%s"%(id, bus_infos["Type"], bus_infos["Name"])) |
|
352 |
if selected != "": |
|
353 |
self.BusList.SetStringSelection(selected) |
|
354 |
||
355 |
def RefreshMainMenu(self): |
|
356 |
if self.menuBar1: |
|
357 |
if self.CurrentProjectPath == "": |
|
358 |
self.menuBar1.EnableTop(1, False) |
|
359 |
self.menuBar1.EnableTop(2, False) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
360 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
361 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
362 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, False) |
0 | 363 |
else: |
364 |
self.menuBar1.EnableTop(1, True) |
|
365 |
self.menuBar1.EnableTop(2, True) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
366 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, True) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
367 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, True) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
368 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, True) |
0 | 369 |
|
370 |
def OnNewProjectMenu(self, event): |
|
371 |
if self.CurrentProjectPath != "": |
|
372 |
defaultpath = self.CurrentProjectPath |
|
373 |
else: |
|
374 |
defaultpath = os.getcwd() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
375 |
dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
376 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 377 |
projectpath = dialog.GetPath() |
378 |
dialog.Destroy() |
|
379 |
if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: |
|
380 |
os.mkdir(os.path.join(projectpath, "eds")) |
|
381 |
self.PLCManager = PLCControler() |
|
382 |
plc_file = os.path.join(projectpath, "plc.xml") |
|
383 |
dialog = ProjectDialog(self) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
384 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 385 |
values = dialog.GetValues() |
386 |
projectname = values.pop("projectName") |
|
387 |
values["creationDateTime"] = datetime(*localtime()[:6]) |
|
388 |
self.PLCManager.CreateNewProject(projectname) |
|
389 |
self.PLCManager.SetProjectProperties(values) |
|
390 |
self.PLCManager.SaveXMLFile(plc_file) |
|
391 |
self.CurrentProjectPath = projectpath |
|
392 |
dialog.Destroy() |
|
393 |
self.RefreshButtons() |
|
394 |
self.RefreshMainMenu() |
|
395 |
else: |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
396 |
message = wx.MessageDialog(self, "Folder choosen isn't empty. You can't use it for a new project!", "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 397 |
message.ShowModal() |
398 |
message.Destroy() |
|
399 |
event.Skip() |
|
400 |
||
401 |
def OnOpenProjectMenu(self, event): |
|
402 |
if self.CurrentProjectPath != "": |
|
403 |
defaultpath = self.CurrentProjectPath |
|
404 |
else: |
|
405 |
defaultpath = os.getcwd() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
406 |
dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
407 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 408 |
projectpath = dialog.GetPath() |
409 |
dialog.Destroy() |
|
2 | 410 |
try: |
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
411 |
if not os.path.isdir(projectpath): |
2 | 412 |
raise Exception |
0 | 413 |
self.BusManagers = {} |
414 |
configpath = os.path.join(projectpath, ".project") |
|
2 | 415 |
if not os.path.isfile(configpath): |
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
416 |
raise Exception |
2 | 417 |
file = open(configpath, "r") |
418 |
lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
|
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
419 |
if lines[0] != "Beremiz": |
2 | 420 |
file.close() |
421 |
raise Exception |
|
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
422 |
for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]: |
2 | 423 |
id = int(bus_id, 16) |
424 |
if bus_type == "CanFestival": |
|
425 |
manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
426 |
nodelist = NodeList(manager) |
|
427 |
result = nodelist.LoadProject(projectpath, bus_name) |
|
428 |
if not result: |
|
429 |
self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} |
|
0 | 430 |
else: |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
431 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
2 | 432 |
message.ShowModal() |
433 |
message.Destroy() |
|
434 |
else: |
|
435 |
self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} |
|
436 |
file.close() |
|
0 | 437 |
self.PLCManager = PLCControler() |
438 |
plc_file = os.path.join(projectpath, "plc.xml") |
|
439 |
if os.path.isfile(plc_file): |
|
440 |
self.PLCManager.OpenXMLFile(plc_file) |
|
441 |
self.CurrentProjectPath = projectpath |
|
442 |
else: |
|
443 |
dialog = ProjectDialog(self) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
444 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 445 |
values = dialog.GetValues() |
446 |
projectname = values.pop("projectName") |
|
447 |
values["creationDateTime"] = datetime(*localtime()[:6]) |
|
448 |
self.PLCManager.CreateNewProject(projectname) |
|
449 |
self.PLCManager.SetProjectProperties(values) |
|
450 |
self.PLCManager.SaveXMLFile(plc_file) |
|
451 |
self.CurrentProjectPath = projectpath |
|
452 |
dialog.Destroy() |
|
453 |
self.RefreshBusList() |
|
454 |
self.RefreshButtons() |
|
455 |
self.RefreshMainMenu() |
|
2 | 456 |
except Exception: |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
457 |
message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR) |
2 | 458 |
message.ShowModal() |
459 |
message.Destroy() |
|
0 | 460 |
event.Skip() |
461 |
||
462 |
def OnCloseProjectMenu(self, event): |
|
463 |
self.PLCManager = None |
|
464 |
self.CurrentProjectPath = projectpath |
|
465 |
self.RefreshButtons() |
|
466 |
self.RefreshMainMenu() |
|
467 |
event.Skip() |
|
468 |
||
469 |
def OnSaveProjectMenu(self, event): |
|
470 |
self.PLCManager.SaveXMLFile() |
|
471 |
cpjfilepath = os.path.join(self.CurrentProjectPath, "nodelist.cpj") |
|
472 |
file = open(cpjfilepath, "w") |
|
473 |
file.write("") |
|
474 |
file.close() |
|
475 |
configpath = os.path.join(self.CurrentProjectPath, ".project") |
|
476 |
file = open(configpath, "w") |
|
3
6d8728efcdec
Adding validity verifications on project folders opened
lbessard
parents:
2
diff
changeset
|
477 |
file.write("Beremiz\n") |
0 | 478 |
busidlist = self.BusManagers.keys() |
479 |
busidlist.sort() |
|
480 |
for id in busidlist: |
|
481 |
bus_infos = self.BusManagers[id] |
|
482 |
file.write("0x%2.2X %s %s\n"%(id, bus_infos["Type"], bus_infos["Name"])) |
|
483 |
bus_infos["NodeList"].SaveProject(bus_infos["Name"]) |
|
484 |
file.close() |
|
485 |
event.Skip() |
|
486 |
||
487 |
def OnPropertiesMenu(self, event): |
|
488 |
event.Skip() |
|
489 |
||
490 |
def OnQuitMenu(self, event): |
|
491 |
self.Close() |
|
492 |
event.Skip() |
|
493 |
||
494 |
def OnEditPLCMenu(self, event): |
|
495 |
self.EditPLC() |
|
496 |
event.Skip() |
|
497 |
||
498 |
def OnAddBusMenu(self, event): |
|
499 |
self.AddBus() |
|
500 |
event.Skip() |
|
501 |
||
502 |
def OnDeleteBusMenu(self, event): |
|
503 |
self.DeleteBus() |
|
504 |
event.Skip() |
|
505 |
||
1 | 506 |
def OnBuildMenu(self, event): |
507 |
self.BuildAutom() |
|
508 |
event.Skip() |
|
509 |
||
0 | 510 |
def OnSimulateMenu(self, event): |
511 |
event.Skip() |
|
512 |
||
513 |
def OnRunMenu(self, event): |
|
514 |
event.Skip() |
|
515 |
||
516 |
def OnSaveLogMenu(self, event): |
|
517 |
event.Skip() |
|
518 |
||
519 |
def OnBeremizMenu(self, event): |
|
520 |
event.Skip() |
|
521 |
||
522 |
def OnAboutMenu(self, event): |
|
523 |
event.Skip() |
|
524 |
||
525 |
def OnEditPLCButton(self, event): |
|
526 |
self.EditPLC() |
|
527 |
event.Skip() |
|
528 |
||
529 |
def OnBuildButton(self, event): |
|
1 | 530 |
self.BuildAutom() |
0 | 531 |
event.Skip() |
532 |
||
533 |
def OnSimulateButton(self, event): |
|
534 |
event.Skip() |
|
535 |
||
536 |
def OnRunButton(self, event): |
|
537 |
event.Skip() |
|
538 |
||
539 |
def OnAddBusButton(self, event): |
|
540 |
self.AddBus() |
|
541 |
event.Skip() |
|
542 |
||
543 |
def OnDeleteBusButton(self, event): |
|
544 |
self.DeleteBus() |
|
545 |
event.Skip() |
|
546 |
||
547 |
def OnBusListDClick(self, event): |
|
1 | 548 |
selected = event.GetSelection() |
0 | 549 |
busidlist = self.BusManagers.keys() |
550 |
busidlist.sort() |
|
551 |
bus_infos = self.BusManagers[busidlist[selected]] |
|
552 |
if bus_infos["Type"] == "CanFestival": |
|
553 |
if bus_infos["Editor"] == None: |
|
554 |
netedit = networkedit(self, bus_infos["NodeList"]) |
|
555 |
netedit.SetBusId(busidlist[selected]) |
|
556 |
netedit.Show() |
|
557 |
bus_infos["Editor"] = netedit |
|
558 |
event.Skip() |
|
559 |
||
560 |
def CloseEditor(self, bus_id): |
|
561 |
if self.BusManagers.get(bus_id, None) != None: |
|
562 |
self.BusManagers[bus_id]["Editor"] = None |
|
563 |
||
564 |
def AddBus(self): |
|
565 |
dialog = AddBusDialog(self) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
566 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 567 |
values = dialog.GetValues() |
568 |
if values["busID"].startswith("0x"): |
|
569 |
bus_id = int(values["busID"], 16) |
|
570 |
else: |
|
571 |
bus_id = int(values["busID"]) |
|
572 |
if self.BusManagers.get(bus_id, None) == None: |
|
573 |
if values["busType"] == "CanFestival": |
|
574 |
manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
575 |
nodelist = NodeList(manager) |
|
576 |
result = nodelist.LoadProject(self.CurrentProjectPath, values["busName"]) |
|
577 |
if not result: |
|
578 |
self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"], "NodeList" : nodelist, "Editor" : None} |
|
579 |
else: |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
580 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
0 | 581 |
message.ShowModal() |
582 |
message.Destroy() |
|
583 |
else: |
|
584 |
self.BusManagers[bus_id] = {"Name" : values["busName"], "Type" : values["busType"]} |
|
585 |
else: |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
586 |
message = wx.MessageDialog(self, "The bus ID \"0x%2.2X\" is already used!"%bus_id, "Error", wx.OK|wx.ICON_ERROR) |
0 | 587 |
message.ShowModal() |
588 |
message.Destroy() |
|
589 |
self.RefreshBusList() |
|
590 |
dialog.Destroy() |
|
591 |
||
592 |
def DeleteBus(self): |
|
593 |
busidlist = self.BusManagers.keys() |
|
594 |
busidlist.sort() |
|
595 |
list = ["0x%2.2X\t%s\t%s"%(id, self.BusManagers[id]["Type"], self.BusManagers[id]["Name"]) for id in busidlist] |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
596 |
dialog = wx.SingleChoiceDialog(self, "Select Bus to delete:", "Bus Delete", list, wx.OK|wx.CANCEL) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
597 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 598 |
selected = dialog.GetSelection() |
599 |
editor = self.BusManagers[busidlist[selected]]["Editor"] |
|
600 |
if editor: |
|
601 |
editor.Close() |
|
602 |
self.BusManagers.pop(busidlist[selected]) |
|
603 |
self.RefreshBusList() |
|
604 |
dialog.Destroy() |
|
605 |
||
606 |
def EditPLC(self): |
|
607 |
if not self.PLCEditor: |
|
608 |
self.PLCEditor = PLCOpenEditor(self, self.PLCManager) |
|
609 |
self.PLCEditor.RefreshProjectTree() |
|
610 |
self.PLCEditor.RefreshFileMenu() |
|
611 |
self.PLCEditor.RefreshEditMenu() |
|
612 |
self.PLCEditor.RefreshToolBar() |
|
613 |
self.PLCEditor.Show() |
|
614 |
||
1 | 615 |
def BuildAutom(self): |
616 |
if self.PLCManager: |
|
617 |
self.TargetDir = os.path.join(self.CurrentProjectPath, "build") |
|
618 |
if not os.path.exists(self.TargetDir): |
|
619 |
os.mkdir(self.TargetDir) |
|
620 |
self.Log.flush() |
|
621 |
sys.stdout = self.Log |
|
622 |
try: |
|
623 |
print "Building ST Program..." |
|
624 |
plc_file = os.path.join(self.TargetDir, "plc.st") |
|
625 |
result = self.PLCManager.GenerateProgram(plc_file) |
|
626 |
if not result: |
|
627 |
raise Exception |
|
628 |
print "Compiling ST Program in to C Program..." |
|
629 |
status, result = commands.getstatusoutput("../matiec/iec2cc %s -I ../matiec/lib %s"%(plc_file, self.TargetDir)) |
|
630 |
if status: |
|
631 |
print result |
|
632 |
raise Exception |
|
633 |
print "Extracting Located Variables..." |
|
634 |
location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h")) |
|
635 |
locations = [] |
|
636 |
lines = [line.strip() for line in location_file.readlines()] |
|
637 |
for line in lines: |
|
638 |
result = LOCATED_MODEL.match(line) |
|
639 |
if result: |
|
640 |
locations.append(result.groups()) |
|
641 |
print "Generating Network Configurations..." |
|
642 |
for bus_id, bus_infos in self.BusManagers.items(): |
|
643 |
if bus_infos["Type"] == "CanFestival": |
|
644 |
master = config_utils.GenerateConciseDCF(locations, bus_id, bus_infos["NodeList"]) |
|
645 |
result = gen_cfile.GenerateFile("%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])), master) |
|
646 |
if result: |
|
647 |
raise Exception |
|
648 |
print "Generating Makefiles..." |
|
649 |
||
650 |
print "Compiling Project..." |
|
651 |
||
652 |
print "\nBuild Project completed" |
|
653 |
except Exception, message: |
|
654 |
pass |
|
655 |
sys.stdout = sys.__stdout__ |
|
656 |
||
0 | 657 |
#------------------------------------------------------------------------------- |
658 |
# Add Bus Dialog |
|
659 |
#------------------------------------------------------------------------------- |
|
660 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
661 |
[ID_ADDBUSDIALOG, ID_ADDBUSDIALOGBUSID, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
662 |
ID_ADDBUSDIALOGBUSNAME, ID_ADDBUSDIALOGBUSTYPE, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
663 |
ID_ADDBUSDIALOGSTATICTEXT1, ID_ADDBUSDIALOGSTATICTEXT2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
664 |
ID_ADDBUSDIALOGSTATICTEXT3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
665 |
] = [wx.NewId() for _init_ctrls in range(7)] |
0 | 666 |
|
667 |
class AddBusDialog(wx.Dialog): |
|
668 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
669 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
670 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
671 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
672 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
673 |
parent.AddGrowableCol(0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
674 |
parent.AddGrowableRow(0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
675 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
676 |
def _init_coll_MainSizer_Items(self, parent): |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
677 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
678 |
parent.AddWindow(self.BusId, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
679 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
680 |
parent.AddWindow(self.BusType, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
681 |
parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
682 |
parent.AddWindow(self.BusName, 0, border=0, flag=wx.GROW) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
683 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
684 |
def _init_coll_MainSizer_Growables(self, parent): |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
685 |
parent.AddGrowableCol(1) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
686 |
|
0 | 687 |
def _init_sizers(self): |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
688 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
689 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=3, vgap=15) |
0 | 690 |
|
691 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
692 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
693 |
self._init_coll_MainSizer_Items(self.MainSizer) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
694 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 695 |
|
696 |
self.SetSizer(self.flexGridSizer1) |
|
697 |
||
698 |
def _init_ctrls(self, prnt): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
699 |
wx.Dialog.__init__(self, id=ID_ADDBUSDIALOG, |
0 | 700 |
name='PouDialog', parent=prnt, pos=wx.Point(376, 183), |
701 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
|
702 |
title='Create a new POU') |
|
703 |
self.SetClientSize(wx.Size(300, 200)) |
|
704 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
705 |
self.staticText1 = wx.StaticText(id=ID_ADDBUSDIALOGSTATICTEXT1, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
706 |
label='Bus ID:', name='staticText1', parent=self, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
707 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
708 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
709 |
self.BusId = wx.TextCtrl(id=ID_ADDBUSDIALOGBUSID, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
710 |
name='BusId', parent=self, pos=wx.Point(0, 0), |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
711 |
size=wx.Size(0, 24), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
712 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
713 |
self.staticText2 = wx.StaticText(id=ID_ADDBUSDIALOGSTATICTEXT2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
714 |
label='Bus Type:', name='staticText2', parent=self, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
715 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
716 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
717 |
self.BusType = wx.Choice(id=ID_ADDBUSDIALOGBUSTYPE, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
718 |
name='BusType', parent=self, pos=wx.Point(0, 0), |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
719 |
size=wx.Size(0, 24), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
720 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
721 |
self.staticText3 = wx.StaticText(id=ID_ADDBUSDIALOGSTATICTEXT3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
722 |
label='Bus Name:', name='staticText3', parent=self, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
723 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
724 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
725 |
self.BusName = wx.TextCtrl(id=ID_ADDBUSDIALOGBUSNAME, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
726 |
name='BusName', parent=self, pos=wx.Point(0, 0), |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
727 |
size=wx.Size(0, 24), style=0) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
728 |
|
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
729 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
730 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
0 | 731 |
|
732 |
self._init_sizers() |
|
733 |
||
734 |
def __init__(self, parent): |
|
735 |
self._init_ctrls(parent) |
|
736 |
||
737 |
for option in ["CanFestival","SVGUI"]: |
|
738 |
self.BusType.Append(option) |
|
739 |
||
740 |
def OnOK(self, event): |
|
741 |
error = [] |
|
742 |
bus_id = self.BusId.GetValue() |
|
743 |
if bus_id == "": |
|
744 |
error.append("Bus ID") |
|
745 |
if self.BusType.GetStringSelection() == "": |
|
746 |
error.append("Bus Type") |
|
747 |
if self.BusName.GetValue() == "": |
|
748 |
error.append("Bus Name") |
|
749 |
if len(error) > 0: |
|
750 |
text = "" |
|
751 |
for i, item in enumerate(error): |
|
752 |
if i == 0: |
|
753 |
text += item |
|
754 |
elif i == len(error) - 1: |
|
755 |
text += " and %s"%item |
|
756 |
else: |
|
757 |
text += ", %s"%item |
|
758 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
759 |
message.ShowModal() |
|
760 |
message.Destroy() |
|
761 |
elif bus_id.startswith("0x"): |
|
762 |
try: |
|
763 |
bus_id = int(bus_id, 16) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
764 |
self.EndModal(wx.ID_OK) |
0 | 765 |
except: |
766 |
message = wxMessageDialog(self, "Bus ID must be a decimal or hexadecimal number!", "Error", wxOK|wxICON_ERROR) |
|
767 |
message.ShowModal() |
|
768 |
message.Destroy() |
|
769 |
elif not bus_id.startswith("-"): |
|
770 |
try: |
|
771 |
bus_id = int(bus_id) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
772 |
self.EndModal(wx.ID_OK) |
0 | 773 |
except: |
774 |
message = wxMessageDialog(self, "Bus ID must be a decimal or hexadecimal number!", "Error", wxOK|wxICON_ERROR) |
|
775 |
message.ShowModal() |
|
776 |
message.Destroy() |
|
777 |
else: |
|
778 |
message = wxMessageDialog(self, "Bus Id must be greater than 0!", "Error", wxOK|wxICON_ERROR) |
|
779 |
message.ShowModal() |
|
780 |
message.Destroy() |
|
781 |
||
782 |
def SetValues(self, values): |
|
783 |
for item, value in values.items(): |
|
784 |
if item == "busID": |
|
785 |
self.BusID.SetValue(value) |
|
786 |
elif item == "busType": |
|
787 |
self.BusType.SetStringSelection(value) |
|
788 |
elif item == "busName": |
|
789 |
self.BusName.SetValue(value) |
|
790 |
||
791 |
def GetValues(self): |
|
792 |
values = {} |
|
793 |
values["busID"] = self.BusId.GetValue() |
|
794 |
values["busType"] = self.BusType.GetStringSelection() |
|
795 |
values["busName"] = self.BusName.GetValue() |
|
796 |
return values |
|
797 |
||
798 |
#------------------------------------------------------------------------------- |
|
799 |
# Exception Handler |
|
800 |
#------------------------------------------------------------------------------- |
|
801 |
||
802 |
Max_Traceback_List_Size = 20 |
|
803 |
||
804 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
805 |
trcbck_lst = [] |
|
806 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
807 |
trcbck = " " + str(i+1) + ". " |
|
808 |
if line[0].find(os.getcwd()) == -1: |
|
809 |
trcbck += "file : " + str(line[0]) + ", " |
|
810 |
else: |
|
811 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
812 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
813 |
trcbck_lst.append(trcbck) |
|
814 |
||
815 |
# Allow clicking.... |
|
816 |
cap = wx.Window_GetCapture() |
|
817 |
if cap: |
|
818 |
cap.ReleaseMouse() |
|
819 |
||
820 |
dlg = wx.SingleChoiceDialog(None, |
|
821 |
""" |
|
822 |
An error happens. |
|
823 |
||
824 |
Click on OK for saving an error report. |
|
825 |
||
826 |
Please contact LOLITech at: |
|
827 |
+33 (0)3 29 52 95 67 |
|
828 |
bugs_Beremiz@lolitech.fr |
|
829 |
||
830 |
||
831 |
Error: |
|
832 |
""" + |
|
833 |
str(e_type) + " : " + str(e_value), |
|
834 |
"Error", |
|
835 |
trcbck_lst) |
|
836 |
try: |
|
837 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
838 |
finally: |
|
839 |
dlg.Destroy() |
|
840 |
||
841 |
return res |
|
842 |
||
843 |
def Display_Error_Dialog(e_value): |
|
844 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
845 |
message.ShowModal() |
|
846 |
message.Destroy() |
|
847 |
||
848 |
def get_last_traceback(tb): |
|
849 |
while tb.tb_next: |
|
850 |
tb = tb.tb_next |
|
851 |
return tb |
|
852 |
||
853 |
||
854 |
def format_namespace(d, indent=' '): |
|
855 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
856 |
||
857 |
||
858 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
859 |
||
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
860 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 861 |
|
862 |
def handle_exception(e_type, e_value, e_traceback): |
|
863 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
864 |
last_tb = get_last_traceback(e_traceback) |
|
865 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
866 |
if str(e_value).startswith("!!!"): |
|
867 |
Display_Error_Dialog(e_value) |
|
868 |
elif ex not in ignored_exceptions: |
|
869 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
870 |
if result: |
|
871 |
ignored_exceptions.append(ex) |
|
872 |
info = { |
|
873 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
874 |
'app-version' : app_version, |
|
875 |
'wx-version' : wx.VERSION_STRING, |
|
876 |
'wx-platform' : wx.Platform, |
|
877 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
878 |
'platform' : platform.platform(), |
|
879 |
'e-type' : e_type, |
|
880 |
'e-value' : e_value, |
|
881 |
'date' : time.ctime(), |
|
882 |
'cwd' : os.getcwd(), |
|
883 |
} |
|
884 |
if e_traceback: |
|
885 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
886 |
last_tb = get_last_traceback(e_traceback) |
|
887 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
888 |
info['locals'] = format_namespace(exception_locals) |
|
889 |
if 'self' in exception_locals: |
|
890 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
891 |
||
892 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
893 |
lst = info.keys() |
|
894 |
lst.sort() |
|
895 |
for a in lst: |
|
896 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
897 |
||
898 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
899 |
sys.excepthook = handle_exception |
|
900 |
||
901 |
if __name__ == '__main__': |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
902 |
app = wx.PySimpleApp() |
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
903 |
wx.InitAllImageHandlers() |
0 | 904 |
|
905 |
# Install a exception handle for bug reports |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
906 |
AddExceptHook(os.getcwd(),__version__) |
0 | 907 |
|
908 |
frame = Beremiz(None) |
|
909 |
||
910 |
frame.Show() |
|
911 |
app.MainLoop() |