Previous Next Contents

20  TCL/Tk interface

20.1   ScilabEval tcl instruction : Evaluate a string with scilab interpreter

Author: Bertrand Guiheneuf

This routine is used inside tcl/tk script executed from scilab. It allows to evaluate any string from the scilab interpreter. It's mainly used to execute callbacks from tk widgets.






USAGE :

ScilabEval str


INPUT PARAMETER :




OUTPUT PARAMETERS :

None


DESCRIPTION :

This function must be called in a tcl/tk script executed from scilab. It allows to associate scilab actions to tcl/tk widgets (graphic objects). The string str is put in the scilab interpreter buffer which then evaluates it. This has in general no border effect in the tcl/tk interpreter.


EXAMPLE (TCL/TK SCRIPT) :

# this text must be saved into a file, for instance 
#  TMPDIR+'/test.tcl'
# then launch scilab and type TK_EvalFile(TMPDIR+'/test.tcl');
toplevel .w1
button .w1.b -text "Click here to see a new Scilab Graphic Window"\
  -command {ScilabEval "xselect()"}
pack .w1.b 



SEE ALSO :

TK_EvalFile, TK_EvalStr, TK_GetVar, TK_Setvar



20.2   TK_EvalFile Reads and evaluate a tcl/tk file

Author: Bertrand Guiheneuf

With this routine, one can read and evaluate the content of a file containing tcl/tk scripts. This allows to create powerful tk interfaces.






USAGE :

TK_EvalFile(filename)


INPUT PARAMETER :




OUTPUT PARAMETERS :

None


DESCRIPTION :

The filename might be relative or absolute. It is absolute if begining with a leading slash (/). When relative, the specified path refers to the directory where scilab was launched.


ADVANTAGES AND DRAWBACKS OF THIS FUNCTIONALITY  :

This routines allows to use directly tcl/tk scripts. This thus allows, for instance to use Interface Builders such as SpecTcl to design the interface. The interfaces built directly with tcl/tk scripts are much faster than th ones built with the Scilab Graphic Object library provided with tksci (see uicontrol for example). Indeed, those Objects are warpings around tk graphic widgets. Nevertheless, this way of creating graphic user interface sould only be used when one aims at adressing directly specific tk/tcl features. There are two main reasons for this. First of all, there is no simple way to manipulate scilab objects from within a tcl/tk script. Thus, the interface designer has to write two sets of callbacks routines. One to describe the changes occuring in the interface when the user acts on the widgets. The second set of call routines will perform the (pure) scilab reactions to the user actions. Here is an example: Suppose you design a scrollbar corresponding to a spline tension value. You want the spline to be displayed in a graphic windows and updated each time the user moves the scrollbar. At the same time, you want the value of this tension parameter to be displayed within the Interface. You will have to write a first tcl/tk (callback) function which will be automatically called by the tk scrollbar ('-command' option). This callback function will update the displayed value of the parameter in the interface and will then call the scilab routine ('ScilabEval' command) to update the graph.


REMARKS ON THE TCL/TK SCRIPT STYLE :

Because Scilab manages the tcl/tk events, it creates the root window ".", this window should not be destroyed nor directly used by your tcl/tk scripts. You should thus always create your own toplevel windows. Moreover, since this module was written at a time when namespaces didn't exist, some variables defined by scilab tcl/tk scripts could bother your code. It is generaly a good idea to take a look to the tcl/tk scripts evaluated when scilab is lauched. They are located in the directory $(SCI)/routines/tksci/SCRIPTS.


SEE ALSO :

ScilabEval, TK_EvalStr, TK_GetVar, TK_Setvar



20.3   TK_EvalStr Evaluate a string whithin the tcl/tk interpreter

Author: Bertrand Guiheneuf

This routine allows to evaluate tcl/tk instructions with the tcl/tk interpreter launched with scilab.






USAGE :

TK_EvalStr(str)


INPUT PARAMETER :




OUTPUT PARAMETERS :

None


DESCRIPTION :

When tcl/tk support is enabled in scilab, you can evaluate tcl/tk expression from scilab interpreter. In fact, scilab launches a slave tcl/tk interpreter. The scilab instruction TK_EvalStr() can be used to evaluate expression without having to write a tcl/tk in a separated file (this is done using TK_EvalFile).


EXAMPLE :

TK_EvalStr('toplevel .foo');
// creates a toplevel TK window. 
TK_EvalStr('label .foo.l -text ""TK married Scilab !!!""');
// create a static label
TK_EvalStr('pack .foo.l');
// pack the label widget. It appears on the screen.
text='button .foo.b -text close -command {destroy .foo}';
TK_EvalStr(text);
TK_EvalStr('pack .foo.b');



