svghmi/svghmi.py
changeset 4071 d0be57df5f8d
parent 3952 9719e0eeb6ff
child 4075 69114ac20de8
equal deleted inserted replaced
4069:e4f648e0595a 4071:d0be57df5f8d
   324       <xsd:element name="SVGHMI">
   324       <xsd:element name="SVGHMI">
   325         <xsd:complexType>
   325         <xsd:complexType>
   326           <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%(launch)s"/>
   326           <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%(launch)s"/>
   327           <xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/>
   327           <xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/>
   328           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="%(watchdog)s"/>
   328           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="%(watchdog)s"/>
       
   329           <xsd:attribute name="SuppressBrowserOutput" type="xsd:boolean" use="optional" default="true"/>
   329           <xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/>
   330           <xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/>
   330           <xsd:attribute name="WatchdogInitial" use="optional" default="30">
   331           <xsd:attribute name="WatchdogInitial" use="optional" default="30">
   331             <xsd:simpleType>
   332             <xsd:simpleType>
   332                 <xsd:restriction base="xsd:integer">
   333                 <xsd:restriction base="xsd:integer">
   333                     <xsd:minInclusive value="2"/>
   334                     <xsd:minInclusive value="2"/>
   639             svghmi_options["enable_watchdog"] = False
   640             svghmi_options["enable_watchdog"] = False
   640 
   641 
   641         res += ((target_fname, open(target_path, "rb")),)
   642         res += ((target_fname, open(target_path, "rb")),)
   642 
   643 
   643         svghmi_cmds = {}
   644         svghmi_cmds = {}
       
   645         suppress_output = not(self.GetParamsAttributes("SVGHMI.SuppressBrowserOutput")["value"])
       
   646         stdstream = "subprocess.DEVNULL" if suppress_output else "None"
   644         for thing in ["Start", "Stop", "Watchdog"]:
   647         for thing in ["Start", "Stop", "Watchdog"]:
   645              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   648              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   646              args = shlex.split(given_command.format(**svghmi_options))
   649              args = shlex.split(given_command.format(**svghmi_options))
   647              svghmi_cmds[thing] = (
   650              svghmi_cmds[thing] = f"Popen({repr(args)}, stdout={stdstream},stderr={stdstream})" \
   648                 "Popen(" +
   651                                   if args else "None # no command given"
   649                 repr(args) +
       
   650                 ")") if args else "None # no command given"
       
   651 
   652 
   652         runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str)
   653         runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str)
   653         runtimefile = open(runtimefile_path, 'w')
   654         runtimefile = open(runtimefile_path, 'w')
   654         runtimefile.write("""
   655         runtimefile.write("""
   655 #!/usr/bin/env python
   656 #!/usr/bin/env python
   656 # -*- coding: utf-8 -*-
   657 # -*- coding: utf-8 -*-
   657 
   658 
   658 # generated by beremiz/svghmi/svghmi.py
   659 # generated by beremiz/svghmi/svghmi.py
       
   660 
       
   661 import subprocess
   659 
   662 
   660 browser_proc = None
   663 browser_proc = None
   661 
   664 
   662 def svghmi_{location}_watchdog_trigger():
   665 def svghmi_{location}_watchdog_trigger():
   663     global browser_proc
   666     global browser_proc