Discussion:
multiple instances of a same gui
(too old to reply)
matt
2007-03-13 01:31:25 UTC
Permalink
hi all,

i have a gui (made with scilab commands figure, uicontrol etc) with which i
handle a plot. This gui has several sliders, some pushbutton and a lot of
text... very simple.

I'd like to be able to run multiple instances of this gui, where each of
them creates a new plot with its default values the first time is called,
and then update its plot with values specified by the user through the
uicontrols.

The point is that all the guis created call the same (shared) callbacks,
e.g. if cb_slider is the callback associate to a slider of the gui, all the
gui (when the user click that slider) call cb_slider and only the current
gui updates its slider!
The same problem with pushbuttons.
But if for the pushbutton i can know the "caller object" through the
variable gcbo, i've found no solutions to know which slider has called the
callback. Any suggestion?

I've read other threads and i've heard that scilab uicontrols and figure
are rather limited. One should use tcl instead. With a gui in pure tcl
could i resolve my problems? (i don't know anything about tcl, but if
necessary i could learn it...)

thanks in advance

matt
François VOGEL
2007-03-13 17:22:20 UTC
Permalink
Post by matt
I'd like to be able to run multiple instances of this gui, where each of
them creates a new plot with its default values the first time is called,
and then update its plot with values specified by the user through the
uicontrols.
The point is that all the guis created call the same (shared) callbacks,
e.g. if cb_slider is the callback associate to a slider of the gui, all the
gui (when the user click that slider) call cb_slider and only the current
gui updates its slider!
The same problem with pushbuttons.
I see what you mean.
I can reproduce this behaviour with the following example code extracted and
modified from the uicontrol demo:

f=figure()
t1 = uicontrol(f, "Position" , [140 130 25 15],...
"Style" , "text",...
"String" , "50",...
"BackgroundColor",[1 1 1]);
s1 = uicontrol(f, "Position" , [10 130 120 15],..
"Style" , "slider",...
"Min" , 0,...
"Max" , 100,...
"Value" , 50,...
"SliderStep", [2 10],...
"callback" , "set(t1,''String'',string(get(s1,''Value'')))");
b1 = uicontrol(f, "Position" , [50 170 70 20],...
"Style" , "pushbutton",...
"String" , "Disp value",...
"callback" , "disp(get(s1,''value''))");

Exec this once.
You get a window with the two controls and the text display. Slide the
slider, it will update the text display. Push the button, you will see the
selected value in the Scilab shell.

Now exec this code a second time without closing the window.
You get a second window, identical to the first one, but with another id (f
is now 2 instead of 1).
Play a bit now with the first window: nothing works any longer in that
window. This is what you're about, right?

But this is NOT a bug of the uicontrol mechanism.

If you change the above code into:

f=figure();
t = uicontrol(f, "Position" , [140 130 25 15],...
"Style" , "text",...
"String" , "50",...
"BackgroundColor",[1 1 1]);
s = uicontrol(f, "Position" , [10 130 120 15],..
"Style" , "slider",...
"Min" , 0,...
"Max" , 100,...
"Value" , 50,...
"SliderStep", [2 10],...
"callback" , "set("+string(t)+...
",''String'',string(get("+string(s)+",''Value'')))");
s = uicontrol(f, "Position" , [10 130 120 15],..
"Style" , "slider",...
"Min" , 0,...
"Max" , 100,...
"Value" , 50,...
"SliderStep", [2 10]);
// callback must be set after uicontrol return
// since the value of s is needed
set(s,"callback","set("+string(t)+...
",''String'',string(get("+string(s)+",''Value'')))");
b = uicontrol(f, "Position" , [50 170 70 20],...
"Style" , "pushbutton",...
"String" , "Disp value",...
"callback" , "disp(get("+string(s)+",''value''))");


then it works flawlessly in both figures (launch this twice (or more!)).

Do you see the difference between those two snippets?
Instead of sending s and t identifiers as strings in the callback string
(making then Scilab use its most recently known value at the execution
level), I now make the value substitution at the callback creation time.
This is the trick.

Finally an adivce for you: you certainly shouldn't rely on gcbo and related
obscure variables and stuff, this is undocumented AFAIK and is highly
subject to anything, especially in the c current context of the old graphics
removal in the trunk. Impossible to know what will remain after these
operations, but for sure I wouldn't rely on an undocumented feature in my
scripts.
Post by matt
I've read other threads and i've heard that scilab uicontrols and figure
are rather limited. One should use tcl instead. With a gui in pure tcl
could i resolve my problems?
Well... The uicontrol mechanism has been developped around 1998 I think and
has never been improved since then. And IMHO bug reports are highly unlikely
to be fixed in that area (nobody is excited about fixing those oldies, java
is so much more fun...).

If I were you, I would really do it directly in Tcl. There are a lot of very
good tutorials to start learning Tcl. And it's so easy to just TCL_EvalFile
from Scilab you file containing the GUI description. And in Tcl, use
ScilabEval for the callbacks to the Scilab engine. If you want an example,
here is something I wrote a long time ago and that could still work with
recent Scilab versions (I didn't check, though):

http://groups.google.com/group/comp.soft-sys.math.scilab/browse_frm/thread/b5489e23934ea57e/2ad4037306ad458b

Cheers,
Francois
matt
2007-03-18 09:22:37 UTC
Permalink
Post by François VOGEL
Instead of sending s and t identifiers as strings in the callback string
(making then Scilab use its most recently known value at the execution
level), I now make the value substitution at the callback creation time.
This is the trick.
Yes, It works! thanks a lot for your help :-)

Matteo
i***@pentax.org.pl
2018-04-12 16:21:20 UTC
Permalink
Hello,

I've got a similar problem but the solution from Francois VOGEL doesn't work on a newest version of Scilab. Also my code is a little different and I don't know how to adjust this solution to my situation. Here is the part of my code:

box_num_w=uicontrol(przel,"style","checkbox","backgroundcolor",..
[1 1 1],"value",1,"string","Numery węzłów","callback","niewidoczne_num_w");

function niewidoczne_num_w()
a=gca();
if get(gcbo,"value")==0 then
value=get(gcbo,"value")
a.children(7).visible="off";
else
a.children(7).visible="on";
end
endfunction

It turns on/off the visibility of some parts of the plot with the checkbox. The problem is the same as was written in the first post: everything works for one figure but when there are more figures the callback function works only on the current figure.

I would be grateful for any help,
Iza

Loading...