[Scilab-users] uicontrol & wiki

Samuel Gougeon sgougeon at free.fr
Tue Dec 20 22:51:08 CET 2016


Le 20/12/2016 22:24, Samuel Gougeon a écrit :
>
> If i understand well your question -- rather the same than Jens's one, 
> that likes loops too, mainly "while" ones embeding xclick() :) --, i 
> would answer the same that i did to him:
> A callback is a local (asynchronous) script that is executed each time 
> that the interactive component defining it is activated.
> So here, each time you press the x^2 button, each time its callback is 
> executed.
>
> In the callback, the instruction
> x = evstr(e.string);
> is not robust, because at the moment the button is pressed, the 
> variable "e"
> may no longer exist. Clearing it or overwriting it with something else 
> in the meantime
> doesnot affect the graphic component. "e" is just a handle (while 
> delete(e) would really
> delete the component).
> For a robust implementation, gcbo.stringis required instead.

OK, here, the button should refer to the edit area. So gcbo is not the 
whole thing.
When writing things, either the button should depend on the edit area, 
or at least
should have a way to get its handle. .tag and findobj() can be used to 
do that :
Here is a robust implementation:

f  =  scf();
uicontrol(f,  "style",  "edit",  ...
              "position",  [0  0  100  20],  ..
              "tag",  "editArea");
uicontrol(f,  "style",  "text",  ...
              "position",  [200  0  100  20],  ..
              "string",  "",  ..
              "tag",  "dispArea");
uicontrol(f,  "style",  "pushbutton",  ...
              "string",  "$x^2$",...
              "position",  [100  0  100  20],  ...
              "callback",  ..
                 "e = findobj(""tag"",""editArea"");"  +  ..
                 "t = findobj(""tag"",""dispArea"");"  +  ..
                 "x = evstr(e.string);"  +  ..
                 "y = x^2;"  +  ..
                 "t.string = string(y);"  +  ..
                 "plot2d(x, y, style = -1);");

HTH
Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161220/0c6d57e4/attachment.htm>


More information about the users mailing list