author | etisserant |
Fri, 07 Sep 2007 10:19:04 +0200 | |
changeset 22 | 9a0c535c3272 |
parent 21 | bded6d31365c |
child 23 | e007d9d466d7 |
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 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
29 |
import types |
0 | 30 |
|
1 | 31 |
import os, re, platform, sys, time, traceback, getopt, commands |
20 | 32 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
33 |
from plugger import PluginsRoot |
0 | 34 |
|
21 | 35 |
def CHECK_WX_VERSION(major, minor, release): |
36 |
return not (wx.MAJOR_VERSION < major or wx.MINOR_VERSION < minor or wx.RELEASE_NUMBER < release) |
|
37 |
||
1 | 38 |
class LogPseudoFile: |
39 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
40 |
def __init__(self, output = None): |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
41 |
self.red_white = wx.TextAttr("RED", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
42 |
self.red_yellow = wx.TextAttr("RED", "YELLOW") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
43 |
self.black_white = wx.TextAttr("BLACK", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
44 |
self.default_style = None |
1 | 45 |
self.output = output |
46 |
||
47 |
def writelines(self, l): |
|
48 |
map(self.write, l) |
|
49 |
||
22 | 50 |
def write(self, s, style = None): |
51 |
if not style : style=self.black_white |
|
52 |
if self.default_style != style: |
|
53 |
self.output.SetDefaultStyle(style) |
|
54 |
self.default_style = style |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
55 |
self.output.AppendText(s) |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
56 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
57 |
def write_warning(self, s): |
22 | 58 |
self.write(s,self.red_white) |
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
59 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
60 |
def write_error(self, s): |
22 | 61 |
self.write(s,self.red_yellow) |
1 | 62 |
|
63 |
def flush(self): |
|
64 |
self.output.SetValue("") |
|
65 |
||
66 |
def isatty(self): |
|
67 |
return false |
|
68 |
||
20 | 69 |
def LogCommand(self, Command, sz_limit = 100): |
70 |
||
71 |
import os, popen2, fcntl, select, signal |
|
72 |
||
73 |
child = popen2.Popen3(Command, 1) # capture stdout and stderr from command |
|
74 |
child.tochild.close() # don't need to talk to child |
|
75 |
outfile = child.fromchild |
|
76 |
outfd = outfile.fileno() |
|
77 |
errfile = child.childerr |
|
78 |
errfd = errfile.fileno() |
|
79 |
outdata = errdata = '' |
|
80 |
outeof = erreof = 0 |
|
81 |
outlen = errlen = 0 |
|
82 |
while 1: |
|
83 |
ready = select.select([outfd,errfd],[],[]) # wait for input |
|
84 |
if outfd in ready[0]: |
|
85 |
outchunk = outfile.readline() |
|
86 |
if outchunk == '': outeof = 1 |
|
87 |
else : outlen += 1 |
|
88 |
outdata += outchunk |
|
89 |
self.write(outchunk) |
|
90 |
if errfd in ready[0]: |
|
91 |
errchunk = errfile.readline() |
|
92 |
if errchunk == '': erreof = 1 |
|
93 |
else : errlen += 1 |
|
94 |
errdata += errchunk |
|
95 |
self.write_warning(errchunk) |
|
96 |
if outeof and erreof : break |
|
97 |
if errlen > sz_limit or outlen > sz_limit : |
|
98 |
os.kill(child.pid, signal.SIGTERM) |
|
99 |
self.write_error("Output size reached limit -- killed\n") |
|
100 |
break |
|
101 |
err = child.wait() |
|
102 |
return (err, outdata, errdata) |
|
103 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
104 |
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
105 |
ID_BEREMIZSECONDSPLITTER, ID_BEREMIZLEFTPANEL, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
106 |
ID_BEREMIZPARAMSPANEL, ID_BEREMIZLOGCONSOLE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
107 |
ID_BEREMIZPLUGINTREE, ID_BEREMIZPLUGINCHILDS, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
108 |
ID_BEREMIZADDBUTTON, ID_BEREMIZDELETEBUTTON, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
109 |
ID_BEREMIZPARAMSSTATICBOX, ID_BEREMIZPARAMSENABLE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
110 |
ID_BEREMIZPARAMSTARGETTYPE, ID_BEREMIZPARAMSIECCHANNEL, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
111 |
ID_BEREMIZPARAMSSTATICTEXT1, ID_BEREMIZPARAMSSTATICTEXT2, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
112 |
ID_BEREMIZPARAMSATTRIBUTESGRID, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
113 |
] = [wx.NewId() for _init_ctrls in range(17)] |
0 | 114 |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
115 |
[ID_BEREMIZFILEMENUITEMS0, ID_BEREMIZFILEMENUITEMS1, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
116 |
ID_BEREMIZFILEMENUITEMS2, ID_BEREMIZFILEMENUITEMS3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
117 |
ID_BEREMIZFILEMENUITEMS5, ID_BEREMIZFILEMENUITEMS7, |
0 | 118 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)] |
119 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
120 |
[ID_BEREMIZEDITMENUITEMS0, ID_BEREMIZEDITMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
121 |
ID_BEREMIZEDITMENUITEMS3, |
0 | 122 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(3)] |
123 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
124 |
[ID_BEREMIZRUNMENUITEMS0, ID_BEREMIZRUNMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
125 |
ID_BEREMIZRUNMENUITEMS3, ID_BEREMIZRUNMENUITEMS5, |
0 | 126 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
127 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
128 |
[ID_BEREMIZHELPMENUITEMS0, ID_BEREMIZHELPMENUITEMS1, |
0 | 129 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
130 |
||
131 |
class Beremiz(wx.Frame): |
|
132 |
||
133 |
def _init_coll_FileMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
134 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS0, |
0 | 135 |
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
|
136 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS1, |
0 | 137 |
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
|
138 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS2, |
0 | 139 |
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
|
140 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS3, |
0 | 141 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
142 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
143 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS5, |
0 | 144 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
145 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
146 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS7, |
0 | 147 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
148 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
149 |
id=ID_BEREMIZFILEMENUITEMS0) |
0 | 150 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
151 |
id=ID_BEREMIZFILEMENUITEMS1) |
0 | 152 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
153 |
id=ID_BEREMIZFILEMENUITEMS2) |
0 | 154 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
155 |
id=ID_BEREMIZFILEMENUITEMS3) |
0 | 156 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
157 |
id=ID_BEREMIZFILEMENUITEMS5) |
0 | 158 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
159 |
id=ID_BEREMIZFILEMENUITEMS7) |
0 | 160 |
|
161 |
def _init_coll_EditMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
162 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS0, |
0 | 163 |
kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R') |
164 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
165 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS2, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
166 |
kind=wx.ITEM_NORMAL, text=u'Add Plugin') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
167 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS3, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
168 |
kind=wx.ITEM_NORMAL, text=u'Delete Plugin') |
0 | 169 |
self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
170 |
id=ID_BEREMIZEDITMENUITEMS0) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
171 |
self.Bind(wx.EVT_MENU, self.OnAddMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
172 |
id=ID_BEREMIZEDITMENUITEMS2) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
173 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
174 |
id=ID_BEREMIZEDITMENUITEMS3) |
0 | 175 |
|
176 |
def _init_coll_RunMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
177 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS0, |
0 | 178 |
kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R') |
179 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
180 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS2, |
0 | 181 |
kind=wx.ITEM_NORMAL, text=u'Simulate') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
182 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS3, |
0 | 183 |
kind=wx.ITEM_NORMAL, text=u'Run') |
184 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
185 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS5, |
0 | 186 |
kind=wx.ITEM_NORMAL, text=u'Save Log') |
1 | 187 |
self.Bind(wx.EVT_MENU, self.OnBuildMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
188 |
id=ID_BEREMIZRUNMENUITEMS0) |
0 | 189 |
self.Bind(wx.EVT_MENU, self.OnSimulateMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
190 |
id=ID_BEREMIZRUNMENUITEMS2) |
0 | 191 |
self.Bind(wx.EVT_MENU, self.OnRunMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
192 |
id=ID_BEREMIZRUNMENUITEMS3) |
0 | 193 |
self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
194 |
id=ID_BEREMIZRUNMENUITEMS5) |
0 | 195 |
|
196 |
def _init_coll_HelpMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
197 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS0, |
0 | 198 |
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
|
199 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS1, |
0 | 200 |
kind=wx.ITEM_NORMAL, text=u'About') |
201 |
self.Bind(wx.EVT_MENU, self.OnBeremizMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
202 |
id=ID_BEREMIZHELPMENUITEMS0) |
0 | 203 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
204 |
id=ID_BEREMIZHELPMENUITEMS1) |
0 | 205 |
|
206 |
def _init_coll_menuBar1_Menus(self, parent): |
|
207 |
parent.Append(menu=self.FileMenu, title=u'File') |
|
208 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
|
209 |
parent.Append(menu=self.RunMenu, title=u'Run') |
|
210 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
211 |
||
212 |
def _init_utils(self): |
|
213 |
self.menuBar1 = wx.MenuBar() |
|
214 |
self.FileMenu = wx.Menu(title=u'') |
|
215 |
self.EditMenu = wx.Menu(title=u'') |
|
216 |
self.RunMenu = wx.Menu(title=u'') |
|
217 |
self.HelpMenu = wx.Menu(title=u'') |
|
218 |
||
219 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
220 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
221 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
222 |
self._init_coll_RunMenu_Items(self.RunMenu) |
|
223 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
224 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
225 |
def _init_coll_LeftGridSizer_Items(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
226 |
parent.AddWindow(self.PluginTree, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
227 |
parent.AddSizer(self.ButtonGridSizer, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
228 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
229 |
def _init_coll_LeftGridSizer_Growables(self, parent): |
0 | 230 |
parent.AddGrowableCol(0) |
231 |
parent.AddGrowableRow(0) |
|
232 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
233 |
def _init_coll_ButtonGridSizer_Items(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
234 |
parent.AddWindow(self.PluginChilds, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
235 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
236 |
parent.AddWindow(self.DeleteButton, 0, border=0, flag=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
237 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
238 |
def _init_coll_ButtonGridSizer_Growables(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
239 |
parent.AddGrowableCol(0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
240 |
parent.AddGrowableRow(0) |
0 | 241 |
|
242 |
def _init_sizers(self): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
243 |
self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
244 |
self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=2, rows=1, vgap=2) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
245 |
self.ParamsPanelMainSizer = wx.BoxSizer(wx.VERTICAL) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
246 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
247 |
self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
248 |
self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
249 |
self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
250 |
self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
251 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
252 |
self.LeftPanel.SetSizer(self.LeftGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
253 |
self.ParamsPanel.SetSizer(self.ParamsPanelMainSizer) |
0 | 254 |
|
255 |
def _init_ctrls(self, prnt): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
256 |
wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz', |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
257 |
parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600), |
0 | 258 |
style=wx.DEFAULT_FRAME_STYLE, title=u'Beremiz') |
259 |
self._init_utils() |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
260 |
self.SetClientSize(wx.Size(1000, 600)) |
0 | 261 |
self.SetMenuBar(self.menuBar1) |
262 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
263 |
self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
264 |
name='MainSplitter', parent=self, point=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
265 |
size=wx.Size(0, 0), style=wx.SP_3D) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
266 |
self.MainSplitter.SetNeedUpdating(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
267 |
self.MainSplitter.SetMinimumPaneSize(1) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
268 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
269 |
self.LeftPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
270 |
name='LeftPanel', parent=self.MainSplitter, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
271 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
272 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
273 |
self.PluginTree = wx.TreeCtrl(id=ID_BEREMIZPLUGINTREE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
274 |
name='PluginTree', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
275 |
size=wx.Size(-1, -1), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
276 |
self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
277 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
278 |
id=ID_BEREMIZPLUGINTREE) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
279 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
280 |
self.PluginChilds = wx.Choice(id=ID_BEREMIZPLUGINCHILDS, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
281 |
name='PluginChilds', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
282 |
size=wx.Size(-1, -1), style=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
283 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
284 |
self.AddButton = wx.Button(id=ID_BEREMIZADDBUTTON, label='Add', |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
285 |
name='AddBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
286 |
size=wx.Size(48, 30), style=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
287 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButton, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
288 |
id=ID_BEREMIZADDBUTTON) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
289 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
290 |
self.DeleteButton = wx.Button(id=ID_BEREMIZDELETEBUTTON, label='Delete', |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
291 |
name='DeleteBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
292 |
size=wx.Size(64, 30), style=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
293 |
self.DeleteButton.Bind(wx.EVT_BUTTON, self.OnDeleteButton, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
294 |
id=ID_BEREMIZDELETEBUTTON) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
295 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
296 |
self.SecondSplitter = wx.SplitterWindow(id=ID_BEREMIZSECONDSPLITTER, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
297 |
name='SecondSplitter', parent=self.MainSplitter, point=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
298 |
size=wx.Size(0, 0), style=wx.SP_3D) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
299 |
self.SecondSplitter.SetNeedUpdating(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
300 |
self.SecondSplitter.SetMinimumPaneSize(1) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
301 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
302 |
self.MainSplitter.SplitVertically(self.LeftPanel, self.SecondSplitter, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
303 |
300) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
304 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
305 |
self.ParamsPanel = wx.ScrolledWindow(id=ID_BEREMIZPARAMSPANEL, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
306 |
name='ParamsPanel', parent=self.SecondSplitter, pos=wx.Point(0, 0), |
21 | 307 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
308 |
self.ParamsPanel.SetScrollbars(10, 10, 0, 0, 0, 0) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
309 |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
310 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
311 |
name='LogConsole', parent=self.SecondSplitter, pos=wx.Point(0, 0), |
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
312 |
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
|
313 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
314 |
self.SecondSplitter.SplitHorizontally(self.ParamsPanel, self.LogConsole, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
315 |
-250) |
0 | 316 |
|
317 |
self._init_sizers() |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
318 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
319 |
def __init__(self, parent, projectOpen): |
0 | 320 |
self._init_ctrls(parent) |
321 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
322 |
self.Log = LogPseudoFile(self.LogConsole) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
323 |
|
20 | 324 |
self.PluginRoot = PluginsRoot(self) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
325 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
326 |
if projectOpen: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
327 |
self.PluginRoot.LoadProject(projectOpen) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
328 |
self.RefreshPluginTree() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
329 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
330 |
self.RefreshPluginParams() |
0 | 331 |
self.RefreshButtons() |
332 |
self.RefreshMainMenu() |
|
333 |
||
334 |
def RefreshButtons(self): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
335 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
336 |
self.PluginChilds.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
337 |
self.AddButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
338 |
self.DeleteButton.Enable(True) |
0 | 339 |
else: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
340 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
341 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
342 |
self.DeleteButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
343 |
|
0 | 344 |
def RefreshMainMenu(self): |
345 |
if self.menuBar1: |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
346 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
347 |
self.menuBar1.EnableTop(1, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
348 |
self.menuBar1.EnableTop(2, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
349 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
350 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
351 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
352 |
else: |
0 | 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) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
358 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
359 |
def RefreshPluginTree(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
360 |
infos = self.PluginRoot.GetPlugInfos() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
361 |
root = self.PluginTree.GetRootItem() |
21 | 362 |
if not root.IsOk(): |
363 |
root = self.PluginTree.AddRoot(infos["name"]) |
|
364 |
self.GenerateTreeBranch(root, infos, True) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
365 |
self.PluginTree.Expand(self.PluginTree.GetRootItem()) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
366 |
self.RefreshPluginParams() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
367 |
|
21 | 368 |
def GenerateTreeBranch(self, root, infos, first = False): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
369 |
to_delete = [] |
21 | 370 |
self.PluginTree.SetItemText(root, infos["name"]) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
371 |
self.PluginTree.SetPyData(root, infos["type"]) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
372 |
item, root_cookie = self.PluginTree.GetFirstChild(root) |
21 | 373 |
for values in infos["values"]: |
374 |
if not item.IsOk(): |
|
375 |
item = self.PluginTree.AppendItem(root, "") |
|
376 |
if wx.VERSION < (2, 7, 0): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
377 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
21 | 378 |
self.GenerateTreeBranch(item, values) |
379 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
380 |
while item.IsOk(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
381 |
to_delete.append(item) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
382 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
383 |
for item in to_delete: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
384 |
self.PluginTree.Delete(item) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
385 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
386 |
def GetSelectedPlugin(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
387 |
selected = self.PluginTree.GetSelection() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
388 |
if not selected.IsOk(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
389 |
return None |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
390 |
if selected == self.PluginTree.GetRootItem(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
391 |
return self.PluginRoot |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
392 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
393 |
name = self.PluginTree.GetItemText(selected) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
394 |
item = self.PluginTree.GetItemParent(selected) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
395 |
while item.IsOk() and item != self.PluginTree.GetRootItem(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
396 |
name = "%s.%s"%(self.PluginTree.GetItemText(item), name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
397 |
item = self.PluginTree.GetItemParent(item) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
398 |
return self.PluginRoot.GetChildByName(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
399 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
400 |
def OnPluginTreeItemSelected(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
401 |
wx.CallAfter(self.RefreshPluginParams) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
402 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
403 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
404 |
def _GetAddPluginFunction(self, name): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
405 |
def OnPluginMenu(event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
406 |
self.AddPlugin(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
407 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
408 |
return OnPluginMenu |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
409 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
410 |
def OnPluginTreeRightUp(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
411 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
412 |
if plugin: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
413 |
main_menu = wx.Menu(title='') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
414 |
if len(plugin.PlugChildsTypes) > 0: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
415 |
plugin_menu = wx.Menu(title='') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
416 |
for name, XSDClass in self.GetSelectedPlugin().PlugChildsTypes: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
417 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
418 |
plugin_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
419 |
self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name), id=new_id) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
420 |
main_menu.AppendMenu(-1, "Add", plugin_menu, '') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
421 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
422 |
main_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete") |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
423 |
self.Bind(wx.EVT_MENU, self.OnDeleteButton, id=new_id) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
424 |
rect = self.PluginTree.GetBoundingRect(self.PluginTree.GetSelection()) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
425 |
self.PluginTree.PopupMenuXY(main_menu, rect.x + rect.width, rect.y) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
426 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
427 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
428 |
def RefreshPluginParams(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
429 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
430 |
if not plugin: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
431 |
# Refresh ParamsPanel |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
432 |
self.ParamsPanel.Hide() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
433 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
434 |
# Refresh PluginChilds |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
435 |
self.PluginChilds.Clear() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
436 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
437 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
438 |
self.DeleteButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
439 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
440 |
# Refresh ParamsPanel |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
441 |
self.ParamsPanel.Show() |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
442 |
infos = plugin.GetParamsAttributes() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
443 |
self.RefreshSizerElement(self.ParamsPanelMainSizer, infos, None) |
21 | 444 |
if len(plugin.PluginMethods) > 0: |
445 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
446 |
self.ParamsPanelMainSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
|
447 |
for name, method in plugin.PluginMethods: |
|
448 |
if method: |
|
449 |
id = wx.NewId() |
|
450 |
button = wx.Button(id=id, label=name, name=name, parent=self.ParamsPanel, |
|
451 |
pos=wx.Point(0, 0), style=wx.BU_EXACTFIT) |
|
452 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, method), id=id) |
|
453 |
boxsizer.AddWindow(button, 0, border=5, flag=wx.GROW|wx.RIGHT) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
454 |
self.ParamsPanelMainSizer.Layout() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
455 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
456 |
# Refresh PluginChilds |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
457 |
self.PluginChilds.Clear() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
458 |
if len(plugin.PlugChildsTypes) > 0: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
459 |
self.PluginChilds.Append("") |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
460 |
for name, XSDClass in plugin.PlugChildsTypes: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
461 |
self.PluginChilds.Append(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
462 |
self.PluginChilds.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
463 |
self.AddButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
464 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
465 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
466 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
467 |
self.DeleteButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
468 |
|
21 | 469 |
def GetButtonCallBackFunction(self, plugin, method): |
470 |
def OnButtonClick(event): |
|
471 |
method(plugin, self.Log) |
|
472 |
event.Skip() |
|
473 |
return OnButtonClick |
|
474 |
||
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
475 |
def GetChoiceCallBackFunction(self, choicectrl, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
476 |
def OnChoiceChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
477 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
478 |
if plugin: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
479 |
plugin.SetParamsAttribute(path, choicectrl.GetStringSelection()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
480 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
481 |
return OnChoiceChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
482 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
483 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
484 |
def OnChoiceContentChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
485 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
486 |
if plugin: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
487 |
plugin.SetParamsAttribute(path, choicectrl.GetStringSelection()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
488 |
infos = self.PluginRoot.GetParamsAttributes(path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
489 |
staticbox = staticboxsizer.GetStaticBox() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
490 |
staticbox.SetLabel("%(name)s - %(value)s"%infos) |
21 | 491 |
self.ParamsPanel.Freeze() |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
492 |
self.RefreshSizerElement(staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"])) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
493 |
self.ParamsPanelMainSizer.Layout() |
21 | 494 |
self.ParamsPanel.Thaw() |
495 |
self.ParamsPanel.Refresh() |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
496 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
497 |
return OnChoiceContentChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
498 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
499 |
def GetTextCtrlCallBackFunction(self, textctrl, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
500 |
def OnTextCtrlChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
501 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
502 |
if plugin: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
503 |
plugin.SetParamsAttribute(path, textctrl.GetValue()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
504 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
505 |
return OnTextCtrlChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
506 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
507 |
def GetCheckBoxCallBackFunction(self, textctrl, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
508 |
def OnCheckBoxChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
509 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
510 |
if plugin: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
511 |
plugin.SetParamsAttribute(path, textctrl.IsChecked()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
512 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
513 |
return OnCheckBoxChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
514 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
515 |
def ClearSizer(self, sizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
516 |
staticboxes = [] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
517 |
for item in sizer.GetChildren(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
518 |
if item.IsSizer(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
519 |
item_sizer = item.GetSizer() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
520 |
self.ClearSizer(item_sizer) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
521 |
if isinstance(item_sizer, wx.StaticBoxSizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
522 |
staticboxes.append(item_sizer.GetStaticBox()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
523 |
sizer.Clear(True) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
524 |
for staticbox in staticboxes: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
525 |
staticbox.Destroy() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
526 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
527 |
def RefreshSizerElement(self, sizer, elements, path): |
21 | 528 |
if wx.VERSION >= (2, 7, 0): |
529 |
sizer.Clear(True) |
|
530 |
else: |
|
531 |
self.ClearSizer(sizer) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
532 |
first = True |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
533 |
for element_infos in elements: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
534 |
if path: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
535 |
element_path = "%s.%s"%(path, element_infos["name"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
536 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
537 |
element_path = element_infos["name"] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
538 |
if isinstance(element_infos["type"], types.ListType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
539 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
540 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
541 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
542 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
543 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
544 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
545 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
546 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
547 |
boxsizer.AddWindow(statictext, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
548 |
id = wx.NewId() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
549 |
choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
550 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
551 |
boxsizer.AddWindow(choicectrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
552 |
choicectrl.Append("") |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
553 |
if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
554 |
for choice, xsdclass in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
555 |
choicectrl.Append(choice) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
556 |
staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
557 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
558 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
559 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
560 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
561 |
self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
562 |
callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
563 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
564 |
for choice in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
565 |
choicectrl.Append(choice) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
566 |
callback = self.GetChoiceCallBackFunction(choicectrl, element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
567 |
choicectrl.Bind(wx.EVT_CHOICE, callback, id=id) |
22 | 568 |
if element_infos["value"]: |
569 |
choicectrl.SetStringSelection(element_infos["value"]) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
570 |
elif isinstance(element_infos["type"], types.DictType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
571 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
572 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
573 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
574 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
575 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
576 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
577 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
578 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
579 |
boxsizer.AddWindow(statictext, 0, border=0, flag=wx.TOP|wx.LEFT|wx.BOTTOM) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
580 |
id = wx.NewId() |
22 | 581 |
min = -sys.maxint-1 |
582 |
max = sys.maxint |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
583 |
if "min" in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
584 |
min = element_infos["type"]["min"] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
585 |
if "max" in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
586 |
max = element_infos["type"]["max"] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
587 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
588 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
589 |
min=min, max=max) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
590 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
591 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
592 |
spinctrl.SetValue(element_infos["value"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
593 |
elif element_infos["type"] == "element": |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
594 |
staticbox = wx.StaticBox(id=-1, label=element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
595 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
596 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
597 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
598 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
599 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
600 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
601 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
602 |
self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
603 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
604 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
605 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
606 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
607 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
608 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
609 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
610 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
611 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
612 |
boxsizer.AddWindow(statictext, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
613 |
id = wx.NewId() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
614 |
if element_infos["type"] == "boolean": |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
615 |
checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
616 |
pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
617 |
boxsizer.AddWindow(checkbox, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
618 |
checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
619 |
checkbox.SetValue(element_infos["value"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
620 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
621 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
622 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
623 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
624 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
625 |
spinctrl.SetValue(element_infos["value"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
626 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
627 |
textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
628 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
629 |
boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
630 |
textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
631 |
textctrl.SetValue(str(element_infos["value"])) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
632 |
first = False |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
633 |
|
0 | 634 |
def OnNewProjectMenu(self, event): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
635 |
defaultpath = self.PluginRoot.GetProjectPath() |
22 | 636 |
if not defaultpath: |
0 | 637 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
638 |
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
|
639 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 640 |
projectpath = dialog.GetPath() |
641 |
dialog.Destroy() |
|
20 | 642 |
res = self.PluginRoot.NewProject(projectpath) |
643 |
if not res : |
|
644 |
self.RefreshPluginTree() |
|
645 |
self.RefreshButtons() |
|
646 |
self.RefreshMainMenu() |
|
0 | 647 |
else: |
20 | 648 |
message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 649 |
message.ShowModal() |
650 |
message.Destroy() |
|
651 |
event.Skip() |
|
652 |
||
653 |
def OnOpenProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
654 |
defaultpath = self.PluginRoot.GetProjectPath() |
20 | 655 |
if not defaultpath: |
0 | 656 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
657 |
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
|
658 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
659 |
projectpath = dialog.GetPath() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
660 |
if os.path.isdir(projectpath): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
661 |
result = self.PluginRoot.LoadProject(projectpath) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
662 |
if not result: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
663 |
self.RefreshPluginTree() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
664 |
self.RefreshButtons() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
665 |
self.RefreshMainMenu() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
666 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
667 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
668 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
669 |
message.Destroy() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
670 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
671 |
message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n"%projectpath, "Error", wx.OK|wx.ICON_ERROR) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
672 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
673 |
message.Destroy() |
0 | 674 |
dialog.Destroy() |
675 |
event.Skip() |
|
676 |
||
677 |
def OnCloseProjectMenu(self, event): |
|
678 |
self.PLCManager = None |
|
679 |
self.CurrentProjectPath = projectpath |
|
680 |
self.RefreshButtons() |
|
681 |
self.RefreshMainMenu() |
|
682 |
event.Skip() |
|
683 |
||
684 |
def OnSaveProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
685 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
686 |
self.PluginRoot.SaveProject() |
0 | 687 |
event.Skip() |
688 |
||
689 |
def OnPropertiesMenu(self, event): |
|
690 |
event.Skip() |
|
691 |
||
692 |
def OnQuitMenu(self, event): |
|
693 |
self.Close() |
|
694 |
event.Skip() |
|
695 |
||
696 |
def OnEditPLCMenu(self, event): |
|
697 |
self.EditPLC() |
|
698 |
event.Skip() |
|
699 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
700 |
def OnAddMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
701 |
self.AddPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
702 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
703 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
704 |
def OnDeleteMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
705 |
self.DeletePlugin() |
0 | 706 |
event.Skip() |
707 |
||
1 | 708 |
def OnBuildMenu(self, event): |
20 | 709 |
#self.BuildAutom() |
1 | 710 |
event.Skip() |
711 |
||
0 | 712 |
def OnSimulateMenu(self, event): |
713 |
event.Skip() |
|
714 |
||
715 |
def OnRunMenu(self, event): |
|
716 |
event.Skip() |
|
717 |
||
718 |
def OnSaveLogMenu(self, event): |
|
719 |
event.Skip() |
|
720 |
||
721 |
def OnBeremizMenu(self, event): |
|
722 |
event.Skip() |
|
723 |
||
724 |
def OnAboutMenu(self, event): |
|
725 |
event.Skip() |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
726 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
727 |
def OnAddButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
728 |
PluginType = self.PluginChilds.GetStringSelection() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
729 |
if PluginType != "": |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
730 |
self.AddPlugin(PluginType) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
731 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
732 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
733 |
def OnDeleteButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
734 |
self.DeletePlugin() |
0 | 735 |
event.Skip() |
736 |
||
737 |
def CloseEditor(self, bus_id): |
|
738 |
if self.BusManagers.get(bus_id, None) != None: |
|
739 |
self.BusManagers[bus_id]["Editor"] = None |
|
740 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
741 |
def AddPlugin(self, PluginType): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
742 |
dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL) |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
743 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
744 |
PluginName = dialog.GetValue() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
745 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
746 |
plugin.PlugAddChild(PluginName, PluginType) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
747 |
self.RefreshPluginTree() |
0 | 748 |
dialog.Destroy() |
749 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
750 |
def DeletePlugin(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
751 |
pass |
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
752 |
|
0 | 753 |
#------------------------------------------------------------------------------- |
754 |
# Exception Handler |
|
755 |
#------------------------------------------------------------------------------- |
|
756 |
||
757 |
Max_Traceback_List_Size = 20 |
|
758 |
||
759 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
760 |
trcbck_lst = [] |
|
761 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
762 |
trcbck = " " + str(i+1) + ". " |
|
763 |
if line[0].find(os.getcwd()) == -1: |
|
764 |
trcbck += "file : " + str(line[0]) + ", " |
|
765 |
else: |
|
766 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
767 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
768 |
trcbck_lst.append(trcbck) |
|
769 |
||
770 |
# Allow clicking.... |
|
771 |
cap = wx.Window_GetCapture() |
|
772 |
if cap: |
|
773 |
cap.ReleaseMouse() |
|
774 |
||
775 |
dlg = wx.SingleChoiceDialog(None, |
|
776 |
""" |
|
777 |
An error happens. |
|
778 |
||
779 |
Click on OK for saving an error report. |
|
780 |
||
781 |
Please contact LOLITech at: |
|
782 |
+33 (0)3 29 52 95 67 |
|
783 |
bugs_Beremiz@lolitech.fr |
|
784 |
||
785 |
||
786 |
Error: |
|
787 |
""" + |
|
788 |
str(e_type) + " : " + str(e_value), |
|
789 |
"Error", |
|
790 |
trcbck_lst) |
|
791 |
try: |
|
792 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
793 |
finally: |
|
794 |
dlg.Destroy() |
|
795 |
||
796 |
return res |
|
797 |
||
798 |
def Display_Error_Dialog(e_value): |
|
799 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
800 |
message.ShowModal() |
|
801 |
message.Destroy() |
|
802 |
||
803 |
def get_last_traceback(tb): |
|
804 |
while tb.tb_next: |
|
805 |
tb = tb.tb_next |
|
806 |
return tb |
|
807 |
||
808 |
||
809 |
def format_namespace(d, indent=' '): |
|
810 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
811 |
||
812 |
||
813 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
814 |
||
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
815 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 816 |
|
817 |
def handle_exception(e_type, e_value, e_traceback): |
|
818 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
819 |
last_tb = get_last_traceback(e_traceback) |
|
820 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
821 |
if str(e_value).startswith("!!!"): |
|
822 |
Display_Error_Dialog(e_value) |
|
823 |
elif ex not in ignored_exceptions: |
|
824 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
825 |
if result: |
|
826 |
ignored_exceptions.append(ex) |
|
827 |
info = { |
|
828 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
829 |
'app-version' : app_version, |
|
830 |
'wx-version' : wx.VERSION_STRING, |
|
831 |
'wx-platform' : wx.Platform, |
|
832 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
833 |
'platform' : platform.platform(), |
|
834 |
'e-type' : e_type, |
|
835 |
'e-value' : e_value, |
|
836 |
'date' : time.ctime(), |
|
837 |
'cwd' : os.getcwd(), |
|
838 |
} |
|
839 |
if e_traceback: |
|
840 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
841 |
last_tb = get_last_traceback(e_traceback) |
|
842 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
843 |
info['locals'] = format_namespace(exception_locals) |
|
844 |
if 'self' in exception_locals: |
|
845 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
846 |
||
847 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
848 |
lst = info.keys() |
|
849 |
lst.sort() |
|
850 |
for a in lst: |
|
851 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
852 |
||
853 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
854 |
sys.excepthook = handle_exception |
|
855 |
||
856 |
if __name__ == '__main__': |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
857 |
def usage(): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
858 |
print "\nUsage of Beremiz.py :" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
859 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
860 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
861 |
try: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
862 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
863 |
except getopt.GetoptError: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
864 |
# print help information and exit: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
865 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
866 |
sys.exit(2) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
867 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
868 |
for o, a in opts: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
869 |
if o in ("-h", "--help"): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
870 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
871 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
872 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
873 |
if len(args) > 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
874 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
875 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
876 |
elif len(args) == 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
877 |
projectOpen = args[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
878 |
else: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
879 |
projectOpen = None |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
880 |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
881 |
app = wx.PySimpleApp() |
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
882 |
wx.InitAllImageHandlers() |
0 | 883 |
|
884 |
# Install a exception handle for bug reports |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
885 |
AddExceptHook(os.getcwd(),__version__) |
0 | 886 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
887 |
frame = Beremiz(None, projectOpen) |
0 | 888 |
|
889 |
frame.Show() |
|
890 |
app.MainLoop() |