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