author | etisserant |
Thu, 21 Feb 2008 11:42:33 +0100 | |
changeset 105 | 434aed8dc58d |
parent 103 | 05b58747ca5d |
child 106 | 9810689febb0 |
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 |
65 | 28 |
import wx.lib.buttons |
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
29 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
30 |
import types |
0 | 31 |
|
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
32 |
import time |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
33 |
|
1 | 34 |
import os, re, platform, sys, time, traceback, getopt, commands |
20 | 35 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
36 |
from plugger import PluginsRoot |
0 | 37 |
|
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
38 |
from wxPopen import wxPopen3 |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
39 |
|
97 | 40 |
SCROLLBAR_UNIT = 10 |
41 |
WINDOW_COLOUR = wx.Colour(240,240,240) |
|
42 |
||
43 |
if wx.Platform == '__WXMSW__': |
|
44 |
faces = { 'times': 'Times New Roman', |
|
45 |
'mono' : 'Courier New', |
|
46 |
'helv' : 'Arial', |
|
47 |
'other': 'Comic Sans MS', |
|
98 | 48 |
'size' : 16, |
97 | 49 |
} |
50 |
else: |
|
51 |
faces = { 'times': 'Times', |
|
52 |
'mono' : 'Courier', |
|
53 |
'helv' : 'Helvetica', |
|
54 |
'other': 'new century schoolbook', |
|
55 |
'size' : 18, |
|
56 |
} |
|
57 |
||
72 | 58 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
59 |
||
97 | 60 |
gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.faceDnClr, wx.SOLID) |
61 |
gen_mini_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenBitmapTextButton._GetLabelSize(obj)[:-1] + (False,)) |
|
98 | 62 |
gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,)) |
63 |
||
64 |
def GenerateEmptyBitmap(width, height): |
|
65 |
bitmap = wx.EmptyBitmap(width, height) |
|
97 | 66 |
dc = wx.MemoryDC(bitmap) |
67 |
dc.SetPen(wx.Pen(WINDOW_COLOUR)) |
|
68 |
dc.SetBrush(wx.Brush(WINDOW_COLOUR)) |
|
98 | 69 |
dc.DrawRectangle(0, 0, width, height) |
97 | 70 |
return bitmap |
71 |
||
1 | 72 |
class LogPseudoFile: |
73 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
74 |
def __init__(self, output = None): |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
75 |
self.red_white = wx.TextAttr("RED", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
76 |
self.red_yellow = wx.TextAttr("RED", "YELLOW") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
77 |
self.black_white = wx.TextAttr("BLACK", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
78 |
self.default_style = None |
1 | 79 |
self.output = output |
80 |
||
81 |
def writelines(self, l): |
|
82 |
map(self.write, l) |
|
83 |
||
22 | 84 |
def write(self, s, style = None): |
101 | 85 |
if not style : style=self.black_white |
22 | 86 |
if self.default_style != style: |
87 |
self.output.SetDefaultStyle(style) |
|
88 |
self.default_style = style |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
89 |
self.output.AppendText(s) |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
90 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
91 |
def write_warning(self, s): |
22 | 92 |
self.write(s,self.red_white) |
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
93 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
94 |
def write_error(self, s): |
22 | 95 |
self.write(s,self.red_yellow) |
1 | 96 |
|
97 |
def flush(self): |
|
98 |
self.output.SetValue("") |
|
99 |
||
100 |
def isatty(self): |
|
101 |
return false |
|
102 |
||
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
103 |
def LogCommand(self, Command, sz_limit = 100, no_stdout=False): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
104 |
self.errlen = 0 |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
105 |
self.exitcode = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
106 |
self.outdata = "" |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
107 |
self.errdata = "" |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
108 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
109 |
def output(v): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
110 |
self.outdata += v |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
111 |
if not no_stdout: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
112 |
self.write(v) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
113 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
114 |
def errors(v): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
115 |
self.errdata += v |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
116 |
self.errlen += 1 |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
117 |
if self.errlen > sz_limit: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
118 |
p.kill() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
119 |
self.write_warning(v) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
120 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
121 |
def fin(pid,ecode): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
122 |
self.exitcode = ecode |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
123 |
if self.exitcode != 0: |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
48
diff
changeset
|
124 |
self.write(Command + "\n") |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
48
diff
changeset
|
125 |
self.write_warning("exited with status %d (pid %d)\n"%(ecode,pid)) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
126 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
127 |
def spin(p): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
128 |
while not p.finished: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
129 |
wx.Yield() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
130 |
time.sleep(0.01) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
131 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
132 |
input = [] |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
133 |
p = wxPopen3(Command, input, output, errors, fin, self.output) |
89 | 134 |
if p.pid: |
135 |
spin(p) |
|
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
136 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
137 |
return (self.exitcode, self.outdata, self.errdata) |
20 | 138 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
139 |
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
97 | 140 |
ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, |
141 |
] = [wx.NewId() for _init_ctrls in range(4)] |
|
0 | 142 |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
143 |
[ID_BEREMIZFILEMENUITEMS0, ID_BEREMIZFILEMENUITEMS1, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
144 |
ID_BEREMIZFILEMENUITEMS2, ID_BEREMIZFILEMENUITEMS3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
145 |
ID_BEREMIZFILEMENUITEMS5, ID_BEREMIZFILEMENUITEMS7, |
0 | 146 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)] |
147 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
148 |
[ID_BEREMIZEDITMENUITEMS0, ID_BEREMIZEDITMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
149 |
ID_BEREMIZEDITMENUITEMS3, |
0 | 150 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(3)] |
151 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
152 |
[ID_BEREMIZRUNMENUITEMS0, ID_BEREMIZRUNMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
153 |
ID_BEREMIZRUNMENUITEMS3, ID_BEREMIZRUNMENUITEMS5, |
0 | 154 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
155 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
156 |
[ID_BEREMIZHELPMENUITEMS0, ID_BEREMIZHELPMENUITEMS1, |
0 | 157 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
158 |
||
159 |
class Beremiz(wx.Frame): |
|
160 |
||
161 |
def _init_coll_FileMenu_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_BEREMIZFILEMENUITEMS0, |
0 | 163 |
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
|
164 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS1, |
0 | 165 |
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
|
166 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS2, |
0 | 167 |
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
|
168 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS3, |
0 | 169 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
170 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
171 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS5, |
0 | 172 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
173 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
174 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS7, |
0 | 175 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
176 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
177 |
id=ID_BEREMIZFILEMENUITEMS0) |
0 | 178 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
179 |
id=ID_BEREMIZFILEMENUITEMS1) |
0 | 180 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
181 |
id=ID_BEREMIZFILEMENUITEMS2) |
0 | 182 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
183 |
id=ID_BEREMIZFILEMENUITEMS3) |
0 | 184 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
185 |
id=ID_BEREMIZFILEMENUITEMS5) |
0 | 186 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
187 |
id=ID_BEREMIZFILEMENUITEMS7) |
0 | 188 |
|
189 |
def _init_coll_EditMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
190 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS0, |
0 | 191 |
kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R') |
192 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
193 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS2, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
194 |
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
|
195 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS3, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
196 |
kind=wx.ITEM_NORMAL, text=u'Delete Plugin') |
0 | 197 |
self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
198 |
id=ID_BEREMIZEDITMENUITEMS0) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
199 |
self.Bind(wx.EVT_MENU, self.OnAddMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
200 |
id=ID_BEREMIZEDITMENUITEMS2) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
201 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
202 |
id=ID_BEREMIZEDITMENUITEMS3) |
0 | 203 |
|
204 |
def _init_coll_RunMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
205 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS0, |
0 | 206 |
kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R') |
207 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
208 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS2, |
0 | 209 |
kind=wx.ITEM_NORMAL, text=u'Simulate') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
210 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS3, |
0 | 211 |
kind=wx.ITEM_NORMAL, text=u'Run') |
212 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
213 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS5, |
0 | 214 |
kind=wx.ITEM_NORMAL, text=u'Save Log') |
1 | 215 |
self.Bind(wx.EVT_MENU, self.OnBuildMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
216 |
id=ID_BEREMIZRUNMENUITEMS0) |
0 | 217 |
self.Bind(wx.EVT_MENU, self.OnSimulateMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
218 |
id=ID_BEREMIZRUNMENUITEMS2) |
0 | 219 |
self.Bind(wx.EVT_MENU, self.OnRunMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
220 |
id=ID_BEREMIZRUNMENUITEMS3) |
0 | 221 |
self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
222 |
id=ID_BEREMIZRUNMENUITEMS5) |
0 | 223 |
|
224 |
def _init_coll_HelpMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
225 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS0, |
0 | 226 |
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
|
227 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS1, |
0 | 228 |
kind=wx.ITEM_NORMAL, text=u'About') |
229 |
self.Bind(wx.EVT_MENU, self.OnBeremizMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
230 |
id=ID_BEREMIZHELPMENUITEMS0) |
0 | 231 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
232 |
id=ID_BEREMIZHELPMENUITEMS1) |
0 | 233 |
|
234 |
def _init_coll_menuBar1_Menus(self, parent): |
|
235 |
parent.Append(menu=self.FileMenu, title=u'File') |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
236 |
#parent.Append(menu=self.EditMenu, title=u'Edit') |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
237 |
#parent.Append(menu=self.RunMenu, title=u'Run') |
0 | 238 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
239 |
||
240 |
def _init_utils(self): |
|
241 |
self.menuBar1 = wx.MenuBar() |
|
242 |
self.FileMenu = wx.Menu(title=u'') |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
243 |
#self.EditMenu = wx.Menu(title=u'') |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
244 |
#self.RunMenu = wx.Menu(title=u'') |
0 | 245 |
self.HelpMenu = wx.Menu(title=u'') |
246 |
||
247 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
248 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
249 |
#self._init_coll_EditMenu_Items(self.EditMenu) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
250 |
#self._init_coll_RunMenu_Items(self.RunMenu) |
0 | 251 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
252 |
||
97 | 253 |
def _init_coll_PLCConfigMainSizer_Items(self, parent): |
254 |
parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
255 |
parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
256 |
||
257 |
def _init_coll_PLCConfigMainSizer_Growables(self, parent): |
|
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
258 |
parent.AddGrowableCol(0) |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
259 |
parent.AddGrowableRow(1) |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
260 |
|
97 | 261 |
def _init_coll_PluginTreeSizer_Growables(self, parent): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
262 |
parent.AddGrowableCol(0) |
97 | 263 |
parent.AddGrowableCol(1) |
0 | 264 |
|
265 |
def _init_sizers(self): |
|
97 | 266 |
self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
267 |
self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL) |
|
99 | 268 |
self.PluginTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2) |
97 | 269 |
|
270 |
self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer) |
|
271 |
self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer) |
|
272 |
self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer) |
|
273 |
||
274 |
self.PLCConfig.SetSizer(self.PLCConfigMainSizer) |
|
275 |
||
0 | 276 |
def _init_ctrls(self, prnt): |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
277 |
wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz', |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
278 |
parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600), |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
279 |
style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz') |
0 | 280 |
self._init_utils() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
281 |
self.SetClientSize(wx.Size(1000, 600)) |
0 | 282 |
self.SetMenuBar(self.menuBar1) |
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
283 |
self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated) |
0 | 284 |
|
71 | 285 |
if wx.VERSION < (2, 8, 0): |
286 |
self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER, |
|
287 |
name='MainSplitter', parent=self, point=wx.Point(0, 0), |
|
288 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
289 |
self.MainSplitter.SetNeedUpdating(True) |
|
290 |
self.MainSplitter.SetMinimumPaneSize(1) |
|
291 |
||
97 | 292 |
parent = self.MainSplitter |
293 |
else: |
|
294 |
parent = self |
|
295 |
||
296 |
self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG, |
|
297 |
name='PLCConfig', parent=parent, pos=wx.Point(0, 0), |
|
298 |
size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) |
|
299 |
self.PLCConfig.SetBackgroundColour(wx.WHITE) |
|
300 |
self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
|
301 |
||
302 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
|
303 |
name='LogConsole', parent=parent, pos=wx.Point(0, 0), |
|
71 | 304 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
97 | 305 |
|
306 |
if wx.VERSION < (2, 8, 0): |
|
307 |
self.MainSplitter.SplitHorizontally(self.PLCConfig, self.LogConsole, -250) |
|
308 |
||
71 | 309 |
else: |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
310 |
self.AUIManager = wx.aui.AuiManager(self) |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
311 |
self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
97 | 312 |
|
313 |
self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane()) |
|
314 |
||
315 |
self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo(). |
|
316 |
Caption("Log Console").Bottom().Layer(1). |
|
317 |
BestSize(wx.Size(800, 200)).CloseButton(False)) |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
318 |
|
71 | 319 |
self.AUIManager.Update() |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
320 |
|
97 | 321 |
self._init_sizers() |
322 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
323 |
def __init__(self, parent, projectOpen): |
0 | 324 |
self._init_ctrls(parent) |
325 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
326 |
self.Log = LogPseudoFile(self.LogConsole) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
327 |
|
20 | 328 |
self.PluginRoot = PluginsRoot(self) |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
329 |
self.DisableEvents = False |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
330 |
|
97 | 331 |
self.PluginInfos = {} |
332 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
333 |
if projectOpen: |
24 | 334 |
self.PluginRoot.LoadProject(projectOpen, self.Log) |
97 | 335 |
self.RefreshPLCParams() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
336 |
self.RefreshPluginTree() |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
337 |
|
0 | 338 |
self.RefreshMainMenu() |
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
339 |
|
97 | 340 |
def OnMoveWindow(self, event): |
341 |
self.GetBestSize() |
|
342 |
self.RefreshScrollBars() |
|
343 |
event.Skip() |
|
344 |
||
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
345 |
def OnFrameActivated(self, event): |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
346 |
if not event.GetActive(): |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
347 |
self.PluginRoot.RefreshPluginsBlockLists() |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
348 |
|
0 | 349 |
def RefreshMainMenu(self): |
350 |
if self.menuBar1: |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
351 |
if self.PluginRoot.HasProjectOpened(): |
42 | 352 |
## self.menuBar1.EnableTop(1, True) |
353 |
## self.menuBar1.EnableTop(2, True) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
354 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
355 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
356 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
357 |
else: |
42 | 358 |
## self.menuBar1.EnableTop(1, False) |
359 |
## self.menuBar1.EnableTop(2, False) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
360 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
361 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
362 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, False) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
363 |
|
97 | 364 |
def RefreshScrollBars(self): |
365 |
xstart, ystart = self.PLCConfig.GetViewStart() |
|
366 |
window_size = self.PLCConfig.GetClientSize() |
|
367 |
sizer = self.PLCConfig.GetSizer() |
|
368 |
if sizer: |
|
369 |
maxx, maxy = sizer.GetMinSize() |
|
370 |
self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
101 | 371 |
maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, xstart, ystart) |
97 | 372 |
|
373 |
def RefreshPLCParams(self): |
|
374 |
self.ClearSizer(self.PLCParamsSizer) |
|
375 |
||
376 |
if self.PluginRoot.HasProjectOpened(): |
|
377 |
plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
378 |
plcwindow.SetBackgroundColour(WINDOW_COLOUR) |
|
379 |
self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
|
380 |
||
98 | 381 |
plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
97 | 382 |
plcwindow.SetSizer(plcwindowsizer) |
383 |
||
384 |
st = wx.StaticText(plcwindow, -1) |
|
98 | 385 |
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
386 |
st.SetLabel(self.PluginRoot.GetProjectName()) |
|
387 |
plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
|
388 |
||
389 |
plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
|
390 |
plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
|
391 |
||
392 |
plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
393 |
plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
|
394 |
||
395 |
msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow) |
|
396 |
plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
|
97 | 397 |
|
398 |
paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1)) |
|
399 |
paramswindow.SetBackgroundColour(WINDOW_COLOUR) |
|
98 | 400 |
plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0) |
97 | 401 |
|
402 |
psizer = wx.BoxSizer(wx.HORIZONTAL) |
|
403 |
paramswindow.SetSizer(psizer) |
|
404 |
||
405 |
plugin_infos = self.PluginRoot.GetParamsAttributes() |
|
406 |
self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False) |
|
407 |
||
408 |
paramswindow.Hide() |
|
409 |
||
410 |
minimizebutton_id = wx.NewId() |
|
411 |
minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')), |
|
412 |
name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0), |
|
413 |
size=wx.Size(24, 24), style=wx.NO_BORDER) |
|
414 |
minimizebutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(minimizebutton) |
|
415 |
minimizebutton.SetBackgroundColour(wx.Colour(208, 208, 208)) |
|
416 |
minimizebutton.labelDelta = 0 |
|
417 |
minimizebutton.SetBezelWidth(0) |
|
418 |
minimizebutton.SetUseFocusIndicator(False) |
|
419 |
minimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Minimize.png'))) |
|
99 | 420 |
plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) |
421 |
||
422 |
if len(self.PluginRoot.PlugChildsTypes) > 0: |
|
423 |
addsizer = self.GenerateAddButtonSizer(self.PluginRoot, plcwindow) |
|
424 |
plcwindowbuttonsizer.AddSizer(addsizer, 0, border=0, flag=0) |
|
425 |
else: |
|
426 |
addsizer = None |
|
427 |
||
97 | 428 |
def togglewindow(event): |
429 |
if minimizebutton.GetToggle(): |
|
430 |
paramswindow.Show() |
|
431 |
msizer.SetCols(1) |
|
99 | 432 |
if addsizer is not None: |
433 |
addsizer.SetCols(1) |
|
97 | 434 |
else: |
435 |
paramswindow.Hide() |
|
436 |
msizer.SetCols(len(self.PluginRoot.PluginMethods)) |
|
99 | 437 |
if addsizer is not None: |
438 |
addsizer.SetCols(len(self.PluginRoot.PlugChildsTypes)) |
|
97 | 439 |
self.PLCConfigMainSizer.Layout() |
440 |
self.RefreshScrollBars() |
|
441 |
event.Skip() |
|
442 |
minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) |
|
101 | 443 |
|
444 |
self.PLCConfigMainSizer.Layout() |
|
445 |
self.RefreshScrollBars() |
|
99 | 446 |
|
447 |
def GenerateAddButtonSizer(self, plugin, parent, horizontal = True): |
|
448 |
if horizontal: |
|
449 |
addsizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) |
|
450 |
else: |
|
451 |
addsizer = wx.FlexGridSizer(cols=1) |
|
98 | 452 |
for name, XSDClass in plugin.PlugChildsTypes: |
453 |
addbutton_id = wx.NewId() |
|
454 |
addbutton = wx.lib.buttons.GenButton(id=addbutton_id, label="Add %s"%name, |
|
455 |
name='AddBusButton', parent=parent, pos=wx.Point(0, 0), |
|
456 |
style=wx.NO_BORDER) |
|
457 |
font = addbutton.GetFont() |
|
458 |
font.SetUnderlined(True) |
|
459 |
addbutton.SetFont(font) |
|
460 |
addbutton._GetLabelSize = gen_textbutton_GetLabelSize(addbutton) |
|
461 |
addbutton.SetForegroundColour(wx.BLUE) |
|
462 |
addbutton.SetToolTipString("Add a %s plugin to this one"%name) |
|
463 |
addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id) |
|
99 | 464 |
addsizer.AddWindow(addbutton, 0, border=0, flag=0) |
98 | 465 |
return addsizer |
466 |
||
467 |
def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True): |
|
468 |
if horizontal: |
|
469 |
msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) |
|
470 |
else: |
|
471 |
msizer = wx.FlexGridSizer(cols=1) |
|
472 |
for plugin_method in plugin.PluginMethods: |
|
473 |
if "method" in plugin_method: |
|
474 |
id = wx.NewId() |
|
475 |
button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=parent, |
|
476 |
bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], |
|
477 |
name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER) |
|
478 |
button.SetToolTipString(plugin_method["tooltip"]) |
|
479 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id) |
|
480 |
#hack to force size to mini |
|
481 |
button._GetLabelSize = gen_mini_GetLabelSize(button) |
|
482 |
#button._GetLabelSize = lambda :(-1,-1,False) |
|
483 |
msizer.AddWindow(button, 0, border=0, flag=0) |
|
484 |
return msizer |
|
97 | 485 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
486 |
def RefreshPluginTree(self): |
97 | 487 |
self.ClearSizer(self.PluginTreeSizer) |
488 |
if self.PluginRoot.HasProjectOpened(): |
|
489 |
index = [0] |
|
490 |
for child in self.PluginRoot.IECSortedChilds(): |
|
491 |
self.GenerateTreeBranch(child, index) |
|
492 |
if not self.PluginInfos[child]["expanded"]: |
|
493 |
self.CollapsePlugin(child) |
|
494 |
self.PLCConfigMainSizer.Layout() |
|
495 |
self.RefreshScrollBars() |
|
496 |
||
497 |
def ExpandPlugin(self, plugin, force = False): |
|
498 |
for child in self.PluginInfos[plugin]["children"]: |
|
499 |
self.PluginTreeSizer.Show(self.PluginInfos[child]["left"]) |
|
99 | 500 |
self.PluginTreeSizer.Show(self.PluginInfos[child]["middle"]) |
97 | 501 |
self.PluginTreeSizer.Show(self.PluginInfos[child]["right"]) |
502 |
if force or not self.PluginInfos[child]["expanded"]: |
|
503 |
self.ExpandPlugin(child, force) |
|
504 |
if force: |
|
505 |
self.PluginInfos[child]["expanded"] = True |
|
506 |
||
507 |
def CollapsePlugin(self, plugin, force = False): |
|
508 |
for child in self.PluginInfos[plugin]["children"]: |
|
509 |
self.PluginTreeSizer.Hide(self.PluginInfos[child]["left"]) |
|
99 | 510 |
self.PluginTreeSizer.Hide(self.PluginInfos[child]["middle"]) |
97 | 511 |
self.PluginTreeSizer.Hide(self.PluginInfos[child]["right"]) |
512 |
if force or self.PluginInfos[child]["expanded"]: |
|
513 |
self.CollapsePlugin(child, force) |
|
514 |
if force: |
|
515 |
self.PluginInfos[child]["expanded"] = False |
|
516 |
||
517 |
def GenerateTreeBranch(self, plugin, index): |
|
518 |
leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
519 |
leftwindow.SetBackgroundColour(WINDOW_COLOUR) |
|
520 |
||
521 |
if plugin not in self.PluginInfos: |
|
99 | 522 |
self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "middle_visible" : False} |
97 | 523 |
|
524 |
self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds() |
|
525 |
||
526 |
self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
|
527 |
||
528 |
leftwindowsizer = wx.FlexGridSizer(cols=1, rows=2) |
|
529 |
leftwindowsizer.AddGrowableCol(0) |
|
530 |
leftwindowsizer.AddGrowableRow(1) |
|
531 |
leftwindow.SetSizer(leftwindowsizer) |
|
532 |
||
533 |
leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1) |
|
534 |
leftbuttonmainsizer.AddGrowableCol(0) |
|
98 | 535 |
leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP) |
97 | 536 |
|
537 |
leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
538 |
leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=15, flag=wx.GROW|wx.RIGHT) |
|
539 |
||
540 |
ieccsizer = wx.BoxSizer(wx.VERTICAL) |
|
541 |
leftbuttonsizer.AddSizer(ieccsizer, 0, border=15, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
542 |
||
543 |
plugin_IECChannel = plugin.BaseParams.getIEC_Channel() |
|
544 |
||
545 |
if plugin_IECChannel > 0: |
|
98 | 546 |
ieccdownbutton_id = wx.NewId() |
547 |
ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCDown.png')), |
|
548 |
name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
549 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
|
97 | 550 |
ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id) |
98 | 551 |
ieccsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_CENTER) |
97 | 552 |
else: |
98 | 553 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(16, 16), |
554 |
name="staticBitmap", parent=leftwindow, |
|
555 |
pos=wx.Point(0, 0), size=wx.Size(16, 16), style=0) |
|
556 |
ieccsizer.AddWindow(staticbitmap, 0, border=0, flag=wx.ALIGN_CENTER) |
|
97 | 557 |
|
558 |
st = wx.StaticText(leftwindow, -1) |
|
559 |
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
|
560 |
st.SetLabel(plugin.GetFullIEC_Channel()) |
|
561 |
ieccsizer.AddWindow(st, 0, border=0, flag=0) |
|
562 |
||
563 |
ieccupbutton_id = wx.NewId() |
|
564 |
ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCUp.png')), |
|
565 |
name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
566 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
|
567 |
ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel + 1), id=ieccupbutton_id) |
|
568 |
ieccsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_CENTER) |
|
569 |
||
570 |
if len(self.PluginInfos[plugin]["children"]) > 0: |
|
571 |
expandbutton_id = wx.NewId() |
|
572 |
expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'plus.png')), |
|
573 |
name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
574 |
size=wx.Size(13, 13), style=wx.NO_BORDER) |
|
575 |
expandbutton.labelDelta = 0 |
|
576 |
expandbutton.SetBezelWidth(0) |
|
577 |
expandbutton.SetUseFocusIndicator(False) |
|
578 |
expandbutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'minus.png'))) |
|
579 |
expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"]) |
|
580 |
||
581 |
def togglebutton(event): |
|
582 |
if expandbutton.GetToggle(): |
|
583 |
self.ExpandPlugin(plugin) |
|
89 | 584 |
else: |
97 | 585 |
self.CollapsePlugin(plugin) |
586 |
self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() |
|
587 |
self.PLCConfigMainSizer.Layout() |
|
588 |
self.RefreshScrollBars() |
|
589 |
event.Skip() |
|
590 |
expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
|
591 |
leftbuttonsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
592 |
||
593 |
tc_id = wx.NewId() |
|
594 |
tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 35), style=wx.TE_PROCESS_ENTER|wx.NO_BORDER) |
|
595 |
tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
|
596 |
tc.SetValue(plugin.MandatoryParams[1].getName()) |
|
597 |
tc.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id) |
|
598 |
leftbuttonsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
599 |
||
600 |
enablebutton_id = wx.NewId() |
|
99 | 601 |
enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Disabled.png')), |
602 |
name='EnableButton', parent=leftwindow, pos=wx.Point(0, 0), style=wx.NO_BORDER) |
|
603 |
enablebutton.SetToolTipString("Enable/Disable this plugin") |
|
97 | 604 |
enablebutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(enablebutton) |
605 |
enablebutton.SetBackgroundColour(wx.Colour(208, 208, 208)) |
|
606 |
enablebutton.labelDelta = 0 |
|
607 |
enablebutton.SetBezelWidth(0) |
|
608 |
enablebutton.SetUseFocusIndicator(False) |
|
609 |
enablebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Enabled.png'))) |
|
610 |
enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled()) |
|
611 |
def toggleenablebutton(event): |
|
612 |
res, StructChanged = plugin.SetParamsAttribute("BaseParams.Enabled", enablebutton.GetToggle(), self.Log) |
|
613 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
|
614 |
enablebutton.SetToggle(res) |
|
615 |
event.Skip() |
|
616 |
enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) |
|
617 |
leftbuttonsizer.AddWindow(enablebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
618 |
||
619 |
leftminimizebutton_id = wx.NewId() |
|
620 |
leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')), |
|
621 |
name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
622 |
size=wx.Size(24, 24), style=wx.NO_BORDER) |
|
623 |
leftminimizebutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(leftminimizebutton) |
|
624 |
leftminimizebutton.SetBackgroundColour(wx.Colour(208, 208, 208)) |
|
625 |
leftminimizebutton.labelDelta = 0 |
|
626 |
leftminimizebutton.SetBezelWidth(0) |
|
627 |
leftminimizebutton.SetUseFocusIndicator(False) |
|
628 |
leftminimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Minimize.png'))) |
|
629 |
leftminimizebutton.SetToggle(self.PluginInfos[plugin]["left_visible"]) |
|
630 |
def toggleleftwindow(event): |
|
631 |
if leftminimizebutton.GetToggle(): |
|
632 |
leftwindowsizer.Show(1) |
|
633 |
else: |
|
634 |
leftwindowsizer.Hide(1) |
|
635 |
self.PluginInfos[plugin]["left_visible"] = leftminimizebutton.GetToggle() |
|
636 |
self.PLCConfigMainSizer.Layout() |
|
637 |
self.RefreshScrollBars() |
|
638 |
event.Skip() |
|
639 |
leftminimizebutton.Bind(wx.EVT_BUTTON, toggleleftwindow, id=leftminimizebutton_id) |
|
640 |
leftbuttonmainsizer.AddWindow(leftminimizebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
|
641 |
||
642 |
deletebutton_id = wx.NewId() |
|
643 |
deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Delete24x24.png')), |
|
644 |
name='DeleteBusButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
645 |
size=wx.Size(24, 24), style=wx.NO_BORDER) |
|
646 |
deletebutton.SetToolTipString("Delete this plugin") |
|
647 |
deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id) |
|
648 |
leftbuttonmainsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
|
649 |
||
98 | 650 |
locations = plugin.GetLocations() |
651 |
lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, max(1, min(len(locations), 4)) * 25), style=wx.NO_BORDER) |
|
652 |
for location in locations: |
|
97 | 653 |
lb.Append(location["NAME"].replace("__", "%").replace("_", ".")) |
654 |
if not self.PluginInfos[plugin]["left_visible"]: |
|
655 |
lb.Hide() |
|
98 | 656 |
self.PluginInfos[plugin]["variable_list"] = lb |
99 | 657 |
leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
658 |
||
659 |
middlewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
660 |
middlewindow.SetBackgroundColour(wx.Colour(240,240,240)) |
|
661 |
||
662 |
self.PluginTreeSizer.AddWindow(middlewindow, 0, border=0, flag=wx.GROW) |
|
663 |
||
664 |
middlewindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
|
665 |
middlewindow.SetSizer(middlewindowmainsizer) |
|
666 |
||
667 |
middlewindowsizer = wx.FlexGridSizer(cols=2, rows=1) |
|
668 |
middlewindowsizer.AddGrowableCol(1) |
|
669 |
middlewindowsizer.AddGrowableRow(0) |
|
670 |
middlewindowmainsizer.AddSizer(middlewindowsizer, 0, border=17, flag=wx.TOP|wx.GROW) |
|
671 |
||
672 |
msizer = self.GenerateMethodButtonSizer(plugin, middlewindow, not self.PluginInfos[plugin]["middle_visible"]) |
|
673 |
middlewindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
|
674 |
||
675 |
middleparamssizer = wx.BoxSizer(wx.HORIZONTAL) |
|
676 |
middlewindowsizer.AddSizer(middleparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
|
677 |
||
678 |
paramswindow = wx.Panel(middlewindow, -1, size=wx.Size(-1, -1)) |
|
679 |
paramswindow.SetBackgroundColour(WINDOW_COLOUR) |
|
680 |
||
681 |
psizer = wx.BoxSizer(wx.HORIZONTAL) |
|
682 |
paramswindow.SetSizer(psizer) |
|
683 |
||
684 |
middleparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL) |
|
685 |
||
686 |
plugin_infos = plugin.GetParamsAttributes() |
|
687 |
self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False) |
|
688 |
||
689 |
if not self.PluginInfos[plugin]["middle_visible"]: |
|
690 |
paramswindow.Hide() |
|
691 |
||
692 |
middleminimizebutton_id = wx.NewId() |
|
693 |
middleminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=middleminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')), |
|
694 |
name='MinimizeButton', parent=middlewindow, pos=wx.Point(0, 0), |
|
695 |
size=wx.Size(24, 24), style=wx.NO_BORDER) |
|
696 |
middleminimizebutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(middleminimizebutton) |
|
697 |
middleminimizebutton.SetBackgroundColour(wx.Colour(208, 208, 208)) |
|
698 |
middleminimizebutton.labelDelta = 0 |
|
699 |
middleminimizebutton.SetBezelWidth(0) |
|
700 |
middleminimizebutton.SetUseFocusIndicator(False) |
|
701 |
middleminimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Minimize.png'))) |
|
702 |
middleminimizebutton.SetToggle(self.PluginInfos[plugin]["middle_visible"]) |
|
703 |
middleparamssizer.AddWindow(middleminimizebutton, 0, border=5, flag=wx.ALL) |
|
704 |
||
97 | 705 |
rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
706 |
rightwindow.SetBackgroundColour(wx.Colour(240,240,240)) |
|
707 |
||
708 |
self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
|
709 |
||
99 | 710 |
rightsizer = wx.BoxSizer(wx.VERTICAL) |
711 |
rightwindow.SetSizer(rightsizer) |
|
712 |
||
713 |
rightmainsizer = wx.BoxSizer(wx.VERTICAL) |
|
714 |
rightsizer.AddSizer(rightmainsizer, 0, border=5, flag=wx.ALL) |
|
715 |
||
716 |
if len(plugin.PlugChildsTypes) > 0: |
|
717 |
addsizer = self.GenerateAddButtonSizer(plugin, rightwindow) |
|
718 |
rightmainsizer.AddSizer(addsizer, 0, border=12, flag=wx.TOP) |
|
719 |
else: |
|
720 |
addsizer = None |
|
721 |
||
722 |
def togglemiddlerightwindow(event): |
|
723 |
if middleminimizebutton.GetToggle(): |
|
724 |
middleparamssizer.Show(0) |
|
97 | 725 |
msizer.SetCols(1) |
99 | 726 |
if addsizer is not None: |
727 |
addsizer.SetCols(1) |
|
97 | 728 |
else: |
99 | 729 |
middleparamssizer.Hide(0) |
97 | 730 |
msizer.SetCols(len(plugin.PluginMethods)) |
99 | 731 |
if addsizer is not None: |
732 |
addsizer.SetCols(len(plugin.PlugChildsTypes)) |
|
733 |
self.PluginInfos[plugin]["middle_visible"] = middleminimizebutton.GetToggle() |
|
97 | 734 |
self.PLCConfigMainSizer.Layout() |
735 |
self.RefreshScrollBars() |
|
84 | 736 |
event.Skip() |
99 | 737 |
middleminimizebutton.Bind(wx.EVT_BUTTON, togglemiddlerightwindow, id=middleminimizebutton_id) |
738 |
||
97 | 739 |
self.PluginInfos[plugin]["left"] = index[0] |
99 | 740 |
self.PluginInfos[plugin]["middle"] = index[0] + 1 |
741 |
self.PluginInfos[plugin]["right"] = index[0] + 2 |
|
742 |
index[0] += 3 |
|
97 | 743 |
for child in self.PluginInfos[plugin]["children"]: |
744 |
self.GenerateTreeBranch(child, index) |
|
745 |
if not self.PluginInfos[child]["expanded"]: |
|
746 |
self.CollapsePlugin(child) |
|
747 |
||
98 | 748 |
def RefreshVariableLists(self): |
749 |
for plugin, infos in self.PluginInfos.items(): |
|
750 |
locations = plugin.GetLocations() |
|
751 |
infos["variable_list"].SetSize(wx.Size(-1, max(1, min(len(locations), 4)) * 25)) |
|
752 |
infos["variable_list"].Clear() |
|
753 |
for location in locations: |
|
754 |
infos["variable_list"].Append(location["NAME"].replace("__", "%").replace("_", ".")) |
|
755 |
self.PLCConfigMainSizer.Layout() |
|
756 |
self.RefreshScrollBars() |
|
757 |
||
97 | 758 |
def GetItemChannelChangedFunction(self, plugin, value): |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
759 |
def OnPluginTreeItemChannelChanged(event): |
97 | 760 |
res, StructChanged = plugin.SetParamsAttribute("BaseParams.IEC_Channel", value, self.Log) |
761 |
wx.CallAfter(self.RefreshPluginTree) |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
762 |
event.Skip() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
763 |
return OnPluginTreeItemChannelChanged |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
764 |
|
97 | 765 |
def _GetAddPluginFunction(self, name, plugin): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
766 |
def OnPluginMenu(event): |
98 | 767 |
wx.CallAfter(self.AddPlugin, name, plugin) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
768 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
769 |
return OnPluginMenu |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
770 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
771 |
def OnPluginTreeRightUp(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
772 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
773 |
if plugin: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
774 |
main_menu = wx.Menu(title='') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
775 |
if len(plugin.PlugChildsTypes) > 0: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
776 |
plugin_menu = wx.Menu(title='') |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
777 |
for name, XSDClass in plugin.PlugChildsTypes: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
778 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
779 |
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
|
780 |
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
|
781 |
main_menu.AppendMenu(-1, "Add", plugin_menu, '') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
782 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
783 |
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
|
784 |
self.Bind(wx.EVT_MENU, self.OnDeleteButton, id=new_id) |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
785 |
pos_x, pos_y = event.GetPosition() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
786 |
self.PluginTree.PopupMenuXY(main_menu, pos_x, pos_y) |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
787 |
event.Skip() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
788 |
|
21 | 789 |
def GetButtonCallBackFunction(self, plugin, method): |
790 |
def OnButtonClick(event): |
|
105
434aed8dc58d
Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents:
103
diff
changeset
|
791 |
getattr(plugin,method)(self.Log) |
98 | 792 |
self.RefreshVariableLists() |
21 | 793 |
event.Skip() |
794 |
return OnButtonClick |
|
795 |
||
97 | 796 |
def GetChoiceCallBackFunction(self, choicectrl, plugin, path): |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
797 |
def OnChoiceChanged(event): |
97 | 798 |
res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log) |
799 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
|
800 |
choicectrl.SetStringSelection(res) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
801 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
802 |
return OnChoiceChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
803 |
|
97 | 804 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path): |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
805 |
def OnChoiceContentChanged(event): |
97 | 806 |
res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log) |
807 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
|
808 |
choicectrl.SetStringSelection(res) |
|
809 |
infos = self.PluginRoot.GetParamsAttributes(path) |
|
810 |
staticbox = staticboxsizer.GetStaticBox() |
|
811 |
staticbox.SetLabel("%(name)s - %(value)s"%infos) |
|
812 |
if wx.VERSION < (2, 8, 0): |
|
813 |
self.ParamsPanel.Freeze() |
|
814 |
self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected) |
|
815 |
self.ParamsPanelMainSizer.Layout() |
|
816 |
self.ParamsPanel.Thaw() |
|
817 |
self.ParamsPanel.Refresh() |
|
818 |
else: |
|
819 |
wx.CallAfter(self.RefreshPluginTree) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
820 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
821 |
return OnChoiceContentChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
822 |
|
97 | 823 |
def GetTextCtrlCallBackFunction(self, textctrl, plugin, path): |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
824 |
def OnTextCtrlChanged(event): |
97 | 825 |
res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log) |
826 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
|
827 |
textctrl.SetValue(res) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
828 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
829 |
return OnTextCtrlChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
830 |
|
97 | 831 |
def GetCheckBoxCallBackFunction(self, chkbx, plugin, path): |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
832 |
def OnCheckBoxChanged(event): |
97 | 833 |
res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log) |
834 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
|
835 |
chkbx.SetValue(res) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
836 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
837 |
return OnCheckBoxChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
838 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
839 |
def ClearSizer(self, sizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
840 |
staticboxes = [] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
841 |
for item in sizer.GetChildren(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
842 |
if item.IsSizer(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
843 |
item_sizer = item.GetSizer() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
844 |
self.ClearSizer(item_sizer) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
845 |
if isinstance(item_sizer, wx.StaticBoxSizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
846 |
staticboxes.append(item_sizer.GetStaticBox()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
847 |
sizer.Clear(True) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
848 |
for staticbox in staticboxes: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
849 |
staticbox.Destroy() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
850 |
|
97 | 851 |
def RefreshSizerElement(self, parent, sizer, plugin, elements, path, clean = True): |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
852 |
if clean: |
97 | 853 |
if wx.VERSION < (2, 8, 0): |
854 |
self.ClearSizer(sizer) |
|
855 |
else: |
|
856 |
sizer.Clear(True) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
857 |
first = True |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
858 |
for element_infos in elements: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
859 |
if path: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
860 |
element_path = "%s.%s"%(path, element_infos["name"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
861 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
862 |
element_path = element_infos["name"] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
863 |
if isinstance(element_infos["type"], types.ListType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
864 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
865 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
866 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
867 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
868 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 869 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
870 |
if os.path.isfile(bitmappath): |
|
871 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
872 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
65 | 873 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
874 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
97 | 875 |
else: |
98 | 876 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
97 | 877 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
878 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
879 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
880 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
881 |
name="%s_label"%element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
882 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
883 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
884 |
id = wx.NewId() |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
885 |
choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
886 |
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
|
887 |
boxsizer.AddWindow(choicectrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
888 |
choicectrl.Append("") |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
889 |
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
|
890 |
for choice, xsdclass in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
891 |
choicectrl.Append(choice) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
892 |
staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
893 |
name='%s_staticbox'%element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
894 |
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
|
895 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
896 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) |
97 | 897 |
self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) |
898 |
callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, plugin, element_path) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
899 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
900 |
for choice in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
901 |
choicectrl.Append(choice) |
97 | 902 |
callback = self.GetChoiceCallBackFunction(choicectrl, plugin, element_path) |
22 | 903 |
if element_infos["value"]: |
904 |
choicectrl.SetStringSelection(element_infos["value"]) |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
905 |
choicectrl.Bind(wx.EVT_CHOICE, callback, id=id) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
906 |
elif isinstance(element_infos["type"], types.DictType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
907 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
908 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
909 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
910 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
911 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 912 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
913 |
if os.path.isfile(bitmappath): |
|
914 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
915 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
65 | 916 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
917 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
97 | 918 |
else: |
98 | 919 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
97 | 920 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
921 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
922 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
923 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
924 |
name="%s_label"%element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
925 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
926 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
927 |
id = wx.NewId() |
23 | 928 |
scmin = -(2**31) |
929 |
scmax = 2**31-1 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
930 |
if "min" in element_infos["type"]: |
23 | 931 |
scmin = element_infos["type"]["min"] |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
932 |
if "max" in element_infos["type"]: |
23 | 933 |
scmax = element_infos["type"]["max"] |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
934 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, |
23 | 935 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
936 |
spinctrl.SetRange(scmin,scmax) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
937 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
938 |
spinctrl.SetValue(element_infos["value"]) |
97 | 939 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
940 |
elif element_infos["type"] == "element": |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
941 |
staticbox = wx.StaticBox(id=-1, label=element_infos["name"], |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
942 |
name='%s_staticbox'%element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
943 |
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
|
944 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
945 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
946 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
947 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
948 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) |
97 | 949 |
self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
950 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
951 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
952 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
953 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
954 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
955 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 956 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
957 |
if os.path.isfile(bitmappath): |
|
958 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
959 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
65 | 960 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
961 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
97 | 962 |
else: |
98 | 963 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
97 | 964 |
name="%s_bitmap"%element_infos["name"], parent=parent, |
965 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
966 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
967 |
||
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
968 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
969 |
name="%s_label"%element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
970 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
971 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
972 |
id = wx.NewId() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
973 |
if element_infos["type"] == "boolean": |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
974 |
checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
975 |
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
|
976 |
boxsizer.AddWindow(checkbox, 0, border=0, flag=0) |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
977 |
checkbox.SetValue(element_infos["value"]) |
97 | 978 |
checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
979 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
23 | 980 |
if element_infos["type"].startswith("unsigned"): |
981 |
scmin = 0 |
|
982 |
else: |
|
983 |
scmin = -(2**31) |
|
984 |
scmax = 2**31-1 |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
985 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
986 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
23 | 987 |
spinctrl.SetRange(scmin, scmax) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
988 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
989 |
spinctrl.SetValue(element_infos["value"]) |
97 | 990 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
991 |
else: |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
992 |
textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
993 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.TE_PROCESS_ENTER) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
994 |
boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
995 |
textctrl.SetValue(str(element_infos["value"])) |
97 | 996 |
textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path), id=id) |
997 |
textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path)) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
998 |
first = False |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
999 |
|
0 | 1000 |
def OnNewProjectMenu(self, event): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1001 |
defaultpath = self.PluginRoot.GetProjectPath() |
22 | 1002 |
if not defaultpath: |
0 | 1003 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
1004 |
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
|
1005 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1006 |
projectpath = dialog.GetPath() |
1007 |
dialog.Destroy() |
|
20 | 1008 |
res = self.PluginRoot.NewProject(projectpath) |
1009 |
if not res : |
|
97 | 1010 |
self.RefreshPLCParams() |
20 | 1011 |
self.RefreshPluginTree() |
1012 |
self.RefreshMainMenu() |
|
0 | 1013 |
else: |
20 | 1014 |
message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 1015 |
message.ShowModal() |
1016 |
message.Destroy() |
|
1017 |
event.Skip() |
|
1018 |
||
1019 |
def OnOpenProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1020 |
defaultpath = self.PluginRoot.GetProjectPath() |
20 | 1021 |
if not defaultpath: |
0 | 1022 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
1023 |
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
|
1024 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1025 |
projectpath = dialog.GetPath() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1026 |
if os.path.isdir(projectpath): |
24 | 1027 |
result = self.PluginRoot.LoadProject(projectpath, self.Log) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1028 |
if not result: |
97 | 1029 |
self.RefreshPLCParams() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1030 |
self.RefreshPluginTree() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1031 |
self.RefreshMainMenu() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1032 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1033 |
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
|
1034 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1035 |
message.Destroy() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1036 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1037 |
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
|
1038 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1039 |
message.Destroy() |
0 | 1040 |
dialog.Destroy() |
1041 |
event.Skip() |
|
1042 |
||
1043 |
def OnCloseProjectMenu(self, event): |
|
97 | 1044 |
self.PluginInfos = {} |
1045 |
self.RefreshPLCParams() |
|
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1046 |
self.RefreshPluginTree() |
0 | 1047 |
self.RefreshMainMenu() |
1048 |
event.Skip() |
|
1049 |
||
1050 |
def OnSaveProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1051 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1052 |
self.PluginRoot.SaveProject() |
0 | 1053 |
event.Skip() |
1054 |
||
1055 |
def OnPropertiesMenu(self, event): |
|
1056 |
event.Skip() |
|
1057 |
||
1058 |
def OnQuitMenu(self, event): |
|
1059 |
self.Close() |
|
1060 |
event.Skip() |
|
1061 |
||
1062 |
def OnEditPLCMenu(self, event): |
|
1063 |
self.EditPLC() |
|
1064 |
event.Skip() |
|
1065 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1066 |
def OnAddMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1067 |
self.AddPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1068 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1069 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1070 |
def OnDeleteMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1071 |
self.DeletePlugin() |
0 | 1072 |
event.Skip() |
1073 |
||
1 | 1074 |
def OnBuildMenu(self, event): |
20 | 1075 |
#self.BuildAutom() |
1 | 1076 |
event.Skip() |
1077 |
||
0 | 1078 |
def OnSimulateMenu(self, event): |
1079 |
event.Skip() |
|
1080 |
||
1081 |
def OnRunMenu(self, event): |
|
1082 |
event.Skip() |
|
1083 |
||
1084 |
def OnSaveLogMenu(self, event): |
|
1085 |
event.Skip() |
|
1086 |
||
1087 |
def OnBeremizMenu(self, event): |
|
1088 |
event.Skip() |
|
1089 |
||
1090 |
def OnAboutMenu(self, event): |
|
1091 |
event.Skip() |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1092 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1093 |
def OnAddButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1094 |
PluginType = self.PluginChilds.GetStringSelection() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1095 |
if PluginType != "": |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1096 |
self.AddPlugin(PluginType) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1097 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1098 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1099 |
def OnDeleteButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1100 |
self.DeletePlugin() |
0 | 1101 |
event.Skip() |
1102 |
||
97 | 1103 |
def GetAddButtonFunction(self, plugin, window): |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1104 |
def AddButtonFunction(event): |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1105 |
if plugin and len(plugin.PlugChildsTypes) > 0: |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1106 |
plugin_menu = wx.Menu(title='') |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1107 |
for name, XSDClass in plugin.PlugChildsTypes: |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1108 |
new_id = wx.NewId() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1109 |
plugin_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=name) |
97 | 1110 |
self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id) |
87 | 1111 |
window_pos = window.GetPosition() |
97 | 1112 |
wx.CallAfter(self.PLCConfig.PopupMenu, plugin_menu) |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1113 |
event.Skip() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1114 |
return AddButtonFunction |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1115 |
|
97 | 1116 |
def GetDeleteButtonFunction(self, plugin): |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1117 |
def DeleteButtonFunction(event): |
97 | 1118 |
wx.CallAfter(self.DeletePlugin, plugin) |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1119 |
event.Skip() |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1120 |
return DeleteButtonFunction |
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
76
diff
changeset
|
1121 |
|
97 | 1122 |
def AddPlugin(self, PluginType, plugin): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1123 |
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
|
1124 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1125 |
PluginName = dialog.GetValue() |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
1126 |
plugin.PlugAddChild(PluginName, PluginType, self.Log) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
1127 |
self.RefreshPluginTree() |
0 | 1128 |
dialog.Destroy() |
1129 |
||
97 | 1130 |
def DeletePlugin(self, plugin): |
72 | 1131 |
dialog = wx.MessageDialog(self, "Really delete plugin ?", "Remove plugin", wx.YES_NO|wx.NO_DEFAULT) |
50 | 1132 |
if dialog.ShowModal() == wx.ID_YES: |
97 | 1133 |
self.PluginInfos.pop(plugin) |
50 | 1134 |
plugin.PlugRemove() |
1135 |
del plugin |
|
1136 |
self.RefreshPluginTree() |
|
1137 |
dialog.Destroy() |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
1138 |
|
0 | 1139 |
#------------------------------------------------------------------------------- |
1140 |
# Exception Handler |
|
1141 |
#------------------------------------------------------------------------------- |
|
1142 |
||
1143 |
Max_Traceback_List_Size = 20 |
|
1144 |
||
1145 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
1146 |
trcbck_lst = [] |
|
1147 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
1148 |
trcbck = " " + str(i+1) + ". " |
|
1149 |
if line[0].find(os.getcwd()) == -1: |
|
1150 |
trcbck += "file : " + str(line[0]) + ", " |
|
1151 |
else: |
|
1152 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
1153 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
1154 |
trcbck_lst.append(trcbck) |
|
1155 |
||
1156 |
# Allow clicking.... |
|
1157 |
cap = wx.Window_GetCapture() |
|
1158 |
if cap: |
|
1159 |
cap.ReleaseMouse() |
|
1160 |
||
1161 |
dlg = wx.SingleChoiceDialog(None, |
|
1162 |
""" |
|
1163 |
An error happens. |
|
1164 |
||
1165 |
Click on OK for saving an error report. |
|
1166 |
||
1167 |
Please contact LOLITech at: |
|
1168 |
+33 (0)3 29 52 95 67 |
|
1169 |
bugs_Beremiz@lolitech.fr |
|
1170 |
||
1171 |
||
1172 |
Error: |
|
1173 |
""" + |
|
1174 |
str(e_type) + " : " + str(e_value), |
|
1175 |
"Error", |
|
1176 |
trcbck_lst) |
|
1177 |
try: |
|
1178 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
1179 |
finally: |
|
1180 |
dlg.Destroy() |
|
1181 |
||
1182 |
return res |
|
1183 |
||
1184 |
def Display_Error_Dialog(e_value): |
|
1185 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
1186 |
message.ShowModal() |
|
1187 |
message.Destroy() |
|
1188 |
||
1189 |
def get_last_traceback(tb): |
|
1190 |
while tb.tb_next: |
|
1191 |
tb = tb.tb_next |
|
1192 |
return tb |
|
1193 |
||
1194 |
||
1195 |
def format_namespace(d, indent=' '): |
|
1196 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
1197 |
||
1198 |
||
1199 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
1200 |
||
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1201 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 1202 |
|
1203 |
def handle_exception(e_type, e_value, e_traceback): |
|
1204 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
1205 |
last_tb = get_last_traceback(e_traceback) |
|
1206 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
1207 |
if str(e_value).startswith("!!!"): |
|
1208 |
Display_Error_Dialog(e_value) |
|
1209 |
elif ex not in ignored_exceptions: |
|
1210 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
1211 |
if result: |
|
1212 |
ignored_exceptions.append(ex) |
|
1213 |
info = { |
|
1214 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
1215 |
'app-version' : app_version, |
|
1216 |
'wx-version' : wx.VERSION_STRING, |
|
1217 |
'wx-platform' : wx.Platform, |
|
1218 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
1219 |
'platform' : platform.platform(), |
|
1220 |
'e-type' : e_type, |
|
1221 |
'e-value' : e_value, |
|
1222 |
'date' : time.ctime(), |
|
1223 |
'cwd' : os.getcwd(), |
|
1224 |
} |
|
1225 |
if e_traceback: |
|
1226 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
1227 |
last_tb = get_last_traceback(e_traceback) |
|
1228 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
1229 |
info['locals'] = format_namespace(exception_locals) |
|
1230 |
if 'self' in exception_locals: |
|
1231 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1232 |
||
1233 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
1234 |
lst = info.keys() |
|
1235 |
lst.sort() |
|
1236 |
for a in lst: |
|
1237 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
1238 |
||
1239 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
1240 |
sys.excepthook = handle_exception |
|
1241 |
||
1242 |
if __name__ == '__main__': |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1243 |
def usage(): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1244 |
print "\nUsage of Beremiz.py :" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1245 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1246 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1247 |
try: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1248 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1249 |
except getopt.GetoptError: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1250 |
# print help information and exit: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1251 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1252 |
sys.exit(2) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1253 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1254 |
for o, a in opts: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1255 |
if o in ("-h", "--help"): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1256 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1257 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1258 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1259 |
if len(args) > 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1260 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1261 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1262 |
elif len(args) == 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1263 |
projectOpen = args[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1264 |
else: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1265 |
projectOpen = None |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1266 |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1267 |
app = wx.PySimpleApp() |
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1268 |
wx.InitAllImageHandlers() |
0 | 1269 |
|
1270 |
# Install a exception handle for bug reports |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1271 |
AddExceptHook(os.getcwd(),__version__) |
0 | 1272 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1273 |
frame = Beremiz(None, projectOpen) |
103 | 1274 |
|
1275 |
# Add beremiz's icon in top left corner of the frame |
|
102 | 1276 |
if wx.Platform == '__WXMSW__': |
103 | 1277 |
winicon = wx.Icon(os.path.join(CWD,"brz.ico"),wx.BITMAP_TYPE_ICO) |
1278 |
frame.SetIcon(winicon) |
|
1279 |
else: |
|
1280 |
linicon = wx.Icon(os.path.join(CWD,"brz.png"),wx.BITMAP_TYPE_PNG) |
|
1281 |
frame.SetIcon(linicon) |
|
1282 |
frame.Show() |
|
0 | 1283 |
app.MainLoop() |