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