Would like to have app access from a timed trigger function -
for sample code below able set label 'statmsg' different value(time or counter or status) once every minute. not have 'app' access testtrigger():
//trigger every minute function createtriggerinvite() { scriptapp.newtrigger('testtrigger') .timebased() .everyminutes(1) .create(); } function testtrigger(){ //not working var app=uiapp.getactiveapplication(); app.getelementbyid('statmsg').settext('time'); return app; } function doget(e) { var dbgtime=true; dbgtime=false; //var dbg=true; createtriggerinvite(); if (dbg==true)log('doget','starting'); var app = uiapp.createapplication(); var stat=app.createlabel('status...').setwidth(50) .setstyleattribute('color', 'white') .sethorizontalalignment(uiapp.horizontalalignment.left) .setid('statmsg')); app.add(stat); return app; }
uiapp widgets can't updated else events happening in uiapp instance, not triggers or other external app.
there way achieve auto update in uiapp uses different approach.
the idea change state of widget fire event handler. timing defined in sleep call.
here example (already published here, op explains better reason used this) uses checkbox initiate event calls server handler :
function doget() { var app = uiapp.createapplication().settitle('counter/timer'); var panel = app.createabsolutepanel().setstyleattribute('padding','35'); var counter = app.createhtml().setid('counter').sethtml('<b>timer = wait</b>').setstyleattribute('fontsize','40px');// set start display var clo = app.createtextbox().setname('clo').setid('clo').setvalue('0').setvisible(false);//set start value in seconds var handler1 = app.createserverhandler('dosomething').addcallbackelement(panel); var chk1 = app.createcheckbox('test1').addvaluechangehandler(handler1).setvisible(true).setid('chk1').setvisible(false); app.add(panel.add(chk1).add(counter).add(clo)); chk1.setvalue(true,true);// start process return app} function dosomething(e) { var app = uiapp.getactiveapplication(); var xx = number(e.parameter.clo); var disp = app.getelementbyid('counter') xx++ ;// replace xx-- count downwards if(xx>600){ // 10 minutes timeout example disp.sethtml('<b> game on ;-)</b>').setstyleattribute('fontsize','80px').setstyleattribute('color','red') return app } var cnt = app.getelementbyid('clo').setvalue(xx) disp.sethtml('<b>'+t(xx)+'</b>') utilities.sleep(1000); // instead of sleeping ! // below comes "active" part var chk1 = app.getelementbyid('chk1').setvalue(false,false) var chk1 = app.getelementbyid('chk1').setvalue(true,true) return app; } function t(val){ var min = parseint(val/60); var sec = val-(60*min); if(sec<10){sec='0'+sec} if(min<10){min='0'+min} var st = '> '+min+':'+sec return st }
Comments
Post a Comment