svghmi/svghmi.py
branchsvghmi
changeset 2823 d631f8671c75
parent 2822 9101a72a1da0
child 2824 074f43e6e114
equal deleted inserted replaced
2822:9101a72a1da0 2823:d631f8671c75
    11 import shutil
    11 import shutil
    12 from itertools import izip, imap
    12 from itertools import izip, imap
    13 from pprint import pformat
    13 from pprint import pformat
    14 import hashlib
    14 import hashlib
    15 import weakref
    15 import weakref
       
    16 import shlex
    16 
    17 
    17 import wx
    18 import wx
    18 import wx.dataview as dv
    19 import wx.dataview as dv
    19 
    20 
    20 from lxml import etree
    21 from lxml import etree
   373 class SVGHMI(object):
   374 class SVGHMI(object):
   374     XSD = """<?xml version="1.0" encoding="utf-8" ?>
   375     XSD = """<?xml version="1.0" encoding="utf-8" ?>
   375     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   376     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   376       <xsd:element name="SVGHMI">
   377       <xsd:element name="SVGHMI">
   377         <xsd:complexType>
   378         <xsd:complexType>
   378           <xsd:attribute name="enableHTTP" type="xsd:boolean" use="optional" default="false"/>
   379           <xsd:attribute name="OnStart" type="xsd:string" use="optional"/>
   379           <xsd:attribute name="bindAddress" type="xsd:string" use="optional" default="localhost"/>
   380           <xsd:attribute name="OnStop" type="xsd:string" use="optional"/>
       
   381           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional"/>
   380           <xsd:attribute name="port" type="xsd:string" use="optional" default="8080"/>
   382           <xsd:attribute name="port" type="xsd:string" use="optional" default="8080"/>
   381         </xsd:complexType>
   383         </xsd:complexType>
   382       </xsd:element>
   384       </xsd:element>
   383     </xsd:schema>
   385     </xsd:schema>
   384     """
   386     """
   501 """)
   503 """)
   502 
   504 
   503         target_file.close()
   505         target_file.close()
   504 
   506 
   505         res += ((target_fname, open(target_path, "rb")),)
   507         res += ((target_fname, open(target_path, "rb")),)
       
   508         
       
   509         svghmi_cmds = {}
       
   510         for thing in ["Start", "Stop", "Watchdog"]:
       
   511              given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
       
   512              if given_command:
       
   513                  svghmi_cmds[thing] = shlex.split(given_command)
   506 
   514 
   507         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   515         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
   508         runtimefile = open(runtimefile_path, 'w')
   516         runtimefile = open(runtimefile_path, 'w')
   509         runtimefile.write("""
   517         runtimefile.write("""
       
   518 # 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():
       
   525     svghmi_cmd("Watchdog")
       
   526 
   510 def _runtime_svghmi1_%(location)s_start():
   527 def _runtime_svghmi1_%(location)s_start():
   511     svghmi_root.putChild('%(view_name)s',File('%(xhtml)s', defaultType='application/xhtml+xml'))
   528     svghmi_root.putChild('%(view_name)s',File('%(xhtml)s', defaultType='application/xhtml+xml'))
       
   529     svghmi_cmd("Start")
   512 
   530 
   513 def _runtime_svghmi1_%(location)s_stop():
   531 def _runtime_svghmi1_%(location)s_stop():
   514     svghmi_root.delEntity('%(view_name)s')
   532     svghmi_root.delEntity('%(view_name)s')
       
   533     svghmi_cmd("Stop")
   515 
   534 
   516         """ % {"location": location_str,
   535         """ % {"location": location_str,
   517                "xhtml": target_fname,
   536                "xhtml": target_fname,
   518                "view_name": view_name})
   537                "view_name": view_name,
       
   538                "svghmi_cmds": repr(svghmi_cmds)})
   519 
   539 
   520         runtimefile.close()
   540         runtimefile.close()
   521 
   541 
   522         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   542         res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
   523 
   543