21 #You should have received a copy of the GNU General Public |
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 |
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 |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import os, sys, getopt |
25 import os, sys, getopt |
|
26 from threading import Thread |
26 |
27 |
27 def usage(): |
28 def usage(): |
28 print """ |
29 print """ |
29 Usage of Beremiz PLC execution service :\n |
30 Usage of Beremiz PLC execution service :\n |
30 %s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
31 %s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
289 TBMENU_LIVE_SHELL = wx.NewId() |
290 TBMENU_LIVE_SHELL = wx.NewId() |
290 TBMENU_WXINSPECTOR = wx.NewId() |
291 TBMENU_WXINSPECTOR = wx.NewId() |
291 TBMENU_CHANGE_WD = wx.NewId() |
292 TBMENU_CHANGE_WD = wx.NewId() |
292 TBMENU_QUIT = wx.NewId() |
293 TBMENU_QUIT = wx.NewId() |
293 |
294 |
294 def __init__(self, pyroserver): |
295 def __init__(self, pyroserver, level): |
295 wx.TaskBarIcon.__init__(self) |
296 wx.TaskBarIcon.__init__(self) |
296 self.pyroserver = pyroserver |
297 self.pyroserver = pyroserver |
297 # Set the image |
298 # Set the image |
298 self.UpdateIcon(None) |
299 self.UpdateIcon(None) |
|
300 self.level = level |
299 |
301 |
300 # bind some events |
302 # bind some events |
301 self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
303 self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
302 self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
304 self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
303 self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
305 self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
316 the base class takes care of the rest. |
318 the base class takes care of the rest. |
317 """ |
319 """ |
318 menu = wx.Menu() |
320 menu = wx.Menu() |
319 menu.Append(self.TBMENU_START, _("Start PLC")) |
321 menu.Append(self.TBMENU_START, _("Start PLC")) |
320 menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
322 menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
321 menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
323 if self.level==1: |
322 menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
324 menu.AppendSeparator() |
323 menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
325 menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
324 menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
326 menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
325 menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
327 menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
|
328 menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
|
329 menu.AppendSeparator() |
|
330 menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
|
331 menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
326 menu.AppendSeparator() |
332 menu.AppendSeparator() |
327 menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
|
328 menu.Append(self.TBMENU_QUIT, _("Quit")) |
333 menu.Append(self.TBMENU_QUIT, _("Quit")) |
329 return menu |
334 return menu |
330 |
335 |
331 def MakeIcon(self, img): |
336 def MakeIcon(self, img): |
332 """ |
337 """ |
346 self.pyroserver.plcobj.StartPLC() |
351 self.pyroserver.plcobj.StartPLC() |
347 evt.Skip() |
352 evt.Skip() |
348 |
353 |
349 def OnTaskBarStopPLC(self, evt): |
354 def OnTaskBarStopPLC(self, evt): |
350 if self.pyroserver.plcobj is not None: |
355 if self.pyroserver.plcobj is not None: |
351 self.pyroserver.plcobj.StopPLC() |
356 Thread(target=self.pyroserver.plcobj.StopPLC).start() |
352 evt.Skip() |
357 evt.Skip() |
353 |
358 |
354 def OnTaskBarChangeInterface(self, evt): |
359 def OnTaskBarChangeInterface(self, evt): |
355 dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=self.pyroserver.ip_addr) |
360 dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=self.pyroserver.ip_addr) |
356 dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), |
361 dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), |
675 |
680 |
676 if havewx: |
681 if havewx: |
677 from threading import Semaphore |
682 from threading import Semaphore |
678 wx_eval_lock = Semaphore(0) |
683 wx_eval_lock = Semaphore(0) |
679 mythread = currentThread() |
684 mythread = currentThread() |
680 |
685 |
681 def statuschange(status): |
686 def statuschange(status): |
682 wx.CallAfter(taskbar_instance.UpdateIcon,status) |
687 wx.CallAfter(taskbar_instance.UpdateIcon,status) |
683 |
688 |
684 eval_res = None |
689 eval_res = None |
685 def wx_evaluator(callable, *args, **kwargs): |
690 def wx_evaluator(callable, *args, **kwargs): |
699 wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
704 wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
700 wx_eval_lock.acquire() |
705 wx_eval_lock.acquire() |
701 return eval_res |
706 return eval_res |
702 |
707 |
703 pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, statuschange, evaluator, website) |
708 pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, statuschange, evaluator, website) |
704 taskbar_instance = BeremizTaskBarIcon(pyroserver) |
709 taskbar_instance = BeremizTaskBarIcon(pyroserver, enablewx) |
705 else: |
710 else: |
706 pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, website=website) |
711 pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, website=website) |
707 |
712 |
708 if havetwisted or havewx: |
713 if havetwisted or havewx: |
709 pyro_thread=Thread(target=pyroserver.Loop) |
714 pyro_thread=Thread(target=pyroserver.Loop) |