svghmi/widget_listswitch.ysl2
author Edouard Tisserant <edouard@beremiz.fr>
Thu, 05 Dec 2024 13:56:59 +0100
changeset 4060 d2f5eb3c7d6e
parent 3403 4a048b5b9e3b
permissions -rw-r--r--
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
3403
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     1
// widget_switch.ysl2
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     2
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     3
widget_desc("ListSwitch") {
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     4
    longdesc
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     5
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     6
    ListSwitch widget displays one item of an HMI:List depending on value of
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     7
    given variable. Main element of the widget must be a clone of the list or
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     8
    of an item of that list.  
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
     9
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    10
    Given variable's current value is compared to list items
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    11
    label. For exemple if given variable type
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    12
    is HMI_INT and value is 1, then item with label '1' will be displayed.
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    13
    If matching variable of type HMI_STRING, then no quotes are needed. 
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    14
    For exemple, 'hello' match HMI_STRING 'hello'.
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    15
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    16
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    17
    shortdesc > Displays item of an HMI:List whose label matches value.
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    18
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    19
    path name="value" accepts="HMI_INT,HMI_STRING" > value to compare to labels
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    20
    
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    21
}
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    22
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    23
widget_class("ListSwitch"){
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    24
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    25
        frequency = 5;
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    26
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    27
}
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    28
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    29
widget_defs("ListSwitch") {
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    30
    // cloned element must be part of a HMI:List or a HMI:List
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    31
    const "targetid", "substring-after($hmi_element/@xlink:href,'#')";
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    32
    const "from_list", "$hmi_lists[(@id | */@id) = $targetid]";
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    33
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    34
        dispatch: function(value) {
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    35
            this.element.href.baseVal = "#"+hmi_widgets["«$from_list/@id»"].items[value];
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    36
        },
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    37
    ||
4a048b5b9e3b SVGHMI: added ListSwitch widget
Edouard Tisserant
parents:
diff changeset
    38
}