beremiz

py_ext: fix CSV Writer

18 months ago, Edouard Tisserant
d2f5eb3c7d6e
py_ext: fix CSV Writer

fix POU logic :
- SAVE is a BOOL
- invocation of py_eval on rising edge of SAVE
- remove save python argument

fix python:
- use no encoding for file open (python2)
- re-use detected dialect if any
- use no "rt+" and truncate since no need to re-sniff dialect for output file
- return "OK" instead of "#SUCCESS", preventing POU logic to ACK result
- support creating new line if writing just after last line
- support appending data on short rows

fix example:
- use a HMI:Button to trigger CSV write instead of HMI:Input +1
- reload CSVs on on each new CSV opened in file browser
- add display of CSV write output
include yslt_noindent.yml2
in xsl decl widget_desc(%name, match="widget[@type='%name']", mode="widget_desc") alias template {
type > «@type»
content;
};
decl nothing alias - ;
decl widget_class(%name) alias - {nothing};
decl widget_defs(%name) alias - {nothing};
decl widget_page(%name) alias - {nothing};
decl gen_index_xhtml alias - {nothing};
decl emit(*name) alias - {nothing};
istylesheet
/* From Inkscape */
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
extension-element-prefixes="ns func exsl regexp str dyn"
exclude-result-prefixes="ns func exsl regexp str dyn svg inkscape" {
const "indexed_hmitree", "/.."; // compatibility with parse_labels.ysl2
include parse_labels.ysl2
const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]";
include widget_*.ysl2
template "@* | node()", mode="document" {
xsl:copy apply "@* | node()", mode="document";
}
template "widget", mode="document" {
xsl:copy {
apply "@* | node()", mode="document";
defs apply ".", mode="widget_desc";
}
}
template "/" {
const "widgets"
apply "$hmi_elements", mode="parselabel";
const "widget_ns", "exsl:node-set($widgets)";
widgets
apply "$widget_ns", mode="document";
}
}