34 |
34 |
35 import os, re, platform, sys, time, traceback, getopt, commands |
35 import os, re, platform, sys, time, traceback, getopt, commands |
36 |
36 |
37 from plugger import PluginsRoot |
37 from plugger import PluginsRoot |
38 |
38 |
39 from wxPopen import wxPopen3 |
|
40 |
|
41 SCROLLBAR_UNIT = 10 |
39 SCROLLBAR_UNIT = 10 |
42 WINDOW_COLOUR = wx.Colour(240,240,240) |
40 WINDOW_COLOUR = wx.Colour(240,240,240) |
43 TITLE_COLOUR = wx.Colour(200,200,220) |
41 TITLE_COLOUR = wx.Colour(200,200,220) |
44 |
42 |
45 if wx.Platform == '__WXMSW__': |
43 if wx.Platform == '__WXMSW__': |
70 button.SetBezelWidth(0) |
68 button.SetBezelWidth(0) |
71 button.SetUseFocusIndicator(False) |
69 button.SetUseFocusIndicator(False) |
72 |
70 |
73 # Patch wx.lib.imageutils so that gray is supported on alpha images |
71 # Patch wx.lib.imageutils so that gray is supported on alpha images |
74 import wx.lib.imageutils |
72 import wx.lib.imageutils |
|
73 from wx.lib.imageutils import grayOut as old_grayOut |
75 def grayOut(anImage): |
74 def grayOut(anImage): |
76 """ |
|
77 Convert the given image (in place) to a grayed-out |
|
78 version, appropriate for a 'disabled' appearance. |
|
79 """ |
|
80 factor = 0.7 # 0 < f < 1. Higher is grayer. |
|
81 if anImage.HasMask(): |
|
82 maskColor = (anImage.GetMaskRed(), anImage.GetMaskGreen(), anImage.GetMaskBlue()) |
|
83 else: |
|
84 maskColor = None |
|
85 |
|
86 if anImage.HasAlpha(): |
75 if anImage.HasAlpha(): |
87 AlphaData = anImage.GetAlphaData() |
76 AlphaData = anImage.GetAlphaData() |
88 else : |
77 else : |
89 AlphaData = None |
78 AlphaData = None |
90 |
79 |
91 data = map(ord, list(anImage.GetData())) |
80 old_grayOut(anImage) |
92 |
|
93 for i in range(0, len(data), 3): |
|
94 pixel = (data[i], data[i+1], data[i+2]) |
|
95 pixel = wx.lib.imageutils.makeGray(pixel, factor, maskColor) |
|
96 for x in range(3): |
|
97 data[i+x] = pixel[x] |
|
98 anImage.SetData(''.join(map(chr, data))) |
|
99 |
81 |
100 if AlphaData is not None: |
82 if AlphaData is not None: |
101 anImage.SetAlphaData(AlphaData) |
83 anImage.SetAlphaData(AlphaData) |
102 |
84 |
103 wx.lib.imageutils.grayOut = grayOut |
85 wx.lib.imageutils.grayOut = grayOut |
134 dc.DrawBitmap(self._bitmap, 0, 0, True) |
116 dc.DrawBitmap(self._bitmap, 0, 0, True) |
135 |
117 |
136 |
118 |
137 class LogPseudoFile: |
119 class LogPseudoFile: |
138 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
120 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
139 def __init__(self, output = None): |
121 def __init__(self, output): |
140 self.red_white = wx.TextAttr("RED", "WHITE") |
122 self.red_white = wx.TextAttr("RED", "WHITE") |
141 self.red_yellow = wx.TextAttr("RED", "YELLOW") |
123 self.red_yellow = wx.TextAttr("RED", "YELLOW") |
142 self.black_white = wx.TextAttr("BLACK", "WHITE") |
124 self.black_white = wx.TextAttr("BLACK", "WHITE") |
143 self.default_style = None |
125 self.default_style = None |
144 self.output = output |
126 self.output = output |
145 |
127 |
146 def writelines(self, l): |
|
147 map(self.write, l) |
|
148 |
|
149 def write(self, s, style = None): |
128 def write(self, s, style = None): |
150 if not style : style=self.black_white |
129 if style is None : style=self.black_white |
|
130 self.output.Freeze(); |
151 if self.default_style != style: |
131 if self.default_style != style: |
152 self.output.SetDefaultStyle(style) |
132 self.output.SetDefaultStyle(style) |
153 self.default_style = style |
133 self.default_style = style |
154 self.output.AppendText(s) |
134 self.output.AppendText(s) |
|
135 self.output.ScrollLines(s.count('\n')+1) |
|
136 self.output.ShowPosition(self.output.GetLastPosition()) |
|
137 self.output.Thaw() |
155 |
138 |
156 def write_warning(self, s): |
139 def write_warning(self, s): |
157 self.write(s,self.red_white) |
140 self.write(s,self.red_white) |
158 |
141 |
159 def write_error(self, s): |
142 def write_error(self, s): |
162 def flush(self): |
145 def flush(self): |
163 self.output.SetValue("") |
146 self.output.SetValue("") |
164 |
147 |
165 def isatty(self): |
148 def isatty(self): |
166 return false |
149 return false |
167 |
|
168 def LogCommand(self, Command, sz_limit = 100, no_stdout=False): |
|
169 self.errlen = 0 |
|
170 self.exitcode = None |
|
171 self.outdata = "" |
|
172 self.errdata = "" |
|
173 |
|
174 def output(v): |
|
175 self.outdata += v |
|
176 if not no_stdout: |
|
177 self.write(v) |
|
178 |
|
179 def errors(v): |
|
180 self.errdata += v |
|
181 self.errlen += 1 |
|
182 if self.errlen > sz_limit: |
|
183 p.kill() |
|
184 self.write_warning(v) |
|
185 |
|
186 def fin(pid,ecode): |
|
187 self.exitcode = ecode |
|
188 if self.exitcode != 0: |
|
189 self.write(Command + "\n") |
|
190 self.write_warning("exited with status %d (pid %d)\n"%(ecode,pid)) |
|
191 |
|
192 def spin(p): |
|
193 while not p.finished: |
|
194 wx.Yield() |
|
195 time.sleep(0.01) |
|
196 |
|
197 input = [] |
|
198 p = wxPopen3(Command, input, output, errors, fin, self.output) |
|
199 if p.pid: |
|
200 spin(p) |
|
201 |
|
202 return (self.exitcode, self.outdata, self.errdata) |
|
203 |
150 |
204 [ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
151 [ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
205 ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, |
152 ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, |
206 ] = [wx.NewId() for _init_ctrls in range(4)] |
153 ] = [wx.NewId() for _init_ctrls in range(4)] |
207 |
154 |
867 self.PopupMenuXY(main_menu) |
814 self.PopupMenuXY(main_menu) |
868 event.Skip() |
815 event.Skip() |
869 return AddPluginMenu |
816 return AddPluginMenu |
870 |
817 |
871 def GetButtonCallBackFunction(self, plugin, method): |
818 def GetButtonCallBackFunction(self, plugin, method): |
|
819 """ Generate the callbackfunc for a given plugin method""" |
872 def OnButtonClick(event): |
820 def OnButtonClick(event): |
|
821 # Disable button to prevent re-entrant call |
|
822 event.GetEventObject().Disable() |
|
823 # Call |
873 getattr(plugin,method)(self.Log) |
824 getattr(plugin,method)(self.Log) |
874 #self.RefreshVariableLists() |
825 # Re-enable button |
|
826 event.GetEventObject().Enable() |
|
827 # Trigger refresh on Idle |
875 wx.CallAfter(self.RefreshAll) |
828 wx.CallAfter(self.RefreshAll) |
876 event.Skip() |
829 event.Skip() |
877 return OnButtonClick |
830 return OnButtonClick |
878 |
831 |
879 def GetChoiceCallBackFunction(self, choicectrl, plugin, path): |
832 def GetChoiceCallBackFunction(self, choicectrl, plugin, path): |