[Scilab-users] GUI help

Claus Futtrup cfuttrup at gmail.com
Wed Nov 27 19:21:41 CET 2019


Hi there

I'm trying to build a GUI. For simplicity on the forum, I've built a 
really simple example of what I'm trying to do. How can I make the 
"conditional" GUI output work and not have it inside the calc function? 
... or, how would you do it? Thanks.

Best regards, Claus.

// GUI_EXAMPLE.SCE
//
// Demo of how to build a simple GUI in Scilab.
// Real simple, with two input variables and one output.
// The example uses the basic mechanical example of a mass and a spring as
// input parameters and calculates the resonance frequency of the mechanical
// system.

// Initialize variables
m  =  1;  // Moving mass 'm'(kilogram)
k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
fres  =  1;  // Resonance frequency (Hertz)
show_result  =  %f;

function  calc()
     m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
     k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
     fres  =  sqrt(m  *  k);
     // putting GUI updates inside the calculation routine is not pretty code.
     uicontrol("style","text","string","Result :","position",  ..
               [10  as(2)-110  80  20]);
     uicontrol("style","text","string",string(fres),  ..
               "position",[100  as(2)-110  80  20]);
     uicontrol("style","text","string","Hz ","position",  ..
               [200  as(2)-110  30  20]);
     show_result  =  %t;
     // update global variables
     [m,k,fres,show_result]=return(m,k,fres,show_result);
endfunction

function  goodbye()
     close(ge);  // Close GUI window
     printf("Resulting fres: %f Hertz\n",fres);
     abort  // Print result in console (e.g. for copy/paste), then kill the app
endfunction

ge  =  scf();  // GUI Example, Initialize and 'set current figure'
as  =  ge.axes_size;  // read size of window, as = [width height]
ge.figure_name  =  "GUI Example";  // Change window header

uicontrol("style","text","string","Moving mass :","position",  ..
           [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
           // position properties has four parameters = x,y,width,height
           // y-position counts from lower left corner, so we subtract from 'as'
ge_m  =  uicontrol("style","edit","string",string(m),  ..
           "position",[100  as(2)-35  80  20]);
uicontrol("style","text","string","kg ","position",  ..
           [200  as(2)-35  30  20],"background",[1  1  1]);

uicontrol("style","text","string","Stiffness :","position",  ..
           [10  as(2)-60  80  20],"background",[1  1  1]);
ge_k  =  uicontrol("style","edit","string",string(k),  ..
           "position",[100  as(2)-60  80  20]);
uicontrol("style","text","string","N/m ","position",  ..
           [200  as(2)-60  30  20],"background",[1  1  1]);

uicontrol("style","pushbutton","string","Calculate",  ..
           "position",[10  as(2)-85  80  20],"callback","calc");

// How do I make this "conditional"output show up in my GUI?
if  show_result  then  // If "Calculate"button was pushed at least once ...
     uicontrol("style","text","string","Result :","position",  ..
               [10  as(2)-110  80  20]);
     uicontrol("style","text","string",string(fres),  ..
               "position",[100  as(2)-110  80  20]);
     uicontrol("style","text","string","Hz ","position",  ..
               [200  as(2)-110  30  20]);
end

uicontrol("style","pushbutton","string","Exit",  ..
           "position",[10  as(2)-135  80  20],"callback","goodbye");

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20191127/3efe17ed/attachment.htm>


More information about the users mailing list