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