svgui/livesvg.js
author Laurent Bessard
Thu, 06 Jun 2013 00:22:22 +0200
changeset 1229 137fd7e7b102
parent 728 e0424e96e3fd
permissions -rw-r--r--
Fixed typo in Viewer
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     1
// import Nevow.Athena
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     2
// import Divmod.Base
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     3
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     4
function updateAttr(id, param, value) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     5
  Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'setattr', id, param, value);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     6
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     7
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
     8
var svguiWidgets = new Array();
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     9
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    10
var currentObject = null;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    11
function setCurrentObject(obj) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    12
	currentObject = obj;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    13
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    14
function isCurrentObject(obj) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    15
	return currentObject == obj;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    16
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    17
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    18
function getSVGElementById(id) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    19
	return document.getElementById(id);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    20
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    21
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    22
function blockSVGElementDrag(element) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    23
	element.addEventListener("draggesture", function(event){event.stopPropagation()}, true);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    24
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    25
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    26
LiveSVGPage.LiveSVGWidget = Nevow.Athena.Widget.subclass('LiveSVGPage.LiveSVGWidget');
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    27
LiveSVGPage.LiveSVGWidget.methods(
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    28
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    29
    function handleEvent(self, evt) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    30
        if (currentObject != null) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    31
            currentObject.handleEvent(evt);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    32
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    33
    },
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    34
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    35
    function receiveData(self, data){
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    36
        dataReceived = json_parse(data);
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    37
        gadget = svguiWidgets[dataReceived.id]
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    38
        if (gadget) {
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    39
        	gadget.updateValues(json_parse(dataReceived.kwargs));
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    40
        }
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    41
        //console.log("OBJET : " + dataReceived.back_id + " STATE : " + newState);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    42
    },
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    43
    
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    44
    function init(self, arg1){
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    45
        //console.log("Object received : " + arg1);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    46
        for (ind in arg1) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    47
            gad = json_parse(arg1[ind]);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    48
            args = json_parse(gad.kwargs);
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    49
            gadget = new svguilib[gad.__class__](self, gad.id, args);
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    50
            svguiWidgets[gadget.id]=gadget;
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    51
            //console.log('GADGET :' + gadget);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    52
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    53
        var elements = document.getElementsByTagName("svg");
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    54
        for (var i = 0; i < elements.length; i++) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    55
        	elements[i].addEventListener("mouseup", self, false);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    56
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    57
        //console.log("SVGUIWIDGETS : " + svguiWidgets);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    58
    }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    59
);