svgui/livesvg.js
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 16 Feb 2018 18:38:30 +0100
changeset 1941 cde74a39df51
parent 728 e0424e96e3fd
permissions -rw-r--r--
Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Problem was caused by splashscreen timeout, wx closing averything else if there is no more main frame.
Changes:
- no more timeout for splashscreen
- use wx.App OnInit method to give first operation to mainloop, object are then now created in mainloop
- main loop is then created _before_ showing splash screen
- no more wxyield or wx processevent tricks needed to display splash screen
- exception handler not blocking anymore on dialog (callafter)
- because of mainloop being there before everything, exit must be called explicitely if exception caught during startup -> exit parameter in handle_exception + try/except around startup calls

UNTESTED ON WINDOWS
// 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);
    }
);