tests/projects/svghmi_widgets/py_ext_0@py_ext/pyfile.xml
author etisserant <edouard.tisserant@gmail.com>
Tue, 13 Dec 2022 22:04:16 +0100
changeset 3699 ddadbdf20e70
parent 3416 53c66c4aefa3
permissions -rw-r--r--
GH CI: try reverting to previous version of ubuntu
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
     1
<?xml version='1.0' encoding='utf-8'?>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
     2
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
     3
  <variables>
3034
793ce2117258 SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
Edouard Tisserant
parents: 3031
diff changeset
     4
    <variable name="AlarmNotify" type="HMI_INT"/>
3046
d1bb0c09e412 SVGHMI: cosmetic fix in test
Edouard Tisserant
parents: 3038
diff changeset
     5
    <variable name="SendAlarm" type="HMI_INT" onchange="TriggerAlarm"/>
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
     6
    <variable name="AlarmText" type="HMI_STRING" initial="'POS'"/>
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
     7
    <variable name="AlarmStatus" type="HMI_STRING" initial="'alarm'"/>
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
     8
  </variables>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
     9
  <globals>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    10
    <xhtml:p><![CDATA[
2994
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    11
from twisted.web.resource import Resource
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    12
import json, time, random, collections
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    13
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    14
Alarms = []
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    15
AlarmIndex = {}
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    16
lastid = 0
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    17
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    18
def TriggerAlarm(changed_var_name):
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    19
    global Alarms, lastid
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    20
    new_entry = [time.time(), PLCGlobals.AlarmText, PLCGlobals.AlarmStatus, lastid]
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    21
    Alarms.append(new_entry)
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    22
    AlarmIndex[lastid] = new_entry
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    23
    lastid = lastid + 1
3038
92101729f7b7 SVGHMI: Alarm test not using Button widget anymore, too many problems. Use Input widget instead to increment value on each click and execute python code on change.
Edouard Tisserant
parents: 3036
diff changeset
    24
    PLCGlobals.AlarmNotify = random.randint(0, 4294967296)
2994
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    25
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    26
class AlarmJsonResource(Resource):
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    27
    def render_GET(self, request):
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    28
        return ''
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    29
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    30
    def render_POST(self, request):
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    31
        newstr = request.content.getvalue()
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    32
        newdata = json.loads(newstr)
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    33
        args = newdata[u'args']
3065
c369a742443d SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents: 3048
diff changeset
    34
        range_feedback = newdata[u'range']
c369a742443d SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents: 3048
diff changeset
    35
        slider_position = newdata[u'position']
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    36
        visible = newdata[u'visible']
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    37
        extra = newdata[u'extra']
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    38
        options = newdata[u'options']
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    39
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    40
        if len(options) == 2 :
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    41
            action, alarmid = options
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    42
            if action == "onClick[acknowledge]":
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    43
                AlarmIndex[int(alarmid)][2] = "ack"
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    44
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    45
        answer = self.renderTable(range_feedback, slider_position, visible, extra)
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    46
        janswer = json.dumps(answer)
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    47
        return janswer
2994
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    48
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    49
    def renderTable(self, old_range, old_position, visible, extra):
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    50
        if len(extra) > 0 and extra[0] != "":
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    51
            fAlarms = [alrm for alrm in Alarms if alrm[1].find(extra[0])!=-1]
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    52
        else:
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    53
            fAlarms = Alarms
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    54
        new_range = len(fAlarms)
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    55
        delta = new_range - visible
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    56
        new_position = 0 if delta <= 0 else delta if old_position > delta else old_position
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    57
        new_visible = new_range if delta <= 0 else visible
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    58
        
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    59
        visible_alarms = []
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3065
diff changeset
    60
        for ts, text, status, alarmid in fAlarms[new_position:new_position + new_visible]:
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    61
            visible_alarms.append({
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    62
                "time": time.ctime(ts),
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    63
                "text": text, # TODO translate text
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    64
                "status": status,
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3046
diff changeset
    65
                "alarmid": alarmid
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    66
            })
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    67
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    68
        return new_range, new_position, visible_alarms
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3034
diff changeset
    69
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    70
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    71
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    72
  </globals>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    73
  <init>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    74
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    75
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    76
  </init>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    77
  <cleanup>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    78
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    79
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    80
  </cleanup>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    81
  <start>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    82
    <xhtml:p><![CDATA[
2994
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    83
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    84
svghmi_root.putChild("alarms", AlarmJsonResource())
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    85
b6a9ef7f7e43 SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2983
diff changeset
    86
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    87
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    88
  </start>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    89
  <stop>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    90
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    91
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    92
  </stop>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    93
</PyFile>