84 WorkingDir = argv[0] |
84 WorkingDir = argv[0] |
85 elif len(argv) == 0: |
85 elif len(argv) == 0: |
86 WorkingDir = os.getcwd() |
86 WorkingDir = os.getcwd() |
87 argv=[WorkingDir] |
87 argv=[WorkingDir] |
88 |
88 |
|
89 import __builtin__ |
|
90 if __name__ == '__main__': |
|
91 __builtin__.__dict__['_'] = lambda x: x |
|
92 |
89 if enablewx: |
93 if enablewx: |
90 try: |
94 try: |
91 import wx, re |
95 import wx, re |
92 from threading import Thread, currentThread |
96 from threading import Thread, currentThread |
93 from types import * |
97 from types import * |
94 havewx = True |
98 havewx = True |
95 except: |
99 except: |
96 havewx = False |
100 havewx = False |
97 |
101 |
98 if havewx: |
102 if havewx: |
|
103 app=wx.App(redirect=False) |
|
104 |
|
105 # Import module for internationalization |
|
106 import gettext |
|
107 |
|
108 CWD = os.path.split(os.path.realpath(__file__))[0] |
|
109 |
|
110 # Get folder containing translation files |
|
111 localedir = os.path.join(CWD,"locale") |
|
112 # Get the default language |
|
113 langid = wx.LANGUAGE_DEFAULT |
|
114 # Define translation domain (name of translation files) |
|
115 domain = "Beremiz" |
|
116 |
|
117 # Define locale for wx |
|
118 loc = __builtin__.__dict__.get('loc', None) |
|
119 if loc is None: |
|
120 loc = wx.Locale(langid) |
|
121 __builtin__.__dict__['loc'] = loc |
|
122 # Define location for searching translation files |
|
123 loc.AddCatalogLookupPathPrefix(localedir) |
|
124 # Define locale domain |
|
125 loc.AddCatalog(domain) |
|
126 |
|
127 def unicode_translation(message): |
|
128 return wx.GetTranslation(message).encode("utf-8") |
|
129 |
|
130 if __name__ == '__main__': |
|
131 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
132 |
99 try: |
133 try: |
100 from wx.lib.embeddedimage import PyEmbeddedImage |
134 from wx.lib.embeddedimage import PyEmbeddedImage |
101 except: |
135 except: |
102 import cStringIO |
136 import cStringIO |
103 import base64 |
137 import base64 |
224 def OnOK(self, event): |
258 def OnOK(self, event): |
225 value = self.GetValue() |
259 value = self.GetValue() |
226 texts = {"value" : value} |
260 texts = {"value" : value} |
227 for function, message in self.Tests: |
261 for function, message in self.Tests: |
228 if not function(value): |
262 if not function(value): |
229 message = wx.MessageDialog(self, message%texts, "Error", wx.OK|wx.ICON_ERROR) |
263 message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) |
230 message.ShowModal() |
264 message.ShowModal() |
231 message.Destroy() |
265 message.Destroy() |
232 return |
266 return |
233 self.EndModal(wx.ID_OK) |
267 self.EndModal(wx.ID_OK) |
234 event.Skip() |
268 event.Skip() |
273 the menu for the default EVT_RIGHT_DOWN event. Just create |
307 the menu for the default EVT_RIGHT_DOWN event. Just create |
274 the menu how you want it and return it from this function, |
308 the menu how you want it and return it from this function, |
275 the base class takes care of the rest. |
309 the base class takes care of the rest. |
276 """ |
310 """ |
277 menu = wx.Menu() |
311 menu = wx.Menu() |
278 menu.Append(self.TBMENU_START, "Start PLC") |
312 menu.Append(self.TBMENU_START, _("Start PLC")) |
279 menu.Append(self.TBMENU_STOP, "Stop PLC") |
313 menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
280 menu.Append(self.TBMENU_CHANGE_NAME, "Change Name") |
314 menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
281 menu.Append(self.TBMENU_CHANGE_INTERFACE, "Change IP of interface to bind") |
315 menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
282 menu.Append(self.TBMENU_LIVE_SHELL, "Launch a live Python shell") |
316 menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
283 menu.Append(self.TBMENU_WXINSPECTOR, "Launch WX GUI inspector") |
317 menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
284 menu.Append(self.TBMENU_CHANGE_PORT, "Change Port Number") |
318 menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
285 menu.AppendSeparator() |
319 menu.AppendSeparator() |
286 menu.Append(self.TBMENU_CHANGE_WD, "Change working directory") |
320 menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
287 menu.Append(self.TBMENU_QUIT, "Quit") |
321 menu.Append(self.TBMENU_QUIT, _("Quit")) |
288 return menu |
322 return menu |
289 |
323 |
290 def MakeIcon(self, img): |
324 def MakeIcon(self, img): |
291 """ |
325 """ |
292 The various platforms have different requirements for the |
326 The various platforms have different requirements for the |
309 if self.pyroserver.plcobj is not None: |
343 if self.pyroserver.plcobj is not None: |
310 self.pyroserver.plcobj.StopPLC() |
344 self.pyroserver.plcobj.StopPLC() |
311 evt.Skip() |
345 evt.Skip() |
312 |
346 |
313 def OnTaskBarChangeInterface(self, evt): |
347 def OnTaskBarChangeInterface(self, evt): |
314 dlg = ParamsEntryDialog(None, "Enter the ip of the interface to bind", defaultValue=self.pyroserver.ip) |
348 dlg = ParamsEntryDialog(None, _("Enter the ip of the interface to bind"), defaultValue=self.pyroserver.ip) |
315 dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, "Ip is not valid!"), |
349 dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("Ip is not valid!")), |
316 ( lambda ip :len([x for x in ip.split(".") if 0 <= int(x) <= 255]) == 4, "Ip is not valid!") |
350 ( lambda ip :len([x for x in ip.split(".") if 0 <= int(x) <= 255]) == 4, _("Ip is not valid!")) |
317 ]) |
351 ]) |
318 if dlg.ShowModal() == wx.ID_OK: |
352 if dlg.ShowModal() == wx.ID_OK: |
319 self.pyroserver.ip = dlg.GetValue() |
353 self.pyroserver.ip = dlg.GetValue() |
320 self.pyroserver.Stop() |
354 self.pyroserver.Stop() |
321 evt.Skip() |
355 evt.Skip() |
322 |
356 |
323 def OnTaskBarChangePort(self, evt): |
357 def OnTaskBarChangePort(self, evt): |
324 dlg = ParamsEntryDialog(None, "Enter a port number ", defaultValue=str(self.pyroserver.port)) |
358 dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
325 dlg.SetTests([(UnicodeType.isdigit, "Port number must be an integer!"), (lambda port : 0 <= int(port) <= 65535 , "Port number must be 0 <= port <= 65535!")]) |
359 dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) |
326 if dlg.ShowModal() == wx.ID_OK: |
360 if dlg.ShowModal() == wx.ID_OK: |
327 self.pyroserver.port = int(dlg.GetValue()) |
361 self.pyroserver.port = int(dlg.GetValue()) |
328 self.pyroserver.Stop() |
362 self.pyroserver.Stop() |
329 evt.Skip() |
363 evt.Skip() |
330 |
364 |
331 def OnTaskBarChangeWorkingDir(self, evt): |
365 def OnTaskBarChangeWorkingDir(self, evt): |
332 dlg = wx.DirDialog(None, "Choose a working directory ", self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
366 dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
333 if dlg.ShowModal() == wx.ID_OK: |
367 if dlg.ShowModal() == wx.ID_OK: |
334 self.pyroserver.workdir = dlg.GetPath() |
368 self.pyroserver.workdir = dlg.GetPath() |
335 self.pyroserver.Stop() |
369 self.pyroserver.Stop() |
336 evt.Skip() |
370 evt.Skip() |
337 |
371 |
338 def OnTaskBarChangeName(self, evt): |
372 def OnTaskBarChangeName(self, evt): |
339 dlg = ParamsEntryDialog(None, "Enter a name ", defaultValue=self.pyroserver.name) |
373 dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=self.pyroserver.name) |
340 dlg.SetTests([(lambda name : len(name) is not 0 , "Name must not be null!")]) |
374 dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) |
341 if dlg.ShowModal() == wx.ID_OK: |
375 if dlg.ShowModal() == wx.ID_OK: |
342 self.pyroserver.name = dlg.GetValue() |
376 self.pyroserver.name = dlg.GetValue() |
343 self.pyroserver.Restart() |
377 self.pyroserver.Restart() |
344 evt.Skip() |
378 evt.Skip() |
345 |
379 |