svghmi/svghmi.py
changeset 3507 e87a2daace80
parent 3499 72ee59ff959c
child 3526 074046800624
child 3647 7c427418396f
equal deleted inserted replaced
3506:ca312be56929 3507:e87a2daace80
   280 
   280 
   281 class SVGHMIEditor(ConfTreeNodeEditor):
   281 class SVGHMIEditor(ConfTreeNodeEditor):
   282     CONFNODEEDITOR_TABS = [
   282     CONFNODEEDITOR_TABS = [
   283         (_("HMI Tree"), "CreateSVGHMI_UI")]
   283         (_("HMI Tree"), "CreateSVGHMI_UI")]
   284 
   284 
       
   285     def __init__(self, parent, controler, window):
       
   286         ConfTreeNodeEditor.__init__(self, parent, controler, window)
       
   287         self.Controler = controler
       
   288 
   285     def CreateSVGHMI_UI(self, parent):
   289     def CreateSVGHMI_UI(self, parent):
   286         global hmi_tree_root
   290         global hmi_tree_root
   287 
   291 
   288         if hmi_tree_root is None:
   292         if hmi_tree_root is None:
   289             buildpath = self.Controler.GetCTRoot()._getBuildPath()
   293             buildpath = self.Controler.GetCTRoot()._getBuildPath()
   290             hmitree_backup_path = os.path.join(buildpath, "hmitree.xml")
   294             hmitree_backup_path = os.path.join(buildpath, "hmitree.xml")
   291             if os.path.exists(hmitree_backup_path):
   295             if os.path.exists(hmitree_backup_path):
   292                 hmitree_backup_file = open(hmitree_backup_path, 'rb')
   296                 hmitree_backup_file = open(hmitree_backup_path, 'rb')
   293                 hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot())
   297                 hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot())
   294 
   298 
   295         ret = SVGHMI_UI(parent, Register_SVGHMI_UI_for_HMI_tree_updates)
   299         ret = SVGHMI_UI(parent, self.Controler, Register_SVGHMI_UI_for_HMI_tree_updates)
   296 
   300 
   297         on_hmitree_update(hmi_tree_root)
   301         on_hmitree_update(hmi_tree_root)
   298 
   302 
   299         return ret
   303         return ret
   300 
   304 
   301 if wx.Platform == '__WXMSW__':
   305 if wx.Platform == '__WXMSW__':
   302     browser_launch_cmd="cmd.exe /c 'start msedge {url}'"
   306     default_cmds={
       
   307         "launch":"cmd.exe /c 'start msedge {url}'",
       
   308         "watchdog":"cmd.exe /k 'echo watchdog for {url} !'"}
   303 else:
   309 else:
   304     browser_launch_cmd="chromium {url}"
   310     default_cmds={
       
   311         "launch":"chromium {url}",
       
   312         "watchdog":"echo Watchdog for {name} !"}
   305 
   313 
   306 class SVGHMI(object):
   314 class SVGHMI(object):
   307     XSD = """<?xml version="1.0" encoding="utf-8" ?>
   315     XSD = """<?xml version="1.0" encoding="utf-8" ?>
   308     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   316     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   309       <xsd:element name="SVGHMI">
   317       <xsd:element name="SVGHMI">
   310         <xsd:complexType>
   318         <xsd:complexType>
   311           <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%s"/>
   319           <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%(launch)s"/>
   312           <xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/>
   320           <xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/>
   313           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default=""/>
   321           <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="%(watchdog)s"/>
   314           <xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/>
   322           <xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/>
   315           <xsd:attribute name="WatchdogInitial" use="optional" default="30">
   323           <xsd:attribute name="WatchdogInitial" use="optional" default="30">
   316             <xsd:simpleType>
   324             <xsd:simpleType>
   317                 <xsd:restriction base="xsd:integer">
   325                 <xsd:restriction base="xsd:integer">
   318                     <xsd:minInclusive value="2"/>
   326                     <xsd:minInclusive value="2"/>
   340             </xsd:simpleType>
   348             </xsd:simpleType>
   341           </xsd:attribute>
   349           </xsd:attribute>
   342         </xsd:complexType>
   350         </xsd:complexType>
   343       </xsd:element>
   351       </xsd:element>
   344     </xsd:schema>
   352     </xsd:schema>
   345     """%browser_launch_cmd
   353     """%default_cmds
   346 
   354 
   347     EditorType = SVGHMIEditor
   355     EditorType = SVGHMIEditor
   348 
   356 
   349     ConfNodeMethods = [
   357     ConfNodeMethods = [
   350         {
   358         {
   397 
   405 
   398     def OnCTNSave(self, from_project_path=None):
   406     def OnCTNSave(self, from_project_path=None):
   399         if from_project_path is not None:
   407         if from_project_path is not None:
   400             shutil.copyfile(self._getSVGpath(from_project_path),
   408             shutil.copyfile(self._getSVGpath(from_project_path),
   401                             self._getSVGpath())
   409                             self._getSVGpath())
   402             shutil.copyfile(self._getPOTpath(from_project_path),
   410 
   403                             self._getPOTpath())
   411             potpath = self._getPOTpath(from_project_path)
   404             # XXX TODO copy .PO files
   412             if os.path.isfile(potpath):
       
   413                 shutil.copyfile(potpath, self._getPOTpath())
       
   414                 # copy .PO files
       
   415                 for _name, pofile in GetPoFiles(from_project_path):
       
   416                     shutil.copy(pofile, self.CTNPath())
   405         return True
   417         return True
   406 
   418 
   407     def GetSVGGeometry(self):
   419     def GetSVGGeometry(self):
   408         self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)")
   420         self.ProgressStart("inkscape", "collecting SVG geometry (Inkscape)")
   409         # invoke inskscape -S, csv-parse output, produce elements
   421         # invoke inskscape -S, csv-parse output, produce elements