--- a/svghmi/gen_index_xhtml.xslt Mon Jan 18 10:32:13 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt Tue Jan 19 11:57:13 2021 +0100
@@ -1,6 +1,6 @@
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" 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#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:debug="debug" xmlns:preamble="preamble" xmlns:declarations="declarations" xmlns:definitions="definitions" xmlns:epilogue="epilogue" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions">
- <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
+<xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0"> + <xsl:output method="xml" cdata-section-elements="xhtml:script"/> <xsl:variable name="svg" select="/svg:svg"/>
<xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
<xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -573,22 +573,14 @@
<xsl:for-each select="$parsed_widgets/widget[@id = $all_page_widgets/@id and @type='Jump']">
- <xsl:variable name="_id" select="@id"/>
- <xsl:variable name="opts">
- <xsl:call-template name="jump_widget_activity">
- <xsl:with-param name="hmi_element" select="$hmi_elements[@id=$_id]"/>
- <xsl:if test="string-length($opts)>0">
- <xsl:text> hmi_widgets["</xsl:text>
- <xsl:value-of select="@id"/>
- <xsl:text>"]</xsl:text>
- <xsl:if test="position()!=last()">
+ <xsl:text> hmi_widgets["</xsl:text> + <xsl:value-of select="@id"/> + <xsl:text>"]</xsl:text> + <xsl:if test="position()!=last()"> @@ -706,6 +698,11 @@
<xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text>
+ <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:text/@inkscape:label[starts-with(., '_')]"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="substring(., 2)"/> <xsl:variable name="hmi_lists_descs" select="$parsed_widgets/widget[@type = 'List']"/>
<xsl:variable name="hmi_lists" select="$hmi_elements[@id = $hmi_lists_descs/@id]"/>
<xsl:variable name="targets_not_to_unlink" select="$hmi_lists/descendant-or-self::svg:*"/>
@@ -929,6 +926,60 @@
+ <xsl:template mode="extract_i18n" match="svg:tspan"> + <xsl:if test="string-length(.) > 0"> + <xsl:value-of select="."/> + <xsl:template mode="extract_i18n" match="svg:text"> + <xsl:attribute name="id"> + <xsl:value-of select="@id"/> + <xsl:attribute name="label"> + <xsl:value-of select="substring(@inkscape:label,2)"/> + <xsl:apply-templates mode="extract_i18n" select="svg:*"/> + <xsl:variable name="translatable_texts" select="//svg:text[starts-with(@inkscape:label, '_')]"/> + <xsl:variable name="translatable_strings"> + <xsl:apply-templates mode="extract_i18n" select="$translatable_texts"/> + <xsl:template match="preamble:i18n"> + <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> + <xsl:variable name="translations" select="ns:GetTranslations($translatable_strings)"/> + <xsl:text>var translations = { + <xsl:for-each select="$translations/*"> + <xsl:text> "</xsl:text> + <xsl:value-of select="local-name()"/> + <xsl:text> }</xsl:text> + <xsl:if test="position()!=last()"> <xsl:template mode="hmi_widgets" match="svg:*">
<xsl:variable name="widget" select="func:widget(@id)"/>
<xsl:variable name="eltid" select="@id"/>
@@ -1295,16 +1346,12 @@
<xsl:text> overshot(new_val, max) {
- <xsl:text> // TODO: use a Toast
<xsl:text> undershot(new_val, min) {
- <xsl:text> // TODO: use a Toast
@@ -2023,9 +2070,19 @@
<xsl:text> dispatch(value) {
+ <xsl:text> this.display_val = value; + <xsl:text> this.request_animate(); <xsl:text> if(this.value_elt)
- <xsl:text> this.value_elt.textContent = String(value);
+ <xsl:text> this.value_elt.textContent = String(this.display_val); <xsl:text> let [min,max,start,end] = this.range;
@@ -2033,21 +2090,29 @@
<xsl:text> let [rx,ry] = this.proportions;
- <xsl:text> let tip = start + (end-start)*Number(value)/(max-min);
+ <xsl:text> let tip = start + (end-start)*Number(this.display_val)/(max-min); - <xsl:text> if (tip-start > Math.PI) {
+ <xsl:text> if (tip-start > Math.PI)
- <xsl:text> this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip)));
+ <xsl:text> this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+ + <xsl:text> " A "+rx+","+ry+ + <xsl:text> " 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); @@ -2055,41 +2120,31 @@
- <xsl:text> let start = Number(this.path_elt.getAttribute('sodipodi:start'));
- <xsl:text> let end = Number(this.path_elt.getAttribute('sodipodi:end'));
- <xsl:text> let cx = Number(this.path_elt.getAttribute('sodipodi:cx'));
- <xsl:text> let cy = Number(this.path_elt.getAttribute('sodipodi:cy'));
- <xsl:text> let rx = Number(this.path_elt.getAttribute('sodipodi:rx'));
- <xsl:text> let ry = Number(this.path_elt.getAttribute('sodipodi:ry'));
- <xsl:text> if (ry == 0) {
+ <xsl:text> let [start, end, cx, cy, rx, ry] = ["start", "end", "cx", "cy", "rx", "ry"]. + <xsl:text> map(tag=>Number(this.path_elt.getAttribute('sodipodi:'+tag))) + <xsl:text> if (ry == 0)
- <xsl:text> if (start > end) {
+ <xsl:text> if (start > end) <xsl:text> end = end + 2*Math.PI;
- <xsl:text> let min = this.min_elt ?
- <xsl:text> Number(this.min_elt.textContent) :
- <xsl:text> this.args.length >= 1 ? this.args[0] : 0;
- <xsl:text> let max = this.max_elt ?
- <xsl:text> Number(this.max_elt.textContent) :
- <xsl:text> this.args.length >= 2 ? this.args[1] : 100;
+ <xsl:text> let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? + <xsl:text> Number(elt.textContent) : + <xsl:text> this.args.length >= i+1 ? this.args[i] : def); <xsl:text> this.range = [min, max, start, end];
@@ -2117,8 +2172,6 @@
<xsl:with-param name="mandatory" select="'no'"/>
<xsl:template mode="widget_class" match="widget[@type='CircularSlider']">
<xsl:text>class CircularSliderWidget extends Widget{
@@ -3835,10 +3888,10 @@
<xsl:text>text box button highlight</xsl:text>
- <xsl:text> // It is assumed that list content conforms to Array interface.
+ <xsl:text> /* TODO : Support HMI:List */ <xsl:for-each select="arg">
<xsl:value-of select="@value"/>
@@ -4638,142 +4691,146 @@
- <xsl:template name="jump_widget_activity">
- <xsl:param name="hmi_element"/>
- <xsl:call-template name="defs_by_labels">
- <xsl:with-param name="hmi_element" select="$hmi_element"/>
- <xsl:with-param name="labels">
- <xsl:text>active inactive</xsl:text>
- <xsl:with-param name="mandatory" select="'no'"/>
- <xsl:template name="jump_widget_disability">
- <xsl:param name="hmi_element"/>
- <xsl:call-template name="defs_by_labels">
- <xsl:with-param name="hmi_element" select="$hmi_element"/>
- <xsl:with-param name="labels">
- <xsl:text>disabled</xsl:text>
- <xsl:with-param name="mandatory" select="'no'"/>
+ <xsl:template mode="widget_class" match="widget[@type='Jump']"> + <xsl:text> class JumpWidget extends Widget{ + <xsl:text> activable = false; + <xsl:text> active = false; + <xsl:text> disabled = false; + <xsl:text> frequency = 2; + <xsl:text> update_activity() { + <xsl:text> if(this.active) { + <xsl:text> /* show active */ + <xsl:text> this.active_elt.setAttribute("style", this.active_elt_style); + <xsl:text> /* hide inactive */ + <xsl:text> this.inactive_elt.setAttribute("style", "display:none"); + <xsl:text> /* show inactive */ + <xsl:text> this.inactive_elt.setAttribute("style", this.inactive_elt_style); + <xsl:text> /* hide active */ + <xsl:text> this.active_elt.setAttribute("style", "display:none"); + <xsl:text> make_on_click() { + <xsl:text> let that = this; + <xsl:text> const name = this.args[0]; + <xsl:text> return function(evt){ + <xsl:text> /* TODO: suport path pointing to local variable whom value + <xsl:text> would be an HMI_TREE index to jump to a relative page */ + <xsl:text> const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined; + <xsl:text> switch_page(name, index); + <xsl:text> notify_page_change(page_name, index) { + <xsl:text> if(this.activable) { + <xsl:text> const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; + <xsl:text> const ref_name = this.args[0]; + <xsl:text> this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index); + <xsl:text> this.update_activity(); + <xsl:text> dispatch(value) { + <xsl:text> this.disabled = !Number(value); + <xsl:text> if(this.disabled) { + <xsl:text> /* show disabled */ + <xsl:text> this.disabled_elt.setAttribute("style", this.disabled_elt_style); + <xsl:text> /* hide inactive */ + <xsl:text> this.inactive_elt.setAttribute("style", "display:none"); + <xsl:text> /* hide active */ + <xsl:text> this.active_elt.setAttribute("style", "display:none"); + <xsl:text> /* hide disabled */ + <xsl:text> this.disabled_elt.setAttribute("style", "display:none"); + <xsl:text> this.update_activity(); <xsl:template mode="widget_defs" match="widget[@type='Jump']">
<xsl:param name="hmi_element"/>
<xsl:variable name="activity">
- <xsl:call-template name="jump_widget_activity">
+ <xsl:call-template name="defs_by_labels"> <xsl:with-param name="hmi_element" select="$hmi_element"/>
+ <xsl:with-param name="labels"> + <xsl:text>active inactive</xsl:text> + <xsl:with-param name="mandatory" select="'no'"/> <xsl:variable name="have_activity" select="string-length($activity)>0"/>
<xsl:value-of select="$activity"/>
<xsl:variable name="disability">
- <xsl:call-template name="jump_widget_disability">
+ <xsl:call-template name="defs_by_labels"> <xsl:with-param name="hmi_element" select="$hmi_element"/>
+ <xsl:with-param name="labels"> + <xsl:text>disabled</xsl:text> + <xsl:with-param name="mandatory" select="'no'"/> <xsl:variable name="have_disability" select="$have_activity and string-length($disability)>0"/>
<xsl:value-of select="$disability"/>
- <xsl:if test="$have_activity">
- <xsl:text> active: false,
- <xsl:if test="$have_disability">
- <xsl:text> disabled: false,
- <xsl:text> frequency: 2,
- <xsl:text> dispatch: function(value) {
- <xsl:text> this.disabled = !Number(value);
- <xsl:text> this.update();
- <xsl:text> update: function(){
- <xsl:if test="$have_disability">
- <xsl:text> if(this.disabled) {
- <xsl:text> /* show disabled */
- <xsl:text> this.disabled_elt.setAttribute("style", this.active_elt_style);
- <xsl:text> /* hide inactive */
- <xsl:text> this.inactive_elt.setAttribute("style", "display:none");
- <xsl:text> /* hide active */
- <xsl:text> this.active_elt.setAttribute("style", "display:none");
- <xsl:text> /* hide disabled */
- <xsl:text> this.disabled_elt.setAttribute("style", "display:none");
- <xsl:text> if(this.active) {
- <xsl:text> /* show active */
- <xsl:text> this.active_elt.setAttribute("style", this.active_elt_style);
- <xsl:text> /* hide inactive */
- <xsl:text> this.inactive_elt.setAttribute("style", "display:none");
- <xsl:text> /* show inactive */
- <xsl:text> this.inactive_elt.setAttribute("style", this.inactive_elt_style);
- <xsl:text> /* hide active */
- <xsl:text> this.active_elt.setAttribute("style", "display:none");
- <xsl:if test="$have_disability">
- <xsl:if test="$have_activity">
- <xsl:text> notify_page_change: function(page_name, index){
- <xsl:text> const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
- <xsl:text> const ref_name = this.args[0];
- <xsl:text> this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index);
- <xsl:text> this.update();
- <xsl:text> make_on_click(){
- <xsl:text> let that = this;
- <xsl:text> const name = this.args[0];
- <xsl:text> return function(evt){
- <xsl:text> const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined;
- <xsl:text> switch_page(name, index);
<xsl:text> init: function() {
<xsl:text> this.element.onclick = this.make_on_click();
@@ -4783,6 +4840,8 @@
<xsl:text> this.inactive_elt_style = this.inactive_elt.getAttribute("style");
+ <xsl:text> this.activable = true; <xsl:when test="$have_disability">
@@ -5360,13 +5419,23 @@
<xsl:text> dispatch(value) {
+ <xsl:text> this.display_val = value; + <xsl:text> this.request_animate(); <xsl:text> if(this.value_elt)
- <xsl:text> this.value_elt.textContent = String(value);
+ <xsl:text> this.value_elt.textContent = String(this.display_val); <xsl:text> let [min,max,totallength] = this.range;
- <xsl:text> let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
+ <xsl:text> let length = Math.max(0,Math.min(totallength,(Number(this.display_val)-min)*totallength/(max-min))); <xsl:text> let tip = this.range_elt.getPointAtLength(length);
@@ -5378,17 +5447,13 @@
- <xsl:text> let min = this.min_elt ?
- <xsl:text> Number(this.min_elt.textContent) :
- <xsl:text> this.args.length >= 1 ? this.args[0] : 0;
- <xsl:text> let max = this.max_elt ?
- <xsl:text> Number(this.max_elt.textContent) :
- <xsl:text> this.args.length >= 2 ? this.args[1] : 100;
+ <xsl:text> let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? + <xsl:text> Number(elt.textContent) : + <xsl:text> this.args.length >= i+1 ? this.args[i] : def); <xsl:text> this.range = [min, max, this.range_elt.getTotalLength()]
@@ -5416,8 +5481,6 @@
<xsl:with-param name="mandatory" select="'no'"/>
<xsl:template mode="widget_class" match="widget[@type='MultiState']">
<xsl:text>class MultiStateWidget extends Widget{
@@ -6396,7 +6459,7 @@
<xsl:apply-templates select="document('')/*/debug:*"/>
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml"> <body style="margin:0;overflow:hidden;user-select:none;touch-action:none;">
<xsl:copy-of select="$result_svg"/>
--- a/svghmi/i18n.py Mon Jan 18 10:32:13 2021 +0100
+++ b/svghmi/i18n.py Tue Jan 19 11:57:13 2021 +0100
@@ -1,4 +1,40 @@
+# This file is part of Beremiz +# Copyright (C) 2021: Edouard TISSERANT +# See COPYING file for copyrights details. +from __future__ import absolute_import +def open_pofile(pofile): + """ Opens PO file with POEdit """ + if sys.platform.startswith('win'): + from six.moves import winreg + poedit_cmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, + 'SOFTWARE\\Classes\\poedit\\shell\\open\\command') + poedit_path = poedit_cmd.replace('"%1"', '').strip().replace('"', '') + poedit_path = subprocess.check_output("command -v poedit", shell=True).strip() + except subprocess.CalledProcessError: + if poedit_path is None: + wx.MessageBox("POEdit is not found or installed !") + subprocess.Popen([poedit_path,pofile]) @@ -15,22 +51,71 @@
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LL@li.org>\\n"
-"Content-Type: text/plain; charset=CHARSET\\n"
-"Content-Transfer-Encoding: ENCODING\\n"
+"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" "Generated-By: SVGHMI 1.0\\n"
+def make_escapes(pass_iso8859): + escapes = [chr(i) for i in range(256)] + # Allow iso-8859 characters to pass through so that e.g. 'msgid + # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we + # escape any character outside the 32..126 range. + if not(32 <= i <= 126): + escapes[i] = "\\%03o" % i + escapes[ord('\\')] = '\\\\' + escapes[ord('\t')] = '\\t' + escapes[ord('\r')] = '\\r' + escapes[ord('\n')] = '\\n' + escapes[ord('\"')] = '\\"' +make_escapes(pass_iso8859 = True) + for i in range(len(s)): + s[i] = escapes[ord(s[i])] + return EMPTYSTRING.join(s) + # This converts the various Python string types into a format that is + # appropriate for .po files, namely much closer to C style. + s = '"' + escape(s) + '"' + lines[-1] = lines[-1] + '\n' + for i in range(len(lines)): + lines[i] = escape(lines[i]) + s = '""\n"' + lineterm.join(lines) + '"' - def ImportMessages(self, msgs):
+ def ImportMessages(self, msgs): - self.addentry("\n".join([line.text for line in msg]), msg.get("label"), msg.get("id"))
+ self.addentry("\n".join([line.text.encode("utf-8") for line in msg]), msg.get("label"), msg.get("id")) def addentry(self, msg, label, svgid):
self.__messages.setdefault(msg, set()).add(entry)
@@ -47,12 +132,12 @@
d = {'label': label, 'svgid': svgid}
- s = _(' %(label)s:%(svgid)d') % d
+ s = _(' %(label)s:%(svgid)s') % d if len(locline) + len(s) <= 78:
--- a/svghmi/svghmi.py Mon Jan 18 10:32:13 2021 +0100
+++ b/svghmi/svghmi.py Tue Jan 19 11:57:13 2021 +0100
@@ -30,7 +30,7 @@
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
from XSLTransform import XSLTransform
-from svghmi.i18n import POTWriter, POReader
+from svghmi.i18n import POTWriter, POReader, open_pofile @@ -455,19 +455,27 @@
- "bitmap": "ImportSVG", # should be something different
+ "bitmap": "EditSVG", # should be something different "tooltip": _("Edit HMI"),
"method": "_StartInkscape"
+ "bitmap": "OpenPOT", # should be something different + "tooltip": _("Open non translated message catalog (POT) to start new language"), - # TODO : Launch POEdit button for new languqge (opens POT)
- # TODO : Launch POEdit button for existing languqge (opens one of existing PO)
+ "bitmap": "EditPO", # should be something different + "name": _("Edit lang"), + "tooltip": _("Edit existing message catalog (PO) for specific language"), # - can drag'n'drop variabes to Inkscape
def _getSVGpath(self, project_path=None):
@@ -484,6 +492,9 @@
if from_project_path is not None:
shutil.copyfile(self._getSVGpath(from_project_path),
+ shutil.copyfile(self._getPOTpath(from_project_path), + # XXX TODO copy .PO files def GetSVGGeometry(self):
@@ -522,8 +533,9 @@
+ with open(self._getPOTpath(), 'w') as POT_file: # XXX scan existing PO files
@@ -678,14 +690,24 @@
open_poedit = dialog.ShowModal() == wx.ID_YES
- def _EditTranslation(self):
""" Select a specific translation and edit it with POEdit """
+ project_path = self.CTNPath() + dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a PO file"), project_path, "", _("PO files (*.po)|*.po"), wx.OPEN) + if dialog.ShowModal() == wx.ID_OK: + POFile = dialog.GetPath() + if os.path.isfile(POFile): + if os.path.dirname(POFile) == project_path: + self._StartPOEdit(POFile) + self.GetCTRoot().logger.write_error(_("PO file misplaced: %s is not in %s\n") % (POFile,project_path)) + self.GetCTRoot().logger.write_error(_("PO file do not exist: %s\n") % POFile) - def _EditNewTranslation(self):
""" Start POEdit with untouched empty catalog """
POFile = self._getPOTpath()
self._StartPOEdit(POFile)