Various fixes to make svghmi_traffic_light example bahave on windows.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 25 May 2022 20:00:31 +0200
changeset 3481 563996733dba
parent 3480 078d72552c3e
child 3482 31f6d7221f60
Various fixes to make svghmi_traffic_light example bahave on windows.
exemples/svghmi_traffic_light/svghmi_0@svghmi/confnode.xml
svghmi/svghmi.py
util/misc.py
--- a/exemples/svghmi_traffic_light/svghmi_0@svghmi/confnode.xml	Wed May 25 09:18:37 2022 +0200
+++ b/exemples/svghmi_traffic_light/svghmi_0@svghmi/confnode.xml	Wed May 25 20:00:31 2022 +0200
@@ -1,2 +1,2 @@
 <?xml version='1.0' encoding='utf-8'?>
-<SVGHMI xmlns:xsd="http://www.w3.org/2001/XMLSchema" OnWatchdog="echo Watchdog for {name} !" WatchdogInitial="10" WatchdogInterval="5" EnableWatchdog="true" Path="{name}"/>
+<SVGHMI xmlns:xsd="http://www.w3.org/2001/XMLSchema" WatchdogInitial="10" WatchdogInterval="5" EnableWatchdog="true" Path="{name}"/>
--- a/svghmi/svghmi.py	Wed May 25 09:18:37 2022 +0200
+++ b/svghmi/svghmi.py	Wed May 25 20:00:31 2022 +0200
@@ -299,18 +299,22 @@
         return ret
 
 if wx.Platform == '__WXMSW__':
-    browser_launch_cmd="cmd.exe /c 'start msedge {url}'"
+    default_cmds={
+        "launch":"cmd.exe /c 'start msedge {url}'",
+        "watchdog":"cmd.exe /k 'echo watchdog for {url} !'"}
 else:
-    browser_launch_cmd="chromium {url}"
+    default_cmds={
+        "launch":"chromium {url}",
+        "watchdog":"echo Watchdog for {name} !"}
 
 class SVGHMI(object):
     XSD = """<?xml version="1.0" encoding="utf-8" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="SVGHMI">
         <xsd:complexType>
-          <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%s"/>
+          <xsd:attribute name="OnStart" type="xsd:string" use="optional" default="%(launch)s"/>
           <xsd:attribute name="OnStop" type="xsd:string" use="optional" default=""/>
-          <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default=""/>
+          <xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="%(watchdog)s"/>
           <xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="false"/>
           <xsd:attribute name="WatchdogInitial" use="optional" default="30">
             <xsd:simpleType>
@@ -342,7 +346,7 @@
         </xsd:complexType>
       </xsd:element>
     </xsd:schema>
-    """%browser_launch_cmd
+    """%default_cmds
 
     EditorType = SVGHMIEditor
 
@@ -399,9 +403,13 @@
         if from_project_path is not None:
             shutil.copyfile(self._getSVGpath(from_project_path),
                             self._getSVGpath())
-            shutil.copyfile(self._getPOTpath(from_project_path),
-                            self._getPOTpath())
-            # XXX TODO copy .PO files
+
+            potpath = self._getPOTpath(from_project_path)
+            if os.path.isfile(potpath):
+                shutil.copyfile(potpath, self._getPOTpath())
+                # copy .PO files
+                for _name, pofile in GetPoFiles(from_project_path):
+                    shutil.copy(pofile, self.CTNPath())
         return True
 
     def GetSVGGeometry(self):
--- a/util/misc.py	Wed May 25 09:18:37 2022 +0200
+++ b/util/misc.py	Wed May 25 20:00:31 2022 +0200
@@ -45,9 +45,9 @@
         dirs[:] = [d for d in dirs if not d[0] == '.']
         if sys.platform.startswith('win'):
             try:
-                testdirpath = os.path.join(root, "testdir_", random.randint(0, 4294967296))
+                testdirpath = os.path.join(root, "testdir_" + str(random.randint(0, 4294967296)))
                 os.mkdir(testdirpath)
-                os.rmmir(testdirpath)
+                os.rmdir(testdirpath)
             except:
                 return False
         else: