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