--- a/svghmi/svghmi.py Tue Jul 20 10:52:25 2021 +0200
+++ b/svghmi/svghmi.py Thu Jul 22 12:02:50 2021 +0200
@@ -468,10 +468,30 @@
self.indent = self.indent - 1
self.GetCTRoot().logger.write(" "*self.indent + "... finished in %.3fs\n"%(t - oldt))
+ def get_SVGHMI_options(self): + view_name = self.BaseParams.getName() + 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]=='/': + enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"] + url="http://"+interface+("" if port==80 else (":"+str(port)) + ) + (("/"+path) if path else "" + ) + ("#watchdog" if enable_watchdog else "") + enable_watchdog=enable_watchdog, def CTNGenerate_C(self, buildpath, locations):
location_str = "_".join(map(str, self.GetCurrentLocation()))
- view_name = self.BaseParams.getName()
+ svghmi_options = self.get_SVGHMI_options() svgfile = self._getSVGpath()
@@ -533,7 +553,7 @@
result = transform.transform(svgdom) # , profile_run=True)
except XSLTApplyError as e:
- self.FatalError("SVGHMI " + view_name + ": " + e.message)
+ self.FatalError("SVGHMI " + svghmi_options["view_name"] + ": " + e.message) for entry in transform.get_error_log():
message = "SVGHMI: "+ entry.message + "\n"
@@ -568,25 +588,12 @@
res += ((target_fname, open(target_path, "rb")),)
- 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]=='/':
- enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"]
- url="http://"+interface+("" if port==80 else (":"+str(port))
- ) + (("/"+path) if path else ""
- ) + ("#watchdog" if enable_watchdog else "")
for thing in ["Start", "Stop", "Watchdog"]:
given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"]
- repr(shlex.split(given_command.format(
+ repr(shlex.split(given_command.format(**svghmi_options))) + ")") if given_command else "pass # no command given"
runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str)
@@ -657,17 +664,13 @@
""".format(location=location_str,
- enable_watchdog = enable_watchdog,
watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"],
watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"],
maxConnections = self.GetParamsAttributes("SVGHMI.MaxConnections")["value"],
- maxConnections_total = maxConnectionsTotal
+ maxConnections_total = maxConnectionsTotal, @@ -685,6 +688,9 @@
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n") % svgpath)
+ def getDefaultSVG(self): + return os.path.join(ScriptDirectory, "default.svg") def _StartInkscape(self):
svgfile = self._getSVGpath()
@@ -698,7 +704,7 @@
if not os.path.isfile(svgfile):
# make a copy of default svg from source
- default = os.path.join(ScriptDirectory, "default.svg")
+ default = self.getDefaultSVG() shutil.copyfile(default, svgfile)