plugins/python/modules/svgui/livesvg.js
changeset 381 5c0f34a9ab00
parent 371 b7cb57a2da08
equal deleted inserted replaced
380:46d7d2ce84d2 381:5c0f34a9ab00
     1 // import Nevow.Athena
     1 // import Nevow.Athena
     2 // import Divmod.Base
     2 // import Divmod.Base
     3 function init() {
       
     4   Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'initClient');
       
     5 }
       
     6 
     3 
     7 function updateAttr(id, param, value) {
     4 function updateAttr(id, param, value) {
     8   Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'setattr', id, param, value);
     5   Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'setattr', id, param, value);
     9 }
     6 }
    10 
     7 
    11 var svguiWidgets={};
     8 var svguiWidgets = new Array();
    12 
     9 
    13 var currentObject = null;
    10 var currentObject = null;
    14 function setCurrentObject(obj) {
    11 function setCurrentObject(obj) {
    15 	currentObject = obj;
    12 	currentObject = obj;
    16 }
    13 }
    26 	element.addEventListener("draggesture", function(event){event.stopPropagation()}, true);
    23 	element.addEventListener("draggesture", function(event){event.stopPropagation()}, true);
    27 }
    24 }
    28 
    25 
    29 LiveSVGPage.LiveSVGWidget = Nevow.Athena.Widget.subclass('LiveSVGPage.LiveSVGWidget');
    26 LiveSVGPage.LiveSVGWidget = Nevow.Athena.Widget.subclass('LiveSVGPage.LiveSVGWidget');
    30 LiveSVGPage.LiveSVGWidget.methods(
    27 LiveSVGPage.LiveSVGWidget.methods(
       
    28 
    31     function handleEvent(self, evt) {
    29     function handleEvent(self, evt) {
    32         if (currentObject != null) {
    30         if (currentObject != null) {
    33             currentObject.handleEvent(evt);
    31             currentObject.handleEvent(evt);
    34         }
    32         }
    35     },
    33     },
    36 
    34 
    37     function receiveData(self, data){
    35     function receiveData(self, data){
    38         dataReceived = json_parse(data);
    36         dataReceived = json_parse(data);
    39         newState = json_parse(dataReceived.kwargs).state
    37         gadget = svguiWidgets[dataReceived.id]
    40         svguiWidgets[dataReceived.back_id].updateState(newState);
    38         if (gadget) {
       
    39         	gadget.updateValues(json_parse(dataReceived.kwargs));
       
    40         }
    41         //console.log("OBJET : " + dataReceived.back_id + " STATE : " + newState);
    41         //console.log("OBJET : " + dataReceived.back_id + " STATE : " + newState);
    42     },
    42     },
    43     
    43     
    44     function SvguiButton(self,elt_back, args){
       
    45         var btn = new svguilib.button(self, elt_back, args.sele_id, args.toggle, args.state, args.active);
       
    46         return btn;
       
    47     },
       
    48     
       
    49     function SvguiTextCtrl(self, elt_back, args){
       
    50         var txtCtrl = new svguilib.textControl(self, elt_back, args.state);
       
    51         return txtCtrl;
       
    52     },
       
    53 
       
    54     function init(self, arg1){
    44     function init(self, arg1){
    55         //console.log("Object received : " + arg1);
    45         //console.log("Object received : " + arg1);
    56         for (ind in arg1) {
    46         for (ind in arg1) {
    57             gad = json_parse(arg1[ind]);
    47             gad = json_parse(arg1[ind]);
    58             args = json_parse(gad.kwargs);
    48             args = json_parse(gad.kwargs);
    59             gadget = self[gad.__class__](gad.back_id, args);
    49             gadget = new svguilib[gad.__class__](self, gad.id, args);
    60             svguiWidgets[gadget.back_elt.id]=gadget;
    50             svguiWidgets[gadget.id]=gadget;
    61             //console.log('GADGET :' + gadget);
    51             //console.log('GADGET :' + gadget);
    62         }
    52         }
    63         var elements = document.getElementsByTagName("svg");
    53         var elements = document.getElementsByTagName("svg");
    64         for (var i = 0; i < elements.length; i++) {
    54         for (var i = 0; i < elements.length; i++) {
    65         	elements[i].addEventListener("mouseup", self, false);
    55         	elements[i].addEventListener("mouseup", self, false);
    66         }
    56         }
    67         //console.log("SVGUIWIDGETS : " + svguiWidgets);
    57         //console.log("SVGUIWIDGETS : " + svguiWidgets);
    68     }
    58     }
    69 );
    59 );
    70 
       
    71 Divmod.Base.addLoadEvent(init);