tests/svghmi/py_ext_0@py_ext/pyfile.xml
author usveticic
Wed, 16 Sep 2020 09:41:52 +0200
branchsvghmi
changeset 3056 827bf284feec
parent 2996 14635b09d329
child 3031 440d74319a74
permissions -rw-r--r--
Button, ToggleButton and slider updated. Error to warning when building

Button fixed so it doesn't release until it gets feedback from plc

Toggle button changed so it makes changes instantly. There was too big delay if we waited for feedback.

Slider added new features need some changes for final version.
<?xml version='1.0' encoding='utf-8'?>
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <variables>
    <variable name="SomePLCglobal" type="HMI_STRING" onchange="MyOnChangeFunc"/>
    <variable name="AlarmCount" type="HMI_INT"/>
  </variables>
  <globals>
    <xhtml:p><![CDATA[
from twisted.web.resource import Resource
import json

class AlarmJsonResource(Resource):
    def render_GET(self, request):
        return ''

    def render_POST(self, request):
        print(request.__dict__)
        newdata = request.content.getvalue()
        print newdata
        selected_alarms = [
            {"name":"three", "sides":3},
            {"name":"four", "sides":4},
            {"name":"five", "sides":5},
            {"name":"six", "sides":6},
        ]
        return json.dumps(selected_alarms)


def MyOnChangeFunc(changed_var_name):
    print changed_var_name + ": " + getattr(PLCGlobals, changed_var_name)

]]></xhtml:p>
  </globals>
  <init>
    <xhtml:p><![CDATA[
]]></xhtml:p>
  </init>
  <cleanup>
    <xhtml:p><![CDATA[
]]></xhtml:p>
  </cleanup>
  <start>
    <xhtml:p><![CDATA[

svghmi_root.putChild("alarms", AlarmJsonResource())


]]></xhtml:p>
  </start>
  <stop>
    <xhtml:p><![CDATA[
]]></xhtml:p>
  </stop>
</PyFile>