SEE ALSO :

ScilabEval, TK_EvalFile, TK_GetVar, TK_Setvar



20.4   TK_GetVar Get a tcl/tk variable value

Author: Bertrand Guiheneuf

This routine allows to get a tcl/tk variable value.






USAGE :

valueTK_SetVar(varname)


INPUT PARAMETER :




OUTPUT PARAMETERS :




DESCRIPTION :

When tcl/tk support is enabled in scilab, this routine can be used to retreive the value of a tcl/tk variable.


EXAMPLE :

TK_EvalStr('toplevel .foo');
// creates a toplevel TK window. 
TK_EvalStr('entry .foo.e -textvariable tvar');
// create an editable entry
TK_EvalStr('set tvar foobar');
// set the entry value
TK_EvalStr('pack .foo.e');
// pack the entry widget. It appears on the screen.
text=TK_GetVar('tvar')
// retrieve the variable value
// change the entry text and repeat the last command ...



SEE ALSO :

ScilabEval, TK_EvalFile, TK_EvalStr, TK_SetVar



20.5   TK_SetVar Set a tcl/tk variable value

Author: Bertrand Guiheneuf

This routine allows to set a variable within the tcl/tk interpreter.






USAGE :

TK_SetVar(varname, value)


INPUT PARAMETER :




OUTPUT PARAMETERS :

None


DESCRIPTION :

When tcl/tk support is enabled in scilab, this routine can be used to set up the value of a tcl/tk variable. This can be useful to change some value in the tcl/tk without having to build a tcl/tk instruction (and use TK_EvalStr).


EXAMPLE :

TK_EvalStr('toplevel .foo'); // creates a toplevel TK window. TK_EvalStr('label .foo.l -textvariable tvar'); // create a static label TK_EvalStr('pack .foo.l'); // pack the label widget. It appears on the screen. TK_SetVar('tvar','This text has been set directly within scilab');


SEE ALSO :

ScilabEval, TK_EvalFile, TK_EvalStr, TK_GetVar



20.6   close close a figure

Author: Bertrand Guiheneuf

This routine allows to close a tksci figure (window).






USAGE :

