svgui/livesvg.js
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 16 Aug 2018 13:42:18 +0300
changeset 2289 cf0934b42d66
parent 728 e0424e96e3fd
permissions -rw-r--r--
Update README for WAMP example to use crossbar with python3

crossbar python2 support is broken in v18.7.2.
I've submitted with fixes for that.
https://github.com/crossbario/crossbar/pull/1376

But they don't test crossbar with python2 in CI, so it's going to be
broken again in the future.
And there is no much reason to use crossbar with python2.
// import Nevow.Athena
// import Divmod.Base

function updateAttr(id, param, value) {
  Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'setattr', id, param, value);
}

var svguiWidgets = new Array();

var currentObject = null;
function setCurrentObject(obj) {
	currentObject = obj;
}
function isCurrentObject(obj) {
	return currentObject == obj;
}

function getSVGElementById(id) {
	return document.getElementById(id);
}

function blockSVGElementDrag(element) {
	element.addEventListener("draggesture", function(event){event.stopPropagation()}, true);
}

LiveSVGPage.LiveSVGWidget = Nevow.Athena.Widget.subclass('LiveSVGPage.LiveSVGWidget');
LiveSVGPage.LiveSVGWidget.methods(

    function handleEvent(self, evt) {
        if (currentObject != null) {
            currentObject.handleEvent(evt);
        }
    },

    function receiveData(self, data){
        dataReceived = json_parse(data);
        gadget = svguiWidgets[dataReceived.id]
        if (gadget) {
        	gadget.updateValues(json_parse(dataReceived.kwargs));
        }
        //console.log("OBJET : " + dataReceived.back_id + " STATE : " + newState);
    },
    
    function init(self, arg1){
        //console.log("Object received : " + arg1);
        for (ind in arg1) {
            gad = json_parse(arg1[ind]);
            args = json_parse(gad.kwargs);
            gadget = new svguilib[gad.__class__](self, gad.id, args);
            svguiWidgets[gadget.id]=gadget;
            //console.log('GADGET :' + gadget);
        }
        var elements = document.getElementsByTagName("svg");
        for (var i = 0; i < elements.length; i++) {
        	elements[i].addEventListener("mouseup", self, false);
        }
        //console.log("SVGUIWIDGETS : " + svguiWidgets);
    }
);