332 # Python based WebSocket HMITree Server |
332 # Python based WebSocket HMITree Server |
333 svghmiserverfile = open(paths.AbsNeighbourFile(__file__, "svghmi_server.py"), 'r') |
333 svghmiserverfile = open(paths.AbsNeighbourFile(__file__, "svghmi_server.py"), 'r') |
334 svghmiservercode = svghmiserverfile.read() |
334 svghmiservercode = svghmiserverfile.read() |
335 svghmiserverfile.close() |
335 svghmiserverfile.close() |
336 |
336 |
337 runtimefile_path = os.path.join(buildpath, "runtime_svghmi.py") |
337 runtimefile_path = os.path.join(buildpath, "runtime_00_svghmi.py") |
338 runtimefile = open(runtimefile_path, 'w') |
338 runtimefile = open(runtimefile_path, 'w') |
339 runtimefile.write(svghmiservercode) |
339 runtimefile.write(svghmiservercode) |
340 runtimefile.close() |
340 runtimefile.close() |
341 |
341 |
342 return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
342 return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
343 ("runtime_svghmi0.py", open(runtimefile_path, "rb"))) |
343 ("runtime_00_svghmi.py", open(runtimefile_path, "rb"))) |
|
344 # ^ |
|
345 # note the double zero after "runtime_", |
|
346 # to ensure placement before other CTN generated code in execution order |
344 |
347 |
345 |
348 |
346 class HMITreeSelector(wx.TreeCtrl): |
349 class HMITreeSelector(wx.TreeCtrl): |
347 def __init__(self, parent): |
350 def __init__(self, parent): |
348 global on_hmitree_update |
351 global on_hmitree_update |
564 svghmi_cmds[thing] = ( |
567 svghmi_cmds[thing] = ( |
565 "Popen(" + |
568 "Popen(" + |
566 repr(shlex.split(given_command.format(port="8008", name=view_name))) + |
569 repr(shlex.split(given_command.format(port="8008", name=view_name))) + |
567 ")") if given_command else "pass # no command given" |
570 ")") if given_command else "pass # no command given" |
568 |
571 |
569 runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str) |
572 runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str) |
570 runtimefile = open(runtimefile_path, 'w') |
573 runtimefile = open(runtimefile_path, 'w') |
571 runtimefile.write(""" |
574 runtimefile.write(""" |
572 # TODO : multiple watchdog (one for each svghmi instance) |
575 # TODO : multiple watchdog (one for each svghmi instance) |
573 def svghmi_watchdog_trigger(): |
576 def svghmi_watchdog_trigger(): |
574 {svghmi_cmds[Watchdog]} |
577 {svghmi_cmds[Watchdog]} |
575 |
578 |
576 svghmi_watchdog = None |
579 svghmi_watchdog = None |
577 |
580 |
578 def _runtime_svghmi1_{location}_start(): |
581 def _runtime_{location}_svghmi_start(): |
579 global svghmi_watchdog |
582 global svghmi_watchdog |
580 svghmi_root.putChild( |
583 svghmi_root.putChild( |
581 '{view_name}', |
584 '{view_name}', |
582 NoCacheFile('{xhtml}', |
585 NoCacheFile('{xhtml}', |
583 defaultType='application/xhtml+xml')) |
586 defaultType='application/xhtml+xml')) |
587 svghmi_watchdog = Watchdog( |
590 svghmi_watchdog = Watchdog( |
588 {watchdog_initial}, |
591 {watchdog_initial}, |
589 {watchdog_interval}, |
592 {watchdog_interval}, |
590 svghmi_watchdog_trigger) |
593 svghmi_watchdog_trigger) |
591 |
594 |
592 def _runtime_svghmi1_{location}_stop(): |
595 def _runtime_{location}_svghmi_stop(): |
593 global svghmi_watchdog |
596 global svghmi_watchdog |
594 if svghmi_watchdog is not None: |
597 if svghmi_watchdog is not None: |
595 svghmi_watchdog.cancel() |
598 svghmi_watchdog.cancel() |
596 svghmi_watchdog = None |
599 svghmi_watchdog = None |
597 |
600 |
606 watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"], |
609 watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"], |
607 )) |
610 )) |
608 |
611 |
609 runtimefile.close() |
612 runtimefile.close() |
610 |
613 |
611 res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),) |
614 res += (("runtime_%s_svghmi.py" % location_str, open(runtimefile_path, "rb")),) |
612 |
615 |
613 return res |
616 return res |
614 |
617 |
615 def _ImportSVG(self): |
618 def _ImportSVG(self): |
616 dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) |
619 dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) |