svgui/svgui.py
changeset 1784 64beb9e9c749
parent 1776 81aa8aaccdd4
child 1832 0f1081928d65
--- a/svgui/svgui.py	Mon Aug 21 20:17:19 2017 +0000
+++ b/svgui/svgui.py	Mon Aug 21 23:22:58 2017 +0300
@@ -24,7 +24,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 import wx
-import os, sys, shutil
+import os
+import sys
+import shutil
 
 from pyjs import translate
 
@@ -33,21 +35,27 @@
 from docutil import open_svg
 from py_ext import PythonFileCTNMixin
 
+
 class SVGUILibrary(POULibrary):
     def GetLibraryPath(self):
-        return paths.AbsNeighbourFile(__file__, "pous.xml") 
+        return paths.AbsNeighbourFile(__file__, "pous.xml")
+
 
 class SVGUI(PythonFileCTNMixin):
 
     ConfNodeMethods = [
-        {"bitmap" : "ImportSVG",
-         "name" : _("Import SVG"),
-         "tooltip" : _("Import SVG"),
-         "method" : "_ImportSVG"},
-        {"bitmap" : "ImportSVG", # should be something different
-         "name" : _("Inkscape"),
-         "tooltip" : _("Create HMI"),
-         "method" : "_StartInkscape"},
+        {
+            "bitmap":    "ImportSVG",
+            "name":    _("Import SVG"),
+            "tooltip": _("Import SVG"),
+            "method":   "_ImportSVG"
+        },
+        {
+            "bitmap":    "ImportSVG",  # should be something different
+            "name":    _("Inkscape"),
+            "tooltip": _("Create HMI"),
+            "method":   "_StartInkscape"
+        },
     ]
 
     def ConfNodePath(self):
@@ -70,21 +78,21 @@
 
     def CTNGenerate_C(self, buildpath, locations):
         """
-        Return C code generated by iec2c compiler 
+        Return C code generated by iec2c compiler
         when _generate_softPLC have been called
         @param locations: ignored
         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
         """
-        
+
         current_location = self.GetCurrentLocation()
         # define a unique name for the generated C file
-        location_str = "_".join(map(lambda x:str(x), current_location))
-        
+        location_str = "_".join(map(lambda x: str(x), current_location))
+
         res = ([], "", False)
-        
-        svgfile=self._getSVGpath()
+
+        svgfile = self._getSVGpath()
         if os.path.exists(svgfile):
-            res += (("gui.svg", file(svgfile,"rb")),)
+            res += (("gui.svg", file(svgfile, "rb")),)
 
         svguiserverfile = open(self._getSVGUIserverpath(), 'r')
         svguiservercode = svguiserverfile.read()
@@ -92,7 +100,7 @@
 
         svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js")
         svguilibfile = open(svguilibpath, 'w')
-        fpath=paths.AbsDir(__file__)
+        fpath = paths.AbsDir(__file__)
         svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "sys.py"), "sys"))
         svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "_pyjs.js"), 'r').read())
         svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "pyjslib.py"), "pyjslib"))
@@ -102,26 +110,25 @@
         svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read())
         svguilibfile.close()
         jsmodules = {"LiveSVGPage": "svguilib.js"}
-        res += (("svguilib.js", file(svguilibpath,"rb")),)
-        
-        runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str)
+        res += (("svguilib.js", file(svguilibpath, "rb")),)
+
+        runtimefile_path = os.path.join(buildpath, "runtime_%s.py" % location_str)
         runtimefile = open(runtimefile_path, 'w')
-        runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"})
+        runtimefile.write(svguiservercode % {"svgfile": "gui.svg"})
         runtimefile.write("""
 def _runtime_%(location)s_start():
     website.LoadHMI(%(svgui_class)s, %(jsmodules)s)
-    
+
 def _runtime_%(location)s_stop():
     website.UnLoadHMI()
-    
-""" % {"location": location_str,
-       "svgui_class": "SVGUI_HMI",
-       "jsmodules" : str(jsmodules),
-      })
+
+        """ % {"location": location_str,
+               "svgui_class": "SVGUI_HMI",
+               "jsmodules": str(jsmodules)})
         runtimefile.close()
-        
-        res += (("runtime_%s.py"%location_str, file(runtimefile_path,"rb")),)
-        
+
+        res += (("runtime_%s.py" % location_str, file(runtimefile_path, "rb")),)
+
         return res
 
     def _ImportSVG(self):
@@ -131,8 +138,8 @@
             if os.path.isfile(svgpath):
                 shutil.copy(svgpath, self._getSVGpath())
             else:
-                self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n")%svgpath)
-        dialog.Destroy()  
+                self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n") % svgpath)
+        dialog.Destroy()
 
     def _StartInkscape(self):
         svgfile = self._getSVGpath()
@@ -141,7 +148,7 @@
             dialog = wx.MessageDialog(self.GetCTRoot().AppFrame,
                                       _("You don't have write permissions.\nOpen Inkscape anyway ?"),
                                       _("Open Inkscape"),
-                                      wx.YES_NO|wx.ICON_QUESTION)
+                                      wx.YES_NO | wx.ICON_QUESTION)
             open_inkscape = dialog.ShowModal() == wx.ID_YES
             dialog.Destroy()
         if open_inkscape: