421 warnings.simplefilter("ignore") |
421 warnings.simplefilter("ignore") |
422 try: |
422 try: |
423 if havewx: |
423 if havewx: |
424 from twisted.internet import wxreactor |
424 from twisted.internet import wxreactor |
425 wxreactor.install() |
425 wxreactor.install() |
426 from twisted.internet import reactor |
426 from twisted.internet import reactor |
|
427 reactor.registerWxApp(app) |
|
428 else: |
|
429 # from twisted.internet import pollreactor |
|
430 # pollreactor.install() |
|
431 from twisted.internet import reactor |
427 |
432 |
428 havetwisted = True |
433 havetwisted = True |
429 except ImportError: |
434 except ImportError: |
430 print(_("Twisted unavailable.")) |
435 print(_("Twisted unavailable.")) |
431 havetwisted = False |
436 havetwisted = False |
432 |
437 |
433 pyruntimevars = {} |
438 pyruntimevars = {} |
434 |
|
435 if havetwisted: |
|
436 if havewx: |
|
437 reactor.registerWxApp(app) |
|
438 |
|
439 |
439 |
440 if havewx: |
440 if havewx: |
441 wx_eval_lock = Semaphore(0) |
441 wx_eval_lock = Semaphore(0) |
442 |
442 |
443 def statuschangeTskBar(status): |
443 def statuschangeTskBar(status): |
576 sys.stdout.write(_("Current working directory :") + WorkingDir + "\n") |
576 sys.stdout.write(_("Current working directory :") + WorkingDir + "\n") |
577 sys.stdout.flush() |
577 sys.stdout.flush() |
578 |
578 |
579 runtime.GetPLCObjectSingleton().AutoLoad(autostart) |
579 runtime.GetPLCObjectSingleton().AutoLoad(autostart) |
580 |
580 |
581 if havetwisted or havewx: |
581 if havetwisted and havewx: |
582 |
582 |
583 waker_func = wx.CallAfter if havewx else partial(reactor.callLater,0) |
583 waker_func = wx.CallAfter |
584 |
584 |
585 # This orders ui loop to signal when ready on Stdout |
585 # This orders ui loop to signal when ready on Stdout |
586 waker_func(print,"UI thread started successfully.") |
586 waker_func(print,"UI thread started successfully.") |
587 |
587 |
588 # worker that copes with wx and (wx)reactor |
588 # interleaved worker copes with wxreactor by delegating all asynchronous |
|
589 # calls to wx's mainloop |
589 runtime.MainWorker.interleave(waker_func, FirstWorkerJob) |
590 runtime.MainWorker.interleave(waker_func, FirstWorkerJob) |
590 |
591 |
591 try: |
592 try: |
592 if havetwisted: |
593 reactor.run(installSignalHandlers=False) |
593 reactor.run(installSignalHandlers=False) |
|
594 else: |
|
595 app.MainLoop |
|
596 except KeyboardInterrupt: |
594 except KeyboardInterrupt: |
597 pass |
595 pass |
598 |
596 |
599 runtime.MainWorker.stop() |
597 runtime.MainWorker.stop() |
600 |
598 |
|
599 elif havewx: |
|
600 |
|
601 try: |
|
602 app.MainLoop |
|
603 except KeyboardInterrupt: |
|
604 pass |
|
605 |
|
606 elif havetwisted: |
|
607 |
|
608 ui_thread_started = Lock() |
|
609 ui_thread_started.acquire() |
|
610 |
|
611 reactor.callLater(0, ui_thread_started.release) |
|
612 |
|
613 ui_thread = Thread( |
|
614 target=partial(reactor.run, installSignalHandlers=False), |
|
615 name="UIThread") |
|
616 ui_thread.start() |
|
617 |
|
618 ui_thread_started.acquire() |
|
619 print("UI thread started successfully.") |
|
620 try: |
|
621 # blocking worker loop |
|
622 runtime.MainWorker.runloop(FirstWorkerJob) |
|
623 except KeyboardInterrupt: |
|
624 pass |
601 else: |
625 else: |
602 try: |
626 try: |
603 # blocking worker loop |
627 # blocking worker loop |
604 runtime.MainWorker.runloop(FirstWorkerJob) |
628 runtime.MainWorker.runloop(FirstWorkerJob) |
605 except KeyboardInterrupt: |
629 except KeyboardInterrupt: |