close([h[)


INPUT PARAMETER :




OUTPUT PARAMETERS :

None


DESCRIPTION :

This routine close a tksci figure (toplevel window). If a handle is given, the figure corresponding to this handle is closed. Otherwise, the current (active) figure is closed.


EXAMPLE :

h=figure();
// creates  figure number 1.  
uicontrol( h, 'style','text', ...
 'string','scilab is great', ...
 'position',[50 70 100 100], ...
 'fontsize',15);
// put a clever text in figure 1
figure();
// create figure 2
uicontrol( 'style','text', ...
 'string','Really great', 'position',[50 70 100 100], 'fontsize',15);
// put a text in figure 2
close();
// close the current graphic window (ie fig. 2)
close(h);
// close figure 1



SEE ALSO :

figure, gcf



20.7   figure create a figure

Author: Bertrand Guiheneuf

This routine allows to create a tksci figure (window).






USAGE :

figure([h[, [prop1, value1 [ ...)


INPUT PARAMETER :




OUTPUT PARAMETERS :

handle of the newly created window


DESCRIPTION :

This routine creates a tksci figure (toplevel window). If a handle is given, the figure corresponding to this handle is created . Otherwise, the window is created with the first free handle, that is the lowest integer not already used by a window. The property named 'position' allows to control the geometrical aspect of the control. It is a [ 1,4] real vector x y w h where the letters stand for the x location of the left bottom corner, the y location of the left bottom corner, the width and the height of the uicontrol. One can also set this property by giving a string where the fields are separated by a '|', ie "x|y|w|h".


EXAMPLE :

h=figure(3);
// creates  figure number 1.
uicontrol( h, 'style','text', ...
 'string','This is a figure', ...
 'position',[50 70 100 100], ...
 'fontsize',15);
// put a  text in figure 3
figure();
// create figure 1
uicontrol( 'style','text', ...
 'string','Another figure', ...
 'position',[50 70 100 100], ...
 'fontsize',15);
// put a text in figure 1
close();
// close the current graphic window (ie fig. 1)
close(h);
// close figure 3



SEE ALSO :

close, gcf



20.8   findobj find an object with specified property

Author: Bertrand Guiheneuf

Allows to find a graphic tksci object testing the value of one of its properties.






USAGE :

h=findobj(prop,value)


INPUT PARAMETER :




OUTPUT PARAMETERS :

handle of the found object.


DESCRIPTION :

This routine is currentlyt used to find objects knowing their 'tag' property. It returns handle of the first found object which property 'prop' is equal to 'value'. If such an object does not exist, the function returns a void matrix.


EXAMPLE :

h=figure();
// creates  figure number 1.
uicontrol( h, 'style','text', ...
 'string','This is a figure', ...
 'position',[50 70 100 100], ...
 'fontsize',15, ...
 'tag','Alabel');
// put a  text in figure 1
lab=findobj('tag','Alabel');
// find the object which 'tag' value is 'Alabel'
disp('the handle of the label is '+string(lab));
close();



SEE ALSO :

uicontrol, uimenu, set, get



20.9   gcf gets the current figure

Author: Bertrand Guiheneuf

Retrieve the current active tksci figure (toplevel window).






USAGE :

h=gcf()


INPUT PARAMETER :

None


OUTPUT PARAMETERS :

handle of the current figure.


DESCRIPTION :

The current figure is the last created (and still existent) figure.


EXAMPLE :

figure(5);
figure();
figure();
gcf()
// returns 2
close(gcf());
// close figure 2
gcf()
// returns 1
close(1);
gcf()
// returns 5
close(5);



SEE ALSO :

figure, close



20.10   get get an UI object property value

Author: Bertrand Guiheneuf

Retrieve a property value from an User Interface object.






USAGE :

val=get(h,prop)


INPUT PARAMETERS :




OUTPUT PARAMETER :




DESCRIPTION :

This routine can be used to retrieve a specified property from a GUI object. Property name are character strings like 'style', 'position' .... This routine returns the value associated to the specified property. Obviously, the type of the returned object depends on the property one aims at querying. For example, the 'style' property which represents the kind of Object the UI control is (ie button, label, list, ..... ) will be represented as a string. On the contrary, the 'position' property, which represents the geometrical aspect of the UI control, will be coded as a [1,4] vector.


EXAMPLE :

h=uicontrol('string', 'Button');
// Opens a window with a  button.
p=get(h,'position');
// get the geometric qspect of the button
disp('Button width: ' + string(p(3)));
// print the width of the button
close();
// close figure



SEE ALSO :

uicontrol, uimenu, set



20.11   set set an UI object property value

Author: Bertrand Guiheneuf

set a property value of a User Interface object.






USAGE :

get(h,prop,val)


INPUT PARAMETERS :




OUTPUT PARAMETER :

None


DESCRIPTION :

This routine can be used to set a GUI object specified property. Property name are character strings like 'style', 'position' .... The type of the value field depends on the property one aims at setting. For example, the 'style' property which represents the kind of Object the UI control is (ie button, label, list, ..... ) will be represented as a string. On the contrary, the 'position' property, which represents the geometrical aspect of the UI control, will be coded as a [1,4] vector.


EXAMPLE :

h=uicontrol('string', 'Button');
// Opens a window with a  button.
set(h,'position',[ 50 50 100 100]);
// set the geometric aspect of the button
close();
// close figure



SEE ALSO :

uicontrol, uimenu, get



20.12   uicontrol create a Graphic User Interface object

Author: Bertrand Guiheneuf

This routine is the one which enventualy creates the Graphich User Interface Controls in the figures. This is a scingle instruction, but in conjonction with set(), it allows to create button, lists, ....






USAGE :

h=uicontrol([ prop1, val1 ] [, prop2, val2 ] ...) or h=uicontrol(f, [ prop1, val1 ] [, prop2, val2 ] ...)


INPUT PARAMETER :




OUTPUT PARAMETERS :

handle of the created object


DESCRIPTION :

this routine creates an object in a figure. If the handle of the figure is given (as the first parameter), the uicontrol is created in this figure. If no handle is given, the uicontrol is created in the current figure ( which may be obtained with a call to gcf() ). If there is no current figure, then one is created before the creation of the uicontrol. Then when the control is created, the properties given as parameters are set with the coresponding values. It is equivalent to create the uicontrol, and then set its properties with the set() command. Nevertheless, it generally more efficient to set the properties in the call to uicontrol(). This is particularly true coincerning the 'style' field. Indeed, the default value for this property is 'pushbutton'. So if you do not set it at creation time, a button will be created, and will be transformed to another uicontrol when you call the get(h,'style', ... ) instruction. Scilab and all the graphic objects communicate through the property mechanism. Thus, to create adapted uicontrol, one has to know the use of the property fields. Those are descibed under:


PROPERTIES :




BACKGROUNDCOLOR :

[ 1,3] real vector or string Background color of the uicontrol. A color is specified as Red, Green and Blue values. Those values are real in [ 0,1 ]. The color can be given as a real vector, ie [ R,G,B ] or a string where each value is separated by a |, ie "R|G|B"


CALLBACK :

string String evaluated by the scilab interpreter when an usicontrol is activated. (for example when you click on a button).


FONTANGLE :

string : {'normal'}| italic | oblique For a control containing some text, this property sets the slant of the font.


FONTSIZE :

real For a control containing some text, this property sets the size of the font in FontUnits.


FONTUNITS :

string : {points}| pixels | normalized For a control containing some text, this property sets the units with which the fontsize is specified.


FONTWEIGHT :

string : light | {normal}| demi | bold For a control containing some text, this property sets the weight of the used font


LISTBOXTOP :

integer For a ListBox, this property tells which item of the list appears on the first line of the visible area of the list.


MAX :

scalar Specifies the largest value the 'value' property can be set to. It has however differnet meaning on each uicontrol:


MAX :

scalar Specifies the lowest value the 'value' property can be set to. It has however differnet meaning on each uicontrol:


PARENT :

integer Handle of the control parent. Changing this property allows to move a control from a figure to another.


POSITION :

[ 1,4] real vector or string This property is used to set or get the geometrical configuration of a control. It is a real; vector : x y w h where the letters stand for the x location of the left bottom corner, the y location of the left bottom corner, the width and the height of the uicontrol. The unit is determined by the 'Unit' property. One can also set this property by giving a string where the fields are separated by a '|', ie "x|y|w|h".


SLIDERSTEP :

[ 1,2] real vector or string small big This property represents the step a slider is moved when the user click on the arrow (small step) or on the slide bar (big step).


STRING :

string Generally, this property represents the text appearing in a uicontrol. Its exact meaning sometimes depends on the uicontrol style:


STYLE :

string : {pushbutton}| radiobutton | checkbox | edit | text | slider | frame |listbox | popupmenu Style of the uicontrol. Here is a short description of each one:


TAG :

string this property is generally used to identify the control. It allows to give it a "name". Mainly used in conjontion with findobj().


UNITS :

string : {points}| pixels | normalized Set the units used to specify the 'position' property.


USERDATA :

scilab object this can be used to associate any scilab object to an uicontrol.


VALUE :

Value of the uicontrol. The eact meaning depends on the style of the uivontrol.


EXAMPLE :

f=figure();
// create a figure
h=uicontrol(f,'style','listbox', ...
 'position', [10 10 150 160]);
// create a listbox
set(h, 'string', "item 1|item 2|item3");
// fill the list
set(h, 'value', [1 3]);
// select item 1 and 3 in the list
close();
// close the figure
f=figure();
// create a figure
h=uicontrol(f,'style','listbox', ...
 'position', [10 10 150 160]);
// create a listbox
set(h, 'string', "item 1|item 2|item3");
// fill the list
set(h, 'value', [1 3]);
// select (highlight) the item 1 and 3 in the list
close();
//close the figure



SEE ALSO :

figure, set, get, uimenu



20.13   uimenu Create a menu or a submenu in a figure

Author: Bertrand Guiheneuf

This routine allows to add a menu or a submenu to the menu bar of a figure






USAGE :

h=uimenu(parent,prop1, val1, prop2, valu2 ...)


INPUT PARAMETER :




OUTPUT PARAMETERS :




DESCRIPTION :

This allows to create menus in a figure. If 'parent' is a figure, then the menu item will be added to the menu bar of the figure. If 'parent' is a menu item , then the new item will be added to the parent item, allowing to create cascaded submenu. The 'callback' property allows to set up the scilab instruction to call when the item is selected by the user. The 'label' property allows to set up the text appearing for the item.


EXAMPLE :

f=figure('position', [10 10 300 200]);
// create a figure
m=uimenu(f,'label', 'windows');
// create an item on the menu bar
m1=uimenu(m,'label', 'operations');
m2=uimenu(m,'label', 'quit scilab', 'callback', "exit");
//create two items in the menu "windows"
m11=uimenu(m1,'label', 'new window', 'callback',"xselect()");
m12=uimenu(m1,'label', 'clear  window', 'callback',"xbasc()");
// create a submenu to the item "operations"
close(f);
// close the figure



SEE ALSO :

figure, uicontrol, set, get


Previous Next Contents