414 |
414 |
415 def __init__(self, parent, projectOpen, buildpath): |
415 def __init__(self, parent, projectOpen, buildpath): |
416 self._init_ctrls(parent) |
416 self._init_ctrls(parent) |
417 |
417 |
418 self.Log = LogPseudoFile(self.LogConsole) |
418 self.Log = LogPseudoFile(self.LogConsole) |
419 |
419 |
420 # create temporary directory for runtime working directory |
420 self.local_runtime = None |
421 self.local_runtime_tmpdir = tempfile.mkdtemp() |
421 self.runtime_port = None |
422 # choose an arbitrary random port for runtime |
422 self.local_runtime_tmpdir = None |
423 self.runtime_port = int(random.random() * 1000) + 61131 |
|
424 # launch local runtime |
|
425 self.local_runtime = ProcessLogger(self.Log, |
|
426 "\"%s\" \"%s\" -p %s -i localhost -x 0 %s"%(sys.executable, |
|
427 Bpath("Beremiz_service.py"), |
|
428 self.runtime_port, |
|
429 self.local_runtime_tmpdir), |
|
430 no_gui=False) |
|
431 |
423 |
432 # Add beremiz's icon in top left corner of the frame |
424 # Add beremiz's icon in top left corner of the frame |
433 self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) |
425 self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) |
434 |
426 |
435 self.DisableEvents = False |
427 self.DisableEvents = False |
436 |
428 |
437 self.PluginInfos = {} |
429 self.PluginInfos = {} |
438 |
430 |
439 if projectOpen: |
431 if projectOpen: |
440 self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port) |
432 self.PluginRoot = PluginsRoot(self, self.Log) |
441 self.PluginRoot.LoadProject(projectOpen, buildpath) |
433 self.PluginRoot.LoadProject(projectOpen, buildpath) |
442 self.RefreshAll() |
434 self.RefreshAll() |
443 else: |
435 else: |
444 self.PluginRoot = None |
436 self.PluginRoot = None |
445 |
437 |
446 self.RefreshMainMenu() |
438 self.RefreshMainMenu() |
|
439 |
|
440 def StartLocalRuntime(self, taskbaricon = True): |
|
441 if self.local_runtime is None or self.local_runtime.finished: |
|
442 # create temporary directory for runtime working directory |
|
443 self.local_runtime_tmpdir = tempfile.mkdtemp() |
|
444 # choose an arbitrary random port for runtime |
|
445 self.runtime_port = int(random.random() * 1000) + 61131 |
|
446 # launch local runtime |
|
447 self.local_runtime = ProcessLogger(self.Log, |
|
448 "\"%s\" \"%s\" -p %s -i localhost %s %s"%(sys.executable, |
|
449 Bpath("Beremiz_service.py"), |
|
450 self.runtime_port, |
|
451 {False : "-x 0", True :"-x 1"}[taskbaricon], |
|
452 self.local_runtime_tmpdir), |
|
453 no_gui=False) |
|
454 self.local_runtime.spin(timeout=500, keyword = "working", kill_it = False) |
|
455 return self.runtime_port |
|
456 |
|
457 def KillLocalRuntime(self): |
|
458 if self.local_runtime is not None: |
|
459 # shutdown local runtime |
|
460 self.local_runtime.kill(gently=False) |
|
461 # clear temp dir |
|
462 shutil.rmtree(self.local_runtime_tmpdir) |
447 |
463 |
448 def OnOpenWidgetInspector(self, evt): |
464 def OnOpenWidgetInspector(self, evt): |
449 # Activate the widget inspection tool |
465 # Activate the widget inspection tool |
450 from wx.lib.inspection import InspectionTool |
466 from wx.lib.inspection import InspectionTool |
451 if not InspectionTool().initialized: |
467 if not InspectionTool().initialized: |