equal
deleted
inserted
replaced
65 enablewx = True |
65 enablewx = True |
66 havewx = False |
66 havewx = False |
67 enabletwisted = True |
67 enabletwisted = True |
68 havetwisted = False |
68 havetwisted = False |
69 |
69 |
70 extensions=[] |
70 extensions = [] |
71 |
71 |
72 for o, a in opts: |
72 for o, a in opts: |
73 if o == "-h": |
73 if o == "-h": |
74 usage() |
74 usage() |
75 sys.exit() |
75 sys.exit() |
109 elif len(argv) == 1: |
109 elif len(argv) == 1: |
110 WorkingDir = argv[0] |
110 WorkingDir = argv[0] |
111 os.chdir(WorkingDir) |
111 os.chdir(WorkingDir) |
112 elif len(argv) == 0: |
112 elif len(argv) == 0: |
113 WorkingDir = os.getcwd() |
113 WorkingDir = os.getcwd() |
114 argv=[WorkingDir] |
114 argv = [WorkingDir] |
115 |
115 |
116 import __builtin__ |
116 import __builtin__ |
117 if __name__ == '__main__': |
117 if __name__ == '__main__': |
118 __builtin__.__dict__['_'] = lambda x: x |
118 __builtin__.__dict__['_'] = lambda x: x |
119 |
119 |
262 the base class takes care of the rest. |
262 the base class takes care of the rest. |
263 """ |
263 """ |
264 menu = wx.Menu() |
264 menu = wx.Menu() |
265 menu.Append(self.TBMENU_START, _("Start PLC")) |
265 menu.Append(self.TBMENU_START, _("Start PLC")) |
266 menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
266 menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
267 if self.level==1: |
267 if self.level == 1: |
268 menu.AppendSeparator() |
268 menu.AppendSeparator() |
269 menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
269 menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
270 menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
270 menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
271 menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
271 menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
272 menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
272 menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
380 os.mkdir(WorkingDir) |
380 os.mkdir(WorkingDir) |
381 |
381 |
382 |
382 |
383 def default_evaluator(tocall, *args, **kwargs): |
383 def default_evaluator(tocall, *args, **kwargs): |
384 try: |
384 try: |
385 res=(tocall(*args, **kwargs), None) |
385 res = (tocall(*args, **kwargs), None) |
386 except Exception: |
386 except Exception: |
387 res=(None, sys.exc_info()) |
387 res = (None, sys.exc_info()) |
388 return res |
388 return res |
389 |
389 |
390 |
390 |
391 class Server(): |
391 class Server(): |
392 def __init__(self, servicename, ip_addr, port, |
392 def __init__(self, servicename, ip_addr, port, |
421 self.plcobj.UnLoadPLC() |
421 self.plcobj.UnLoadPLC() |
422 self.Stop() |
422 self.Stop() |
423 |
423 |
424 def Start(self): |
424 def Start(self): |
425 pyro.initServer() |
425 pyro.initServer() |
426 self.daemon=pyro.Daemon(host=self.ip_addr, port=self.port) |
426 self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port) |
427 self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
427 self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
428 self.statuschange, self.evaluator, |
428 self.statuschange, self.evaluator, |
429 self.pyruntimevars) |
429 self.pyruntimevars) |
430 uri = self.daemon.connect(self.plcobj, "PLCObject") |
430 uri = self.daemon.connect(self.plcobj, "PLCObject") |
431 |
431 |
509 global main_thread |
509 global main_thread |
510 if(main_thread == currentThread()): |
510 if(main_thread == currentThread()): |
511 # avoid dead lock if called from the wx mainloop |
511 # avoid dead lock if called from the wx mainloop |
512 return default_evaluator(tocall, *args, **kwargs) |
512 return default_evaluator(tocall, *args, **kwargs) |
513 else: |
513 else: |
514 o=type('', (object,), dict(call=(tocall, args, kwargs), res=None)) |
514 o = type('', (object,), dict(call=(tocall, args, kwargs), res=None)) |
515 wx.CallAfter(wx_evaluator, o) |
515 wx.CallAfter(wx_evaluator, o) |
516 wx_eval_lock.acquire() |
516 wx_eval_lock.acquire() |
517 return o.res |
517 return o.res |
518 |
518 |
519 pyroserver = Server(servicename, given_ip, port, |
519 pyroserver = Server(servicename, given_ip, port, |
596 except Exception, e: |
596 except Exception, e: |
597 print _("WAMP client startup failed. "), e |
597 print _("WAMP client startup failed. "), e |
598 |
598 |
599 |
599 |
600 if havetwisted or havewx: |
600 if havetwisted or havewx: |
601 pyro_thread=Thread(target=pyroserver.Loop) |
601 pyro_thread = Thread(target=pyroserver.Loop) |
602 pyro_thread.start() |
602 pyro_thread.start() |
603 |
603 |
604 if havetwisted: |
604 if havetwisted: |
605 reactor.run() |
605 reactor.run() |
606 elif havewx: |
606 elif havewx: |