svghmi/svghmi.py
branchsvghmi
changeset 2824 074f43e6e114
parent 2823 d631f8671c75
child 2826 1e5abecc3cde
equal deleted inserted replaced
2823:d631f8671c75 2824:074f43e6e114
   377       <xsd:element name="SVGHMI">
   377       <xsd:element name="SVGHMI">
   378         <xsd:complexType>
   378         <xsd:complexType>
   379           <xsd:attribute name="OnStart" type="xsd:string" use="optional"/>
   379           <xsd:attribute name="OnStart" type="xsd:string" use="optional"/>
   380           <xsd:attribute name="OnStop" type="xsd:string" use="optional"/>
   380           <xsd:attribute name="OnStop" type="xsd:string" use="optional"/>
   381           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional"/>
   381           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional"/>
   382           <xsd:attribute name="port" type="xsd:string" use="optional" default="8080"/>
       
   383         </xsd:complexType>
   382         </xsd:complexType>
   384       </xsd:element>
   383       </xsd:element>
   385     </xsd:schema>
   384     </xsd:schema>
   386     """
   385     """
   387 
   386 
   507         res += ((target_fname, open(target_path, "rb")),)
   506         res += ((target_fname, open(target_path, "rb")),)
   508         
   507         
   509         svghmi_cmds = {}
   508         svghmi_cmds = {}
   510         for thing in ["Start", "Stop", "Watchdog"]:
   509         for thing in ["Start", "Stop", "Watchdog"]:
   511              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   510              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
   512              if given_command:
   511              svghmi_cmds[thing] = (
   513                  svghmi_cmds[thing] = shlex.split(given_command)
   512                 "Popen(" +
       
   513                 repr(shlex.split(given_command.format(port="8008", name=view_name))) + 
       
   514                 ")") if given_command else "# no command given"
   514 
   515 
   515         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   516         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   516         runtimefile = open(runtimefile_path, 'w')
   517         runtimefile = open(runtimefile_path, 'w')
   517         runtimefile.write("""
   518         runtimefile.write("""
   518 # TODO : multi        
   519 # TODO : multi        
   519 svghmi_cmds = %(svghmi_cmds)s
       
   520 def svghmi_cmd(cmd):
       
   521     if cmd in svghmi_cmds:
       
   522         Popen(svghmi_cmds[cmd])
       
   523 
       
   524 def watchdog_trigger():
   520 def watchdog_trigger():
   525     svghmi_cmd("Watchdog")
   521     {svghmi_cmds.Watchdog}
   526 
   522 
   527 def _runtime_svghmi1_%(location)s_start():
   523 def _runtime_svghmi1_{location}_start():
   528     svghmi_root.putChild('%(view_name)s',File('%(xhtml)s', defaultType='application/xhtml+xml'))
   524     svghmi_root.putChild('{view_name}',File('{xhtml}', defaultType='application/xhtml+xml'))
   529     svghmi_cmd("Start")
   525     {svghmi_cmds.Start}
   530 
   526 
   531 def _runtime_svghmi1_%(location)s_stop():
   527 def _runtime_svghmi1_{location}_stop():
   532     svghmi_root.delEntity('%(view_name)s')
   528     svghmi_root.delEntity('{view_name}')
   533     svghmi_cmd("Stop")
   529     {svghmi_cmds.Stop}
   534 
   530 
   535         """ % {"location": location_str,
   531         """.format(location=location_str,
   536                "xhtml": target_fname,
   532                    xhtml=target_fname,
   537                "view_name": view_name,
   533                    view_name=view_name,
   538                "svghmi_cmds": repr(svghmi_cmds)})
   534                    svghmi_cmds=type("dicobj",(object,),svghmi_cmds)))
   539 
   535 
   540         runtimefile.close()
   536         runtimefile.close()
   541 
   537 
   542         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   538         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   543 
   539