SVGHMI: Better error message when inkscape is not installed. svghmi
authorEdouard Tisserant
Thu, 03 Sep 2020 11:16:08 +0200
branchsvghmi
changeset 3052 ffce85221ea5
parent 3051 44dd48070e41
child 3053 bff50b7e50ee
SVGHMI: Better error message when inkscape is not installed.
docutil/docsvg.py
svghmi/svghmi.py
--- a/docutil/docsvg.py	Wed Sep 02 11:45:41 2020 +0200
+++ b/docutil/docsvg.py	Thu Sep 03 11:16:08 2020 +0200
@@ -34,16 +34,23 @@
     if wx.Platform == '__WXMSW__':
         from six.moves import winreg
         try:
-            svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
-                                           'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
+                svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
+                                               'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
         except OSError:
-            svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
-                                           'Software\\Classes\\inkscape.svg\\shell\\open\\command')
+            try:
+                svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
+                                               'Software\\Classes\\inkscape.svg\\shell\\open\\command')
+            except Exception:
+                return None
+
         svgexepath = svgexepath.replace('"%1"', '').strip()
         return svgexepath.replace('"', '')
     else:
-        # TODO: search path
-        return os.path.join("/usr/bin", "inkscape")
+        # TODO: search for inkscape in $PATH
+        svgexepath = os.path.join("/usr/bin", "inkscape")
+        if os.path.exists(svgexepath):
+            return svgexepath
+        return None
 
 
 def open_win_svg(svgexepath, svgfile):
--- a/svghmi/svghmi.py	Wed Sep 02 11:45:41 2020 +0200
+++ b/svghmi/svghmi.py	Thu Sep 03 11:16:08 2020 +0200
@@ -485,13 +485,17 @@
         InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
 
         inkpath = get_inkscape_path()
+
+        if inkpath is None:
+            self.FatalError("SVGHMI: inkscape is not installed.")
+
         svgpath = self._getSVGpath()
         status, result, _err_result = ProcessLogger(self.GetCTRoot().logger,
                                                      '"' + inkpath + '" -S "' + svgpath + '"',
                                                      no_stdout=True,
                                                      no_stderr=True).spin()
         if status != 0:
-            self.FatalError("SVGHMI : inkscape couldn't extract geometry from given SVG")
+            self.FatalError("SVGHMI: inkscape couldn't extract geometry from given SVG.")
 
         res = []
         for line in result.split():