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