author | lbessard |
Mon, 19 Nov 2007 17:23:01 +0100 | |
changeset 71 | e0bb49781b80 |
parent 69 | 6a331a809986 |
child 72 | dc107daa2135 |
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 |
|
1 | 40 |
class LogPseudoFile: |
41 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
42 |
def __init__(self, output = None): |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
43 |
self.red_white = wx.TextAttr("RED", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
44 |
self.red_yellow = wx.TextAttr("RED", "YELLOW") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
45 |
self.black_white = wx.TextAttr("BLACK", "WHITE") |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
46 |
self.default_style = None |
1 | 47 |
self.output = output |
48 |
||
49 |
def writelines(self, l): |
|
50 |
map(self.write, l) |
|
51 |
||
22 | 52 |
def write(self, s, style = None): |
53 |
if not style : style=self.black_white |
|
54 |
if self.default_style != style: |
|
55 |
self.output.SetDefaultStyle(style) |
|
56 |
self.default_style = style |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
57 |
self.output.AppendText(s) |
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
58 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
59 |
def write_warning(self, s): |
22 | 60 |
self.write(s,self.red_white) |
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
61 |
|
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
62 |
def write_error(self, s): |
22 | 63 |
self.write(s,self.red_yellow) |
1 | 64 |
|
65 |
def flush(self): |
|
66 |
self.output.SetValue("") |
|
67 |
||
68 |
def isatty(self): |
|
69 |
return false |
|
70 |
||
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
if self.exitcode != 0: |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
48
diff
changeset
|
92 |
self.write(Command + "\n") |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
48
diff
changeset
|
93 |
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
|
94 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
100 |
input = [] |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
101 |
p = wxPopen3(Command, input, output, errors, fin, self.output) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
102 |
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
|
103 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
46
diff
changeset
|
104 |
return (self.exitcode, self.outdata, self.errdata) |
20 | 105 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
106 |
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
107 |
ID_BEREMIZSECONDSPLITTER, ID_BEREMIZLEFTPANEL, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
108 |
ID_BEREMIZPARAMSPANEL, ID_BEREMIZLOGCONSOLE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
109 |
ID_BEREMIZPLUGINTREE, ID_BEREMIZPLUGINCHILDS, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
110 |
ID_BEREMIZADDBUTTON, ID_BEREMIZDELETEBUTTON, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
111 |
ID_BEREMIZPARAMSSTATICBOX, ID_BEREMIZPARAMSENABLE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
112 |
ID_BEREMIZPARAMSTARGETTYPE, ID_BEREMIZPARAMSIECCHANNEL, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
113 |
ID_BEREMIZPARAMSSTATICTEXT1, ID_BEREMIZPARAMSSTATICTEXT2, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
114 |
ID_BEREMIZPARAMSATTRIBUTESGRID, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
115 |
] = [wx.NewId() for _init_ctrls in range(17)] |
0 | 116 |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
117 |
[ID_BEREMIZFILEMENUITEMS0, ID_BEREMIZFILEMENUITEMS1, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
118 |
ID_BEREMIZFILEMENUITEMS2, ID_BEREMIZFILEMENUITEMS3, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
119 |
ID_BEREMIZFILEMENUITEMS5, ID_BEREMIZFILEMENUITEMS7, |
0 | 120 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)] |
121 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
122 |
[ID_BEREMIZEDITMENUITEMS0, ID_BEREMIZEDITMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
123 |
ID_BEREMIZEDITMENUITEMS3, |
0 | 124 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(3)] |
125 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
126 |
[ID_BEREMIZRUNMENUITEMS0, ID_BEREMIZRUNMENUITEMS2, |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
127 |
ID_BEREMIZRUNMENUITEMS3, ID_BEREMIZRUNMENUITEMS5, |
0 | 128 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
129 |
||
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
130 |
[ID_BEREMIZHELPMENUITEMS0, ID_BEREMIZHELPMENUITEMS1, |
0 | 131 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
132 |
||
133 |
class Beremiz(wx.Frame): |
|
134 |
||
135 |
def _init_coll_FileMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
136 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS0, |
0 | 137 |
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
|
138 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS1, |
0 | 139 |
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
|
140 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS2, |
0 | 141 |
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
|
142 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS3, |
0 | 143 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
144 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
145 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS5, |
0 | 146 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
147 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
148 |
parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS7, |
0 | 149 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
150 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
151 |
id=ID_BEREMIZFILEMENUITEMS0) |
0 | 152 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
153 |
id=ID_BEREMIZFILEMENUITEMS1) |
0 | 154 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
155 |
id=ID_BEREMIZFILEMENUITEMS2) |
0 | 156 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
157 |
id=ID_BEREMIZFILEMENUITEMS3) |
0 | 158 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
159 |
id=ID_BEREMIZFILEMENUITEMS5) |
0 | 160 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
161 |
id=ID_BEREMIZFILEMENUITEMS7) |
0 | 162 |
|
163 |
def _init_coll_EditMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
164 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS0, |
0 | 165 |
kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R') |
166 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
167 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS2, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
168 |
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
|
169 |
parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS3, |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
170 |
kind=wx.ITEM_NORMAL, text=u'Delete Plugin') |
0 | 171 |
self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
172 |
id=ID_BEREMIZEDITMENUITEMS0) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
173 |
self.Bind(wx.EVT_MENU, self.OnAddMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
174 |
id=ID_BEREMIZEDITMENUITEMS2) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
175 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
176 |
id=ID_BEREMIZEDITMENUITEMS3) |
0 | 177 |
|
178 |
def _init_coll_RunMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
179 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS0, |
0 | 180 |
kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R') |
181 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
182 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS2, |
0 | 183 |
kind=wx.ITEM_NORMAL, text=u'Simulate') |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
184 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS3, |
0 | 185 |
kind=wx.ITEM_NORMAL, text=u'Run') |
186 |
parent.AppendSeparator() |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
187 |
parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS5, |
0 | 188 |
kind=wx.ITEM_NORMAL, text=u'Save Log') |
1 | 189 |
self.Bind(wx.EVT_MENU, self.OnBuildMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
190 |
id=ID_BEREMIZRUNMENUITEMS0) |
0 | 191 |
self.Bind(wx.EVT_MENU, self.OnSimulateMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
192 |
id=ID_BEREMIZRUNMENUITEMS2) |
0 | 193 |
self.Bind(wx.EVT_MENU, self.OnRunMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
194 |
id=ID_BEREMIZRUNMENUITEMS3) |
0 | 195 |
self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
196 |
id=ID_BEREMIZRUNMENUITEMS5) |
0 | 197 |
|
198 |
def _init_coll_HelpMenu_Items(self, parent): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
199 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS0, |
0 | 200 |
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
|
201 |
parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS1, |
0 | 202 |
kind=wx.ITEM_NORMAL, text=u'About') |
203 |
self.Bind(wx.EVT_MENU, self.OnBeremizMenu, |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
204 |
id=ID_BEREMIZHELPMENUITEMS0) |
0 | 205 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
206 |
id=ID_BEREMIZHELPMENUITEMS1) |
0 | 207 |
|
208 |
def _init_coll_menuBar1_Menus(self, parent): |
|
209 |
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
|
210 |
#parent.Append(menu=self.EditMenu, title=u'Edit') |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
211 |
#parent.Append(menu=self.RunMenu, title=u'Run') |
0 | 212 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
213 |
||
214 |
def _init_utils(self): |
|
215 |
self.menuBar1 = wx.MenuBar() |
|
216 |
self.FileMenu = wx.Menu(title=u'') |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
217 |
#self.EditMenu = wx.Menu(title=u'') |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
218 |
#self.RunMenu = wx.Menu(title=u'') |
0 | 219 |
self.HelpMenu = wx.Menu(title=u'') |
220 |
||
221 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
222 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
223 |
#self._init_coll_EditMenu_Items(self.EditMenu) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
224 |
#self._init_coll_RunMenu_Items(self.RunMenu) |
0 | 225 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
226 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
227 |
def _init_coll_LeftGridSizer_Items(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
228 |
parent.AddWindow(self.PluginTree, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
229 |
parent.AddSizer(self.ButtonGridSizer, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
230 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
231 |
def _init_coll_LeftGridSizer_Growables(self, parent): |
0 | 232 |
parent.AddGrowableCol(0) |
233 |
parent.AddGrowableRow(0) |
|
234 |
||
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
235 |
def _init_coll_RightGridSizer_Items(self, parent): |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
236 |
parent.AddSizer(self.MenuSizer, 0, border=0, flag=wx.GROW) |
71 | 237 |
if wx.VERSION < (2, 8, 0): |
238 |
parent.AddWindow(self.SecondSplitter, 0, border=0, flag=wx.GROW) |
|
239 |
else: |
|
240 |
parent.AddWindow(self.ParamsPanel, 0, border=0, flag=wx.GROW) |
|
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
241 |
|
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
242 |
def _init_coll_RightGridSizer_Growables(self, parent): |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
243 |
parent.AddGrowableCol(0) |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
244 |
parent.AddGrowableRow(1) |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
245 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
246 |
def _init_coll_ButtonGridSizer_Items(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
247 |
parent.AddWindow(self.PluginChilds, 0, border=0, flag=wx.GROW) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
248 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
249 |
parent.AddWindow(self.DeleteButton, 0, border=0, flag=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
250 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
251 |
def _init_coll_ButtonGridSizer_Growables(self, parent): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
252 |
parent.AddGrowableCol(0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
253 |
parent.AddGrowableRow(0) |
0 | 254 |
|
255 |
def _init_sizers(self): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
256 |
self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
257 |
self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
258 |
self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=2, rows=1, vgap=2) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
259 |
self.MenuSizer = wx.BoxSizer(wx.HORIZONTAL) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
260 |
self.ParamsPanelMainSizer = wx.BoxSizer(wx.VERTICAL) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
261 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
262 |
self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
263 |
self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
264 |
self._init_coll_RightGridSizer_Growables(self.RightGridSizer) |
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
265 |
self._init_coll_RightGridSizer_Items(self.RightGridSizer) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
266 |
self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
267 |
self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
268 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
269 |
self.LeftPanel.SetSizer(self.LeftGridSizer) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
270 |
self.RightPanel.SetSizer(self.RightGridSizer) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
271 |
self.ParamsPanel.SetSizer(self.ParamsPanelMainSizer) |
0 | 272 |
|
273 |
def _init_ctrls(self, prnt): |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz') |
0 | 277 |
self._init_utils() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
278 |
self.SetClientSize(wx.Size(1000, 600)) |
0 | 279 |
self.SetMenuBar(self.menuBar1) |
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
280 |
self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated) |
0 | 281 |
|
71 | 282 |
if wx.VERSION >= (2, 8, 0): |
283 |
self.AUIManager = wx.aui.AuiManager(self) |
|
284 |
self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
|
285 |
||
286 |
if wx.VERSION < (2, 8, 0): |
|
287 |
self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER, |
|
288 |
name='MainSplitter', parent=self, point=wx.Point(0, 0), |
|
289 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
290 |
self.MainSplitter.SetNeedUpdating(True) |
|
291 |
self.MainSplitter.SetMinimumPaneSize(1) |
|
292 |
||
293 |
self.LeftPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, |
|
294 |
name='LeftPanel', parent=self.MainSplitter, pos=wx.Point(0, 0), |
|
295 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
296 |
else: |
|
297 |
self.LeftPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, |
|
298 |
name='LeftPanel', parent=self, pos=wx.Point(0, 0), |
|
299 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
300 |
self.AUIManager.AddPane(self.LeftPanel, wx.aui.AuiPaneInfo().Caption("Plugin Tree").Left().Layer(1).BestSize(wx.Size(300, 500)).CloseButton(False)) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
301 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
302 |
self.PluginTree = wx.TreeCtrl(id=ID_BEREMIZPLUGINTREE, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
303 |
name='PluginTree', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
304 |
size=wx.Size(-1, -1), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
305 |
self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
306 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
307 |
id=ID_BEREMIZPLUGINTREE) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
308 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
309 |
self.PluginChilds = wx.Choice(id=ID_BEREMIZPLUGINCHILDS, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
310 |
name='PluginChilds', parent=self.LeftPanel, pos=wx.Point(0, 0), |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
311 |
size=wx.Size(-1, -1), style=0) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
312 |
|
68 | 313 |
if wx.VERSION < (2, 8, 0): |
314 |
self.AddButton = wx.lib.buttons.GenBitmapButton(ID=ID_BEREMIZADDBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Add.png')), |
|
315 |
name='AddBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
|
316 |
size=wx.Size(32, 32), style=wx.NO_BORDER) |
|
317 |
else: |
|
318 |
self.AddButton = wx.lib.buttons.GenBitmapButton(id=ID_BEREMIZADDBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Add.png')), |
|
319 |
name='AddBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
|
320 |
size=wx.Size(32, 32), style=wx.NO_BORDER) |
|
321 |
||
65 | 322 |
self.AddButton.SetToolTipString("Add a plugin of the type selected") |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
323 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButton, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
324 |
id=ID_BEREMIZADDBUTTON) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
325 |
|
68 | 326 |
if wx.VERSION < (2, 8, 0): |
327 |
self.DeleteButton = wx.lib.buttons.GenBitmapButton(ID=ID_BEREMIZDELETEBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Delete.png')), |
|
328 |
name='DeleteBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
|
329 |
size=wx.Size(32, 32), style=wx.NO_BORDER) |
|
330 |
else: |
|
331 |
self.DeleteButton = wx.lib.buttons.GenBitmapButton(id=ID_BEREMIZDELETEBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Delete.png')), |
|
332 |
name='DeleteBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0), |
|
333 |
size=wx.Size(32, 32), style=wx.NO_BORDER) |
|
65 | 334 |
self.DeleteButton.SetToolTipString("Delete the current selected plugin") |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
335 |
self.DeleteButton.Bind(wx.EVT_BUTTON, self.OnDeleteButton, |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
336 |
id=ID_BEREMIZDELETEBUTTON) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
337 |
|
71 | 338 |
if wx.VERSION < (2, 8, 0): |
339 |
self.RightPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, |
|
340 |
name='RightPanel', parent=self.MainSplitter, pos=wx.Point(0, 0), |
|
341 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
342 |
||
343 |
self.SecondSplitter = wx.SplitterWindow(id=ID_BEREMIZSECONDSPLITTER, |
|
344 |
name='SecondSplitter', parent=self.RightPanel, point=wx.Point(0, 0), |
|
345 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
346 |
self.SecondSplitter.SetNeedUpdating(True) |
|
347 |
self.SecondSplitter.SetMinimumPaneSize(1) |
|
348 |
||
349 |
self.MainSplitter.SplitVertically(self.LeftPanel, self.RightPanel, |
|
350 |
300) |
|
351 |
||
352 |
self.ParamsPanel = wx.ScrolledWindow(id=ID_BEREMIZPARAMSPANEL, |
|
353 |
name='ParamsPanel', parent=self.SecondSplitter, pos=wx.Point(0, 0), |
|
354 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
355 |
self.ParamsPanel.SetScrollbars(10, 10, 0, 0, 0, 0) |
|
356 |
||
357 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
|
358 |
name='LogConsole', parent=self.SecondSplitter, pos=wx.Point(0, 0), |
|
359 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
|
360 |
||
361 |
self.SecondSplitter.SplitHorizontally(self.ParamsPanel, self.LogConsole, |
|
362 |
-250) |
|
363 |
else: |
|
364 |
self.RightPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, |
|
365 |
name='RightPanel', parent=self, pos=wx.Point(0, 0), |
|
366 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
367 |
self.AUIManager.AddPane(self.RightPanel, wx.aui.AuiPaneInfo().CenterPane()) |
|
368 |
||
369 |
self.ParamsPanel = wx.ScrolledWindow(id=ID_BEREMIZPARAMSPANEL, |
|
370 |
name='ParamsPanel', parent=self.RightPanel, pos=wx.Point(0, 0), |
|
371 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
372 |
self.ParamsPanel.SetScrollbars(10, 10, 0, 0, 0, 0) |
|
373 |
||
374 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
|
375 |
name='LogConsole', parent=self, pos=wx.Point(0, 0), |
|
376 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
|
377 |
self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo().Caption("Log Console").Bottom().Layer(0).BestSize(wx.Size(800, 200)).CloseButton(False)) |
|
378 |
||
379 |
self.AUIManager.Update() |
|
0 | 380 |
|
381 |
self._init_sizers() |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
382 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
383 |
def __init__(self, parent, projectOpen): |
0 | 384 |
self._init_ctrls(parent) |
385 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
386 |
self.Log = LogPseudoFile(self.LogConsole) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
387 |
|
20 | 388 |
self.PluginRoot = PluginsRoot(self) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
389 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
390 |
if projectOpen: |
24 | 391 |
self.PluginRoot.LoadProject(projectOpen, self.Log) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
392 |
self.RefreshPluginTree() |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
48
diff
changeset
|
393 |
self.PluginTree.SelectItem(self.PluginTree.GetRootItem()) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
394 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
395 |
self.RefreshPluginParams() |
0 | 396 |
self.RefreshButtons() |
397 |
self.RefreshMainMenu() |
|
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
398 |
|
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
399 |
def OnFrameActivated(self, event): |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
400 |
if not event.GetActive(): |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
401 |
self.PluginRoot.RefreshPluginsBlockLists() |
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
402 |
|
0 | 403 |
def RefreshButtons(self): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
404 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
405 |
self.PluginChilds.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
406 |
self.AddButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
407 |
self.DeleteButton.Enable(True) |
0 | 408 |
else: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
409 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
410 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
411 |
self.DeleteButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
412 |
|
0 | 413 |
def RefreshMainMenu(self): |
414 |
if self.menuBar1: |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
415 |
if self.PluginRoot.HasProjectOpened(): |
42 | 416 |
## self.menuBar1.EnableTop(1, True) |
417 |
## self.menuBar1.EnableTop(2, True) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
418 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
419 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
420 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
421 |
else: |
42 | 422 |
## self.menuBar1.EnableTop(1, False) |
423 |
## self.menuBar1.EnableTop(2, False) |
|
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
424 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
425 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, False) |
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
426 |
self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, False) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
427 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
428 |
def RefreshPluginTree(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
429 |
infos = self.PluginRoot.GetPlugInfos() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
430 |
root = self.PluginTree.GetRootItem() |
21 | 431 |
if not root.IsOk(): |
432 |
root = self.PluginTree.AddRoot(infos["name"]) |
|
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
433 |
last_selected = self.GetSelectedPluginName() |
21 | 434 |
self.GenerateTreeBranch(root, infos, True) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
435 |
self.PluginTree.Expand(self.PluginTree.GetRootItem()) |
46 | 436 |
self.SelectedPluginByName(root, last_selected) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
437 |
self.RefreshPluginParams() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
438 |
|
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
439 |
def SelectedPluginByName(self, root, name): |
46 | 440 |
if name: |
441 |
toks = name.split('.',1) |
|
442 |
item, root_cookie = self.PluginTree.GetFirstChild(root) |
|
443 |
while item.IsOk(): |
|
444 |
if self.PluginTree.GetPyData(item) == toks[0]: |
|
445 |
if len(toks)>1: |
|
446 |
return self.SelectedPluginByName(item, toks[1]) |
|
447 |
else: |
|
448 |
self.PluginTree.SelectItem(item, True) |
|
449 |
return True |
|
450 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
|
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
451 |
return False |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
452 |
|
21 | 453 |
def GenerateTreeBranch(self, root, infos, first = False): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
454 |
to_delete = [] |
21 | 455 |
self.PluginTree.SetItemText(root, infos["name"]) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
456 |
self.PluginTree.SetPyData(root, infos["type"]) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
457 |
item, root_cookie = self.PluginTree.GetFirstChild(root) |
21 | 458 |
for values in infos["values"]: |
459 |
if not item.IsOk(): |
|
460 |
item = self.PluginTree.AppendItem(root, "") |
|
60 | 461 |
if wx.Platform != '__WXMSW__': |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
462 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
21 | 463 |
self.GenerateTreeBranch(item, values) |
464 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
465 |
while item.IsOk(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
466 |
to_delete.append(item) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
467 |
item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
468 |
for item in to_delete: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
469 |
self.PluginTree.Delete(item) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
470 |
|
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
471 |
def GetSelectedPluginName(self): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
472 |
selected = self.PluginTree.GetSelection() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
473 |
if not selected.IsOk(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
474 |
return None |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
475 |
if selected == self.PluginTree.GetRootItem(): |
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
476 |
return "" |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
477 |
else: |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
478 |
name = self.PluginTree.GetPyData(selected) |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
479 |
item = self.PluginTree.GetItemParent(selected) |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
480 |
while item.IsOk() and item != self.PluginTree.GetRootItem(): |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
481 |
name = "%s.%s"%(self.PluginTree.GetPyData(item), name) |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
482 |
item = self.PluginTree.GetItemParent(item) |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
483 |
return name |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
484 |
|
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
485 |
def GetSelectedPlugin(self): |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
486 |
name = self.GetSelectedPluginName() |
36 | 487 |
if name is None: |
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
488 |
return None |
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
28
diff
changeset
|
489 |
elif name == "": |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
490 |
return self.PluginRoot |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
491 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
492 |
return self.PluginRoot.GetChildByName(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
493 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
494 |
def OnPluginTreeItemSelected(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
495 |
wx.CallAfter(self.RefreshPluginParams) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
496 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
497 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
498 |
def _GetAddPluginFunction(self, name): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
499 |
def OnPluginMenu(event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
500 |
self.AddPlugin(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
501 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
502 |
return OnPluginMenu |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
503 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
504 |
def OnPluginTreeRightUp(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
505 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
506 |
if plugin: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
507 |
main_menu = wx.Menu(title='') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
508 |
if len(plugin.PlugChildsTypes) > 0: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
509 |
plugin_menu = wx.Menu(title='') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
510 |
for name, XSDClass in self.GetSelectedPlugin().PlugChildsTypes: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
511 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
512 |
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
|
513 |
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
|
514 |
main_menu.AppendMenu(-1, "Add", plugin_menu, '') |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
515 |
new_id = wx.NewId() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
516 |
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
|
517 |
self.Bind(wx.EVT_MENU, self.OnDeleteButton, id=new_id) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
518 |
rect = self.PluginTree.GetBoundingRect(self.PluginTree.GetSelection()) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
519 |
self.PluginTree.PopupMenuXY(main_menu, rect.x + rect.width, rect.y) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
520 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
521 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
522 |
def RefreshPluginParams(self): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
523 |
plugin = self.GetSelectedPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
524 |
if not plugin: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
525 |
# Refresh ParamsPanel |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
526 |
self.ParamsPanel.Hide() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
527 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
528 |
# Refresh PluginChilds |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
529 |
self.PluginChilds.Clear() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
530 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
531 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
532 |
self.DeleteButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
533 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
534 |
# Refresh ParamsPanel |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
535 |
self.ParamsPanel.Show() |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
536 |
infos = plugin.GetParamsAttributes() |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
537 |
if wx.VERSION >= (2, 7, 0): |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
538 |
self.MenuSizer.Clear(True) |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
539 |
self.ParamsPanelMainSizer.Clear(True) |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
540 |
else: |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
541 |
self.ClearSizer(self.MenuSizer) |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
542 |
self.ClearSizer(self.ParamsPanelMainSizer) |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
543 |
if len(self.PluginRoot.PluginMethods) > 0: |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
544 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
545 |
self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
65 | 546 |
for plugin_infos in self.PluginRoot.PluginMethods: |
547 |
if "method" in plugin_infos: |
|
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
548 |
id = wx.NewId() |
65 | 549 |
if "bitmap" in plugin_infos: |
68 | 550 |
if wx.VERSION < (2, 8, 0): |
551 |
button = wx.lib.buttons.GenBitmapTextButton(ID=id, parent=self.RightPanel, |
|
552 |
bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], |
|
553 |
name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER) |
|
554 |
else: |
|
555 |
button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=self.RightPanel, |
|
556 |
bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], |
|
557 |
name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER) |
|
558 |
||
65 | 559 |
else: |
560 |
button = wx.Button(id=id, label=plugin_infos["name"], |
|
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
561 |
name=plugin_infos["name"], parent=self.RightPanel, |
65 | 562 |
pos=wx.Point(0, 0), style=wx.BU_EXACTFIT) |
563 |
button.SetToolTipString(plugin_infos["tooltip"]) |
|
564 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(self.PluginRoot, plugin_infos["method"]), id=id) |
|
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
565 |
boxsizer.AddWindow(button, 0, border=5, flag=wx.GROW|wx.RIGHT) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
566 |
self.RightGridSizer.Layout() |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
567 |
self.RefreshSizerElement(self.ParamsPanelMainSizer, infos, None, False) |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
568 |
if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0: |
21 | 569 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
570 |
self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
65 | 571 |
for plugin_infos in plugin.PluginMethods: |
572 |
if "method" in plugin_infos: |
|
21 | 573 |
id = wx.NewId() |
65 | 574 |
if "bitmap" in plugin_infos: |
68 | 575 |
if wx.VERSION < (2, 8, 0): |
576 |
button = wx.lib.buttons.GenBitmapTextButton(ID=id, parent=self.RightPanel, |
|
577 |
bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], |
|
578 |
name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER) |
|
579 |
else: |
|
580 |
button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=self.RightPanel, |
|
581 |
bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], |
|
582 |
name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER) |
|
65 | 583 |
else: |
584 |
button = wx.Button(id=id, label=plugin_infos["name"], |
|
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
585 |
name=plugin_infos["name"], parent=self.RightPanel, |
65 | 586 |
pos=wx.Point(0, 0), style=wx.BU_EXACTFIT) |
587 |
button.SetToolTipString(plugin_infos["tooltip"]) |
|
588 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_infos["method"]), id=id) |
|
21 | 589 |
boxsizer.AddWindow(button, 0, border=5, flag=wx.GROW|wx.RIGHT) |
67
862da764c5b5
Layout changed for making buttons at top of the frame always visible
lbessard
parents:
65
diff
changeset
|
590 |
self.RightGridSizer.Layout() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
591 |
self.ParamsPanelMainSizer.Layout() |
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
592 |
self.ParamsPanel.SetClientSize(self.ParamsPanel.GetClientSize()) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
593 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
594 |
# Refresh PluginChilds |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
595 |
self.PluginChilds.Clear() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
596 |
if len(plugin.PlugChildsTypes) > 0: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
597 |
self.PluginChilds.Append("") |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
598 |
for name, XSDClass in plugin.PlugChildsTypes: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
599 |
self.PluginChilds.Append(name) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
600 |
self.PluginChilds.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
601 |
self.AddButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
602 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
603 |
self.PluginChilds.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
604 |
self.AddButton.Enable(False) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
605 |
self.DeleteButton.Enable(True) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
606 |
|
21 | 607 |
def GetButtonCallBackFunction(self, plugin, method): |
608 |
def OnButtonClick(event): |
|
609 |
method(plugin, self.Log) |
|
610 |
event.Skip() |
|
611 |
return OnButtonClick |
|
612 |
||
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
613 |
def GetChoiceCallBackFunction(self, choicectrl, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
614 |
def OnChoiceChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
615 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
616 |
if plugin: |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
617 |
res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
618 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
619 |
choicectrl.SetStringSelection(res) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
620 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
621 |
return OnChoiceChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
622 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
623 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
624 |
def OnChoiceContentChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
625 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
626 |
if plugin: |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
627 |
res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
628 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
629 |
choicectrl.SetStringSelection(res) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
630 |
infos = self.PluginRoot.GetParamsAttributes(path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
631 |
staticbox = staticboxsizer.GetStaticBox() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
632 |
staticbox.SetLabel("%(name)s - %(value)s"%infos) |
21 | 633 |
self.ParamsPanel.Freeze() |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
634 |
self.RefreshSizerElement(staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"])) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
635 |
self.ParamsPanelMainSizer.Layout() |
21 | 636 |
self.ParamsPanel.Thaw() |
637 |
self.ParamsPanel.Refresh() |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
638 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
639 |
return OnChoiceContentChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
640 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
641 |
def GetTextCtrlCallBackFunction(self, textctrl, path): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
642 |
def OnTextCtrlChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
643 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
644 |
if plugin: |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
645 |
res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
646 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
647 |
textctrl.SetValue(res) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
648 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
649 |
return OnTextCtrlChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
650 |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
651 |
def GetCheckBoxCallBackFunction(self, chkbx, path): |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
652 |
def OnCheckBoxChanged(event): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
653 |
plugin = self.GetSelectedPlugin() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
654 |
if plugin: |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
655 |
res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
656 |
if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
657 |
chkbx.SetValue(res) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
658 |
event.Skip() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
659 |
return OnCheckBoxChanged |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
660 |
|
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
661 |
def ClearSizer(self, sizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
662 |
staticboxes = [] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
663 |
for item in sizer.GetChildren(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
664 |
if item.IsSizer(): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
665 |
item_sizer = item.GetSizer() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
666 |
self.ClearSizer(item_sizer) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
667 |
if isinstance(item_sizer, wx.StaticBoxSizer): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
668 |
staticboxes.append(item_sizer.GetStaticBox()) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
669 |
sizer.Clear(True) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
670 |
for staticbox in staticboxes: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
671 |
staticbox.Destroy() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
672 |
|
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
673 |
def RefreshSizerElement(self, sizer, elements, path, clean = True): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
674 |
if clean: |
62
ddf0cdd71558
Adding support for refresh block list where beremiz loose focus
lbessard
parents:
60
diff
changeset
|
675 |
sizer.Clear(True) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
676 |
first = True |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
677 |
for element_infos in elements: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
678 |
if path: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
679 |
element_path = "%s.%s"%(path, element_infos["name"]) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
680 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
681 |
element_path = element_infos["name"] |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
682 |
if isinstance(element_infos["type"], types.ListType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
683 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
684 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
685 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
686 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
687 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 688 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
689 |
if os.path.isfile(bitmappath): |
|
690 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
691 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel, |
|
692 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
693 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
694 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
695 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
696 |
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
|
697 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
698 |
id = wx.NewId() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
699 |
choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
700 |
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
|
701 |
boxsizer.AddWindow(choicectrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
702 |
choicectrl.Append("") |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
703 |
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
|
704 |
for choice, xsdclass in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
705 |
choicectrl.Append(choice) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
706 |
staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
707 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
708 |
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
|
709 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
710 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
711 |
self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
712 |
callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
713 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
714 |
for choice in element_infos["type"]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
715 |
choicectrl.Append(choice) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
716 |
callback = self.GetChoiceCallBackFunction(choicectrl, element_path) |
22 | 717 |
if element_infos["value"]: |
718 |
choicectrl.SetStringSelection(element_infos["value"]) |
|
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
719 |
choicectrl.Bind(wx.EVT_CHOICE, callback, id=id) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
720 |
elif isinstance(element_infos["type"], types.DictType): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
721 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
722 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
723 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
724 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
725 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 726 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
727 |
if os.path.isfile(bitmappath): |
|
728 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
729 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel, |
|
730 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
731 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
732 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
733 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
734 |
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
|
735 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
736 |
id = wx.NewId() |
23 | 737 |
scmin = -(2**31) |
738 |
scmax = 2**31-1 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
739 |
if "min" in element_infos["type"]: |
23 | 740 |
scmin = element_infos["type"]["min"] |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
741 |
if "max" in element_infos["type"]: |
23 | 742 |
scmax = element_infos["type"]["max"] |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
743 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
23 | 744 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
745 |
spinctrl.SetRange(scmin,scmax) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
746 |
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
|
747 |
spinctrl.SetValue(element_infos["value"]) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
748 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
749 |
elif element_infos["type"] == "element": |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
750 |
staticbox = wx.StaticBox(id=-1, label=element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
751 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
752 |
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
|
753 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
754 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
755 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
756 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
757 |
sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
758 |
self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
759 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
760 |
boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
761 |
if first: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
762 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
763 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
764 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
65 | 765 |
bitmappath = os.path.join("images", "%s.png"%element_infos["name"]) |
766 |
if os.path.isfile(bitmappath): |
|
767 |
staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
|
768 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel, |
|
769 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
770 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
771 |
statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
772 |
name="%s_label"%element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
773 |
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
|
774 |
boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
775 |
id = wx.NewId() |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
776 |
if element_infos["type"] == "boolean": |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
777 |
checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
778 |
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
|
779 |
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
|
780 |
checkbox.SetValue(element_infos["value"]) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
781 |
checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
782 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
23 | 783 |
if element_infos["type"].startswith("unsigned"): |
784 |
scmin = 0 |
|
785 |
else: |
|
786 |
scmin = -(2**31) |
|
787 |
scmax = 2**31-1 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
788 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
789 |
pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
23 | 790 |
spinctrl.SetRange(scmin, scmax) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
791 |
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
|
792 |
spinctrl.SetValue(element_infos["value"]) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
793 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
794 |
else: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
795 |
textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
796 |
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
|
797 |
boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
798 |
textctrl.SetValue(str(element_infos["value"])) |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
799 |
textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, element_path), id=id) |
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
800 |
textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, element_path)) |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
801 |
first = False |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
802 |
|
0 | 803 |
def OnNewProjectMenu(self, event): |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
804 |
defaultpath = self.PluginRoot.GetProjectPath() |
22 | 805 |
if not defaultpath: |
0 | 806 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
807 |
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
|
808 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 809 |
projectpath = dialog.GetPath() |
810 |
dialog.Destroy() |
|
20 | 811 |
res = self.PluginRoot.NewProject(projectpath) |
812 |
if not res : |
|
813 |
self.RefreshPluginTree() |
|
814 |
self.RefreshButtons() |
|
815 |
self.RefreshMainMenu() |
|
0 | 816 |
else: |
20 | 817 |
message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 818 |
message.ShowModal() |
819 |
message.Destroy() |
|
820 |
event.Skip() |
|
821 |
||
822 |
def OnOpenProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
823 |
defaultpath = self.PluginRoot.GetProjectPath() |
20 | 824 |
if not defaultpath: |
0 | 825 |
defaultpath = os.getcwd() |
4
e9d061c23e83
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
3
diff
changeset
|
826 |
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
|
827 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
828 |
projectpath = dialog.GetPath() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
829 |
if os.path.isdir(projectpath): |
24 | 830 |
result = self.PluginRoot.LoadProject(projectpath, self.Log) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
831 |
if not result: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
832 |
self.RefreshPluginTree() |
46 | 833 |
self.PluginTree.SelectItem(self.PluginTree.GetRootItem()) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
834 |
self.RefreshButtons() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
835 |
self.RefreshMainMenu() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
836 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
837 |
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
|
838 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
839 |
message.Destroy() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
840 |
else: |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
841 |
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
|
842 |
message.ShowModal() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
843 |
message.Destroy() |
0 | 844 |
dialog.Destroy() |
845 |
event.Skip() |
|
846 |
||
847 |
def OnCloseProjectMenu(self, event): |
|
848 |
self.PLCManager = None |
|
849 |
self.RefreshButtons() |
|
850 |
self.RefreshMainMenu() |
|
851 |
event.Skip() |
|
852 |
||
853 |
def OnSaveProjectMenu(self, event): |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
854 |
if self.PluginRoot.HasProjectOpened(): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
855 |
self.PluginRoot.SaveProject() |
0 | 856 |
event.Skip() |
857 |
||
858 |
def OnPropertiesMenu(self, event): |
|
859 |
event.Skip() |
|
860 |
||
861 |
def OnQuitMenu(self, event): |
|
862 |
self.Close() |
|
863 |
event.Skip() |
|
864 |
||
865 |
def OnEditPLCMenu(self, event): |
|
866 |
self.EditPLC() |
|
867 |
event.Skip() |
|
868 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
869 |
def OnAddMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
870 |
self.AddPlugin() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
871 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
872 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
873 |
def OnDeleteMenu(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
874 |
self.DeletePlugin() |
0 | 875 |
event.Skip() |
876 |
||
1 | 877 |
def OnBuildMenu(self, event): |
20 | 878 |
#self.BuildAutom() |
1 | 879 |
event.Skip() |
880 |
||
0 | 881 |
def OnSimulateMenu(self, event): |
882 |
event.Skip() |
|
883 |
||
884 |
def OnRunMenu(self, event): |
|
885 |
event.Skip() |
|
886 |
||
887 |
def OnSaveLogMenu(self, event): |
|
888 |
event.Skip() |
|
889 |
||
890 |
def OnBeremizMenu(self, event): |
|
891 |
event.Skip() |
|
892 |
||
893 |
def OnAboutMenu(self, event): |
|
894 |
event.Skip() |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
895 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
896 |
def OnAddButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
897 |
PluginType = self.PluginChilds.GetStringSelection() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
898 |
if PluginType != "": |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
899 |
self.AddPlugin(PluginType) |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
900 |
event.Skip() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
901 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
902 |
def OnDeleteButton(self, event): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
903 |
self.DeletePlugin() |
0 | 904 |
event.Skip() |
905 |
||
906 |
def CloseEditor(self, bus_id): |
|
907 |
if self.BusManagers.get(bus_id, None) != None: |
|
908 |
self.BusManagers[bus_id]["Editor"] = None |
|
909 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
910 |
def AddPlugin(self, PluginType): |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
911 |
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
|
912 |
if dialog.ShowModal() == wx.ID_OK: |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
913 |
PluginName = dialog.GetValue() |
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
914 |
plugin = self.GetSelectedPlugin() |
28
848ce4b1f9e4
Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents:
25
diff
changeset
|
915 |
plugin.PlugAddChild(PluginName, PluginType, self.Log) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
916 |
self.RefreshPluginTree() |
0 | 917 |
dialog.Destroy() |
918 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
13
diff
changeset
|
919 |
def DeletePlugin(self): |
50 | 920 |
dialog = wx.MessageDialog(self,"Really delete plugin ?", "Remove plugin",wx.YES_NO|wx.NO_DEFAULT) |
921 |
if dialog.ShowModal() == wx.ID_YES: |
|
922 |
plugin = self.GetSelectedPlugin() |
|
923 |
plugin.PlugRemove() |
|
924 |
del plugin |
|
925 |
self.RefreshPluginTree() |
|
926 |
dialog.Destroy() |
|
7
e20fa7257d41
Added stdout/stderr separation limitation and coloration
etisserant
parents:
6
diff
changeset
|
927 |
|
0 | 928 |
#------------------------------------------------------------------------------- |
929 |
# Exception Handler |
|
930 |
#------------------------------------------------------------------------------- |
|
931 |
||
932 |
Max_Traceback_List_Size = 20 |
|
933 |
||
934 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
935 |
trcbck_lst = [] |
|
936 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
937 |
trcbck = " " + str(i+1) + ". " |
|
938 |
if line[0].find(os.getcwd()) == -1: |
|
939 |
trcbck += "file : " + str(line[0]) + ", " |
|
940 |
else: |
|
941 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
942 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
943 |
trcbck_lst.append(trcbck) |
|
944 |
||
945 |
# Allow clicking.... |
|
946 |
cap = wx.Window_GetCapture() |
|
947 |
if cap: |
|
948 |
cap.ReleaseMouse() |
|
949 |
||
950 |
dlg = wx.SingleChoiceDialog(None, |
|
951 |
""" |
|
952 |
An error happens. |
|
953 |
||
954 |
Click on OK for saving an error report. |
|
955 |
||
956 |
Please contact LOLITech at: |
|
957 |
+33 (0)3 29 52 95 67 |
|
958 |
bugs_Beremiz@lolitech.fr |
|
959 |
||
960 |
||
961 |
Error: |
|
962 |
""" + |
|
963 |
str(e_type) + " : " + str(e_value), |
|
964 |
"Error", |
|
965 |
trcbck_lst) |
|
966 |
try: |
|
967 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
968 |
finally: |
|
969 |
dlg.Destroy() |
|
970 |
||
971 |
return res |
|
972 |
||
973 |
def Display_Error_Dialog(e_value): |
|
974 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
975 |
message.ShowModal() |
|
976 |
message.Destroy() |
|
977 |
||
978 |
def get_last_traceback(tb): |
|
979 |
while tb.tb_next: |
|
980 |
tb = tb.tb_next |
|
981 |
return tb |
|
982 |
||
983 |
||
984 |
def format_namespace(d, indent=' '): |
|
985 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
986 |
||
987 |
||
988 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
989 |
||
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
990 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 991 |
|
992 |
def handle_exception(e_type, e_value, e_traceback): |
|
993 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
994 |
last_tb = get_last_traceback(e_traceback) |
|
995 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
996 |
if str(e_value).startswith("!!!"): |
|
997 |
Display_Error_Dialog(e_value) |
|
998 |
elif ex not in ignored_exceptions: |
|
999 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
1000 |
if result: |
|
1001 |
ignored_exceptions.append(ex) |
|
1002 |
info = { |
|
1003 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
1004 |
'app-version' : app_version, |
|
1005 |
'wx-version' : wx.VERSION_STRING, |
|
1006 |
'wx-platform' : wx.Platform, |
|
1007 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
1008 |
'platform' : platform.platform(), |
|
1009 |
'e-type' : e_type, |
|
1010 |
'e-value' : e_value, |
|
1011 |
'date' : time.ctime(), |
|
1012 |
'cwd' : os.getcwd(), |
|
1013 |
} |
|
1014 |
if e_traceback: |
|
1015 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
1016 |
last_tb = get_last_traceback(e_traceback) |
|
1017 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
1018 |
info['locals'] = format_namespace(exception_locals) |
|
1019 |
if 'self' in exception_locals: |
|
1020 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1021 |
||
1022 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
1023 |
lst = info.keys() |
|
1024 |
lst.sort() |
|
1025 |
for a in lst: |
|
1026 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
1027 |
||
1028 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
1029 |
sys.excepthook = handle_exception |
|
1030 |
||
1031 |
if __name__ == '__main__': |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1032 |
def usage(): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1033 |
print "\nUsage of Beremiz.py :" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1034 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1035 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1036 |
try: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1037 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1038 |
except getopt.GetoptError: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1039 |
# print help information and exit: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1040 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1041 |
sys.exit(2) |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1042 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1043 |
for o, a in opts: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1044 |
if o in ("-h", "--help"): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1045 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1046 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1047 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1048 |
if len(args) > 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1049 |
usage() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1050 |
sys.exit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1051 |
elif len(args) == 1: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1052 |
projectOpen = args[0] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1053 |
else: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1054 |
projectOpen = None |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1055 |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1056 |
app = wx.PySimpleApp() |
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1057 |
wx.InitAllImageHandlers() |
0 | 1058 |
|
1059 |
# Install a exception handle for bug reports |
|
5
9565bb5facf7
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
4
diff
changeset
|
1060 |
AddExceptHook(os.getcwd(),__version__) |
0 | 1061 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
1062 |
frame = Beremiz(None, projectOpen) |
0 | 1063 |
|
1064 |
frame.Show() |
|
1065 |
app.MainLoop() |