# HG changeset patch # User Edouard Tisserant # Date 1626100195 -7200 # Node ID 16066300b2544192d238d76e17e8f494eb38c02f # Parent 08a5a019bed291c886f8e7ac183da8488a5bbdc1 SVGHMI: default library path, default page when starting a SVGHMI project, error page when no SVG present diff -r 08a5a019bed2 -r 16066300b254 svghmi/default.svg --- a/svghmi/default.svg Mon Jul 12 14:13:29 2021 +0200 +++ b/svghmi/default.svg Mon Jul 12 16:29:55 2021 +0200 @@ -2,6 +2,7 @@ <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg + xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -9,84 +10,19 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="1280" + inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)" + sodipodi:docname="default.svg" + id="hmi0" + version="1.1" + viewBox="0 0 1280 720" height="720" - viewBox="0 0 1280 720" - version="1.1" - id="hmi0" - sodipodi:docname="default.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata4542"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs2" /> - <sodipodi:namedview - id="base" - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1.0" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:document-units="px" - inkscape:current-layer="hmi0" - showgrid="false" - units="px" - inkscape:zoom="0.7" - inkscape:cx="576.80864" - inkscape:cy="330.28432" - inkscape:window-width="1600" - inkscape:window-height="886" - inkscape:window-x="0" - inkscape:window-y="27" - inkscape:window-maximized="1" /> + width="1280"> <rect - style="color:#000000" - id="page0" + inkscape:label="HMI:Page:Home" + y="0" + x="0" + height="720" width="1280" - height="720" - x="0" - y="0"> - <desc - id="desc_page0">This is description for page 0 - -all lines in the form "name: value" -are used as js object definition initializer - -role: "page" -name: "Home" - -after triple opening braces is global JavaScript code - -{{{ -/* JS style Comment */ -alert("Hello World"); -}}} - -after triple closing braces is back to description -</desc> - </rect> - <text - xml:space="preserve" - style="font-style:normal;font-weight:normal;font-size:160px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" - x="436.32812" - y="418.24219" - id="text5151" - inkscape:label="count"><desc - id="desc5153">path: "count" -format: "%4.4d"</desc><tspan - sodipodi:role="line" - id="tspan5149" - x="436.32812" - y="418.24219" - style="stroke-width:1px">8888</tspan></text> + id="rect1016" + style="color:#000000;opacity:1;fill:#d6d6d6;fill-opacity:1" /> </svg> diff -r 08a5a019bed2 -r 16066300b254 svghmi/svghmi.py --- a/svghmi/svghmi.py Mon Jul 12 14:13:29 2021 +0200 +++ b/svghmi/svghmi.py Mon Jul 12 16:29:55 2021 +0200 @@ -535,7 +535,10 @@ else: target_file = open(target_path, 'wb') target_file.write("""<!DOCTYPE html> -<html> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>SVGHMI</title> +</head> <body> <h1> No SVG file provided </h1> </body> @@ -548,6 +551,8 @@ port = self.GetParamsAttributes("SVGHMI.Port")["value"] interface = self.GetParamsAttributes("SVGHMI.Interface")["value"] path = self.GetParamsAttributes("SVGHMI.Path")["value"].format(name=view_name) + if path and path[0]=='/': + path = path[1:] enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"] url="http://"+interface+("" if port==80 else (":"+str(port)) ) + (("/"+path) if path else "" @@ -672,7 +677,9 @@ dialog.Destroy() if open_inkscape: if not os.path.isfile(svgfile): - svgfile = None + # make a copy of default svg from source + default = os.path.join(ScriptDirectory, "default.svg") + shutil.copyfile(default, svgfile) open_svg(svgfile) def _StartPOEdit(self, POFile): diff -r 08a5a019bed2 -r 16066300b254 svghmi/ui.py --- a/svghmi/ui.py Mon Jul 12 14:13:29 2021 +0200 +++ b/svghmi/ui.py Mon Jul 12 16:29:55 2021 +0200 @@ -290,6 +290,8 @@ self.Config = wx.ConfigBase.Get() self.libdir = self.RecallLibDir() + if self.libdir is None: + self.libdir = os.path.join(ScriptDirectory, "widgetlib") self.picker_desc_splitter = wx.SplitterWindow(self, style=wx.SUNKEN_BORDER | wx.SP_3D)