[Scilab-users] ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel
Antoine Monmayrant
amonmayr at laas.fr
Fri Nov 29 18:34:57 CET 2019
> > 4) I will also look into this. My problem is the steep learning curve.
> > If you look at the Scilab tutorials you have the good-old Openeering
> > LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial
> > using the Model-Viewer-Controller approach? - Maybe the
> > Model-Viewer-Controller could be presented in a _simple_ tutorial - is
> > it possible?
>
> Hmm, that would be a good idea.
> I'll see whether I can put something together.
> The thing is, MVC approach looks rather silly and overengineered on a small example.
I have not tried to follow a MWC approach, but here is my attempt at making a really simple GUI to just show the basics (see below).
It take numbers from two different types of uicontrols (a slider and an edit) and display the sum in a text uicontrol.
To keep things simple, I positioned and sized the uicontrols manually instead of using a gridbag.
I also tried to use the fancy syntax for get() and set() that do not require calling findobj(), as suggested by Samuel.
Hope it helps,
Antoine
f=figure();
/* ---------------- First number from slider ---------------- */
//values
nmin=-5;
nmax=10;
nini=7;
nsmallstep=1;
nsbigstep=2;
//slider position and size
x=10;
y=20;
w=100;
h=25;
//slider uicontrol creation in figure f
hslider=uicontrol(f, ...
"style", "slider", ...
"tag", "slider1", ...
"backgroundcolor", [1 1 1], ...
"position", [x y w h], ...
"value", nini, ...
"min", nmin, ...
"max", nmax, ...
"sliderstep", [nsmallstep, nsbigstep], ...
"callback", "update_values");
/* ------------- Second number from an editable text ------------- */
// initial value
editini="3.14";
//edit position and size
x2=x;
y2=y+h+5;
w2=w;
h2=h;
//edit uicontrol creation in figure f
hedit=uicontrol(f, ...
"style", "edit", ...
"tag", "edit2", ...
"backgroundcolor", [1 1 1], ...
"position", [x2 y2 w2 h2], ...
"string", editini, ...
"callback", "update_values");
/* ------------- Sum displayed in a text uicontrol ------------- */
// initial value
textini="Nothing"
//edit position and size
x3=x+w+5;
y3=y;
w3=w;
h3=2*h+5;
//slider uicontrol creation
htext=uicontrol(f, ...
"style", "text", ...
"tag", "text3", ...
"backgroundcolor", [1 1 1], ...
"position", [x3 y3 w3 h3], ...
"string", textini);
/* -------- callback function for slider and edit uicontrols -------- */
//Whenever user interacts with the slider or the edit uicontrols
// show the sum of both numbers in the text field
function update_values()
//temporarily deactivate the callback (don't want callback calls to stack up while processing the current one
set(gcbo,"callback_type",-1);
/*
Using the unique tag chosen at the creation time of the uicontrols
to set/get the uicontrol properties
*/
//get both numbers from the slider and the edit uicontrols
number1=get("slider1", "value");
string2=get("edit2", "string");
//do your maths & conversion
string3=string(number1+evstr(string2));
//change the string displayed in the text uicontrol
set("text3", "string", string3);
//reactivate callback
set(gcbo,"callback_type",0);
endfunction
More information about the users
mailing list