--- a/docutil/docsvg.py Wed May 25 20:00:31 2022 +0200
+++ b/docutil/docsvg.py Thu May 26 23:39:30 2022 +0200
@@ -27,7 +27,8 @@
-def get_inkscape_path():
+def _get_inkscape_path(): """ Return the Inkscape binary path """
if wx.Platform == '__WXMSW__':
@@ -55,6 +56,36 @@
except subprocess.CalledProcessError:
+def get_inkscape_path(): + """ Return the Inkscape binary path """ + if _inkscape_path is not None: + _inkscape_path = _get_inkscape_path() +def _get_inkscape_version(): + inkpath = get_inkscape_path() + subprocess.check_output([inkpath,"--version"]).split()[1].split('.')) +_inkscape_version = None +def get_inkscape_version(): + global _inkscape_version + if _inkscape_version is not None: + return _inkscape_version + _inkscape_version = _get_inkscape_version() + return _inkscape_version """ Generic function to open SVG file """
--- a/svghmi/svghmi.py Wed May 25 20:00:31 2022 +0200
+++ b/svghmi/svghmi.py Thu May 26 23:39:30 2022 +0200
@@ -282,6 +282,10 @@
(_("HMI Tree"), "CreateSVGHMI_UI")]
+ def __init__(self, parent, controler, window): + ConfTreeNodeEditor.__init__(self, parent, controler, window) + self.Controler = controler def CreateSVGHMI_UI(self, parent):
@@ -292,7 +296,7 @@
hmitree_backup_file = open(hmitree_backup_path, 'rb')
hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot())
- ret = SVGHMI_UI(parent, Register_SVGHMI_UI_for_HMI_tree_updates)
+ ret = SVGHMI_UI(parent, self.Controler, Register_SVGHMI_UI_for_HMI_tree_updates) on_hmitree_update(hmi_tree_root)
--- a/svghmi/ui.py Wed May 25 20:00:31 2022 +0200
+++ b/svghmi/ui.py Thu May 26 23:39:30 2022 +0200
@@ -11,6 +11,7 @@
from threading import Thread, Lock
from functools import reduce
from itertools import izip
@@ -26,7 +27,7 @@
import util.paths as paths
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
-from docutil import get_inkscape_path
+from docutil import get_inkscape_path, get_inkscape_version from util.ProcessLogger import ProcessLogger
@@ -276,8 +277,10 @@
_conf_key = "SVGHMIWidgetLib"
+thumbnail_temp_path = None class WidgetLibBrowser(wx.SplitterWindow):
- def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
+ def __init__(self, parent, controler, id=wx.ID_ANY, pos=wx.DefaultPosition, wx.SplitterWindow.__init__(self, parent,
@@ -287,6 +290,7 @@
+ self.Controler = controler self.Config = wx.ConfigBase.Get()
self.libdir = self.RecallLibDir()
@@ -455,10 +459,14 @@
self.msg = _("Inkscape is not installed.")
+ export_opt = "-o" if get_inkscape_version()[0] > 0 else "-e" # TODO: spawn a thread, to decouple thumbnail gen
status, result, _err_result = ProcessLogger(
- '"' + inkpath + '" "' + svgpath + '" -e "' + thumbpath +
+ self.Controler.GetCTRoot().logger, + '"' + inkpath + '" "' + svgpath + '" ' + + export_opt + ' "' + thumbpath + '" -D -h ' + str(_preview_height)).spin()
self.msg = _("Inkscape couldn't generate thumbnail.")
@@ -470,10 +478,28 @@
Called when tree item is selected
@param event: wx.TreeEvent
+ global thumbnail_temp_path item_pydata = self.widgetpicker.GetPyData(event.GetItem())
if item_pydata is not None:
- dname = os.path.dirname(svgpath)
+ if thumbnail_temp_path is None: + dname = os.path.dirname(svgpath) + thumbdir = os.path.join(dname, ".svghmithumbs") + if not os.path.exists(thumbdir): + # library not writable : use temp dir + thumbnail_temp_path = os.path.join( + tempfile.gettempdir(), "svghmithumbs") + thumbdir = thumbnail_temp_path + if not os.path.exists(thumbdir): + thumbdir = thumbnail_temp_path fname = os.path.basename(svgpath)
hasher = hashlib.new('md5')
with open(svgpath, 'rb') as afile:
@@ -485,30 +511,24 @@
digest = hasher.hexdigest()
thumbfname = os.path.splitext(fname)[0]+"_"+digest+".png"
- thumbdir = os.path.join(dname, ".svghmithumbs")
thumbpath = os.path.join(thumbdir, thumbfname)
have_thumb = os.path.exists(thumbpath)
- if not os.path.exists(thumbdir):
- have_thumb = self.GenThumbnail(svgpath, thumbpath)
- self.bmp = wx.Bitmap(thumbpath) if have_thumb else None
+ self.Controler.GetCTRoot().logger.write( + "Rendering preview of " + fname + " widget.\n") + have_thumb = self.GenThumbnail(svgpath, thumbpath) - self.selected_SVG = svgpath if have_thumb else None
+ self.bmp = wx.Bitmap(thumbpath) if have_thumb else None - self.AnalyseWidgetAndUpdateUI(fname)
+ self.selected_SVG = svgpath if have_thumb else None - self.SetMessage(self.msg)
+ self.AnalyseWidgetAndUpdateUI(fname)
- self.msg = _("Widget library must be writable")
+ self.SetMessage(self.msg)
def OnHMITreeNodeSelection(self, hmitree_nodes):
self.hmitree_nodes = hmitree_nodes
@@ -687,12 +707,12 @@
class SVGHMI_UI(wx.SplitterWindow):
- def __init__(self, parent, register_for_HMI_tree_updates):
+ def __init__(self, parent, controler, register_for_HMI_tree_updates): wx.SplitterWindow.__init__(self, parent,
style=wx.SUNKEN_BORDER | wx.SP_3D)
self.SelectionTree = HMITreeSelector(self)
- self.Staging = WidgetLibBrowser(self)
+ self.Staging = WidgetLibBrowser(self, controler) self.SplitVertically(self.SelectionTree, self.Staging, 300)
register_for_HMI_tree_updates(weakref.ref(self))