tests/svghmi/py_ext_0@py_ext/pyfile.xml
author Edouard Tisserant
Tue, 25 Aug 2020 14:32:39 +0200
branchsvghmi
changeset 3036 4930455428df
parent 3034 793ce2117258
child 3038 92101729f7b7
permissions -rw-r--r--
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.
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"/>
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
     5
    <variable name="SendAlarm" type="HMI_BOOL" onchange="TriggerAlarm"/>
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
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
    12
import json, time, random
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 = []
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
    15
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
    16
def TriggerAlarm(changed_var_name):
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
    global 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
    18
    if(getattr(PLCGlobals, changed_var_name)):
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
    19
        Alarms.append((time.time(), PLCGlobals.AlarmText, PLCGlobals.AlarmStatus))
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
    20
        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
    21
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
    22
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
    23
    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
    24
        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
    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
    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
    27
        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
    28
        newdata = json.loads(newstr)
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
    29
        print newdata
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
    30
        vars = newdata[u'vars']
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
        args = newdata[u'args']
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
        visible = newdata[u'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
    33
        svars = (vars + [0,0])[:3]
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
    34
        range_feedback = svars[1]
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
    35
        slider_position = svars[2]
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
        answer = self.renderTable(range_feedback, slider_position, visible, *(args+svars[3:]))
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
    37
        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
    38
        print janswer
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
    39
        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
    40
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
    41
    def renderTable(self, old_range, old_position, visible, *options):
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
    42
        new_range = len(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
    43
        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
    44
        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
    45
        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
    46
        
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
        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
    48
        for ts, text, status in Alarms[new_position:new_position + new_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
    49
            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
    50
                "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
    51
                "text": text, # TODO translate text
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
    52
                "status": status
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
    53
            })
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    54
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
        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
    56
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    57
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    58
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    59
  </globals>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    60
  <init>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    61
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    62
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    63
  </init>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    64
  <cleanup>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    65
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    66
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    67
  </cleanup>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    68
  <start>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    69
    <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
    70
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
    71
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
    72
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
    73
2983
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    74
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    75
  </start>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    76
  <stop>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    77
    <xhtml:p><![CDATA[
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    78
]]></xhtml:p>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    79
  </stop>
43198edb6ac0 SVGHMI: Add use of Python PLC Globals it test
Edouard Tisserant
parents:
diff changeset
    80
</PyFile>