Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

keyboard hotkeying to uicontrol buttons?

263 views
Skip to first unread message

coolsti

unread,
Aug 1, 2006, 3:06:54 AM8/1/06
to
Hi,

I created a scilab application for my work, with a GUI where by clicking
on buttons, things happen. Now my colleagues would like to substitute a
key click for a mouse click, which would ease things since there is a lot
of repetitive clicking in this application. For example, I would like to
bind one key to one button, and another key to another button, so that
when the user hits that key, the respective button is activated.

Is this even possible when using uicontrols?

Many thanks!

Steve,
Denmark

François Coulombeau

unread,
Aug 1, 2006, 4:02:48 AM8/1/06
to
Hi,

See the function 'seteventhandler'.

Best regards,
François

coolsti

unread,
Aug 2, 2006, 1:57:17 AM8/2/06
to

Hi Francois,

thanks for your reply. I took a look at seteventhandler, and it seems like
this might work for me, with the exception that I don't know if it could
be implemented for a "window" that I create through the uicontrols. The
user interface has been created completly with uicontrols, and the
"window" has been created with the figure() function. According to Scilab
help, the function that is passed to seteventhandler must have as its
first argument the number of the window where the event has occurred.

It sounds to me as if seteventhandler is meant to work with graphical
windows. Can this also work with windows created with the function
figure()?

Regards,
Steve,Denmark

François Coulombeau

unread,
Aug 2, 2006, 5:56:30 AM8/2/06
to
Hi Steve,

You're right, the seteventhandler function does only work for graphic
windows. I'm not sure how to do the same for figures... Sorry, but I'll
let you if I find a way of doing what you want.

Enrico Segre

unread,
Aug 8, 2006, 7:51:16 AM8/8/06
to

Well, it occurs me that it should be easy, sending the proper
TCL_EvalStr("bind ....") commands. I'd have to dig into the scilab -
tcl stuff to find out what is the tk name that each uicontrol object
gets.
For the Tcl part see:

http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm

Enrico

Enrico Segre

unread,
Aug 8, 2006, 9:52:17 AM8/8/06
to
On Tue, 2006-08-08 at 14:51 +0300, Enrico Segre wrote:

> Well, it occurs me that it should be easy, sending the proper
> TCL_EvalStr("bind ....") commands. I'd have to dig into the scilab -
> tcl stuff to find out what is the tk name that each uicontrol object
> gets.

ok: so the window created by figure(N) is called .objfigureN

Here is how you retrieve in scilab the names of the objects you have
drawn in figure(n):


TCL_EvalStr("set widg_list [place slaves .objfigure"+string(n)+"]");
TCL_GetVar("widg_list")

There might be a rule for generating these names, probably they just get
progressive numbers, as handles do, which depends on the session
history. The best is to monitor the widget list every time a new item is
added.

So for instance

n=3; figure(n)
myFig=".objfigure"+string(n)
uicontrol(n,"style","checkbox","position",[100 100 20 20])
TCL_EvalStr("set widg_list [place slaves "+myFig+"]");
myBut=TCL_GetVar("widg_list")

and finally

TCL_EvalStr("bind "+myFig+" <a> {focus "+myBut+"; "+myBut+" toggle}")

allows you to toggle the checkbox with the key "a".

Enjoy.

Enrico Segre

unread,
Aug 8, 2006, 9:58:39 AM8/8/06
to
On Tue, 2006-08-08 at 16:52 +0300, Enrico Segre wrote:
> TCL_EvalStr("bind "+myFig+" <a> {focus "+myBut+"; "+myBut+" toggle}")

I meant

TCL_EvalStr("bind "+myFig+" <a> {"+myBut+" toggle}")

which is enough as long as .objfigureN is focused. What I proposed above
doesn't itself help, though of course some more sophisticate binding
could be generated in order to bring additionally the focus to that
particular objfigure.

coolsti

unread,
Aug 11, 2006, 4:22:33 AM8/11/06
to

Hi and thanks!

I will definitely give it a try, Enrico, when I find the time. I much
appreciate your efforts in finding a solution.

I will repost when I do try it if it works for me.

Steve, Denmark

Francois Vogel

unread,
Aug 11, 2006, 1:47:51 PM8/11/06
to
> I will definitely give it a try, Enrico, when I find the time. I much
> appreciate your efforts in finding a solution.

I think you should consider this only as a hack, since the names of the
widgets generated by uicontrol is not part of the public interface. In
other words it is subject to change without notice.

I think I remember reading somewhere that uicontrols would be rewritten
one day or another (not sure, though). This code is very old and is
affected by quite a number of bugs, see:
http://scilabsoft.inria.fr/cgi-bin/bugzilla_bug_II/buglist.cgi?query_format=specific&op_sys=All+OS&op_sys=All+Windows&op_sys=Windows+9x+only&op_sys=Windows+2000+and+more&op_sys=All+Linux&op_sys=All+others&short_desc_type=allwordssubstr&short_desc=uicontrol&long_desc_type=substring&long_desc=&changedin=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time

Francois

coolsti

unread,
Aug 27, 2006, 2:59:51 AM8/27/06
to

Ok, its been a few weeks, and I finally tried Enrico's example, and that
works fine. If I create a figure in the manner I usually do, where the
handle is the return value, e.g. n = figure(<my other arguments here>)
then the example above with one push button works. When the figure has the
focus, the push button toggles with the letter a.

However, since I don't know much of TCL yet, I can't figure out how to
extend this example to the case where there are several buttons in the
figure, and I want to bind one key to one button, and a different key to
another button. Can anyone same me heaps of time by giving a brief example
of this? In other words, let us say I create a figure with scilab handle
or number n, and then I create three buttons, where maybe for the sake of
the example I give them a "tag" property of respectively A, B and C, how
could I bind the letter a to A, b to B and c to C?

Regards,
Steve, Denmark

Enrico Segre

unread,
Aug 28, 2006, 6:59:54 AM8/28/06
to
n=1; figure(n)
myFig=".objfigure"+string(n) //just to have the name ".objfgureN"

//create checkbuttons with bound keys: just iterate the following
lines

// create the uicontrol
uicontrol(n,"style","checkbox","position",[100 50 20 20],"tag","A")
// find the Tk name given to it (there must be a trivial rule, but a
posteriori)
// find all the uicontrol names as a tcl list


TCL_EvalStr("set widg_list [place slaves "+myFig+"]");

// the newly created one is the first one of the list
myButtons=tokens(TCL_GetVar("widg_list"))
LastButton=myButtons(1);
// now bind a keypress (or any other X event) to it
TCL_EvalStr("bind "+myFig+" <a> {"+LastButton+" toggle}")
// if you had another type of uicontrol, you would rather bind a
command
// different than {toggle}. I'd have to look up the tcl man and check.

// now just repeat again:

uicontrol(n,"style","checkbox","position",[100 100 20 20],"tag","B")


TCL_EvalStr("set widg_list [place slaves "+myFig+"]");

myButtons=tokens(TCL_GetVar("widg_list"))
LastButton=myButtons(1);
TCL_EvalStr("bind "+myFig+" <b> {"+LastButton+" toggle}")

uicontrol(n,"style","checkbox","position",[100 150 20 20],"tag","C")


TCL_EvalStr("set widg_list [place slaves "+myFig+"]");

myButtons=tokens(TCL_GetVar("widg_list"))
LastButton=myButtons(1);
TCL_EvalStr("bind "+myFig+" <c> {"+LastButton+" toggle}")

coolsti

unread,
Aug 29, 2006, 2:14:24 AM8/29/06
to
On Mon, 28 Aug 2006 03:59:54 -0700, Enrico Segre wrote:

...... post shortened, see previous post ......

> uicontrol(n,"style","checkbox","position",[100 150 20 20],"tag","C")
> TCL_EvalStr("set widg_list [place slaves "+myFig+"]");
> myButtons=tokens(TCL_GetVar("widg_list"))
> LastButton=myButtons(1);
> TCL_EvalStr("bind "+myFig+" <c> {"+LastButton+" toggle}")

Thank you Enrico! Just read your new post, and I will try to find time to
try it soon! I will report back on this thread if I have success!

Much appreciate your help and your taking the time to help!

Steve, Denmark

coolsti

unread,
Aug 29, 2006, 6:41:50 AM8/29/06
to

Whooptee! Got it!

Decided to give a Google and TCL manual search one more shot, and it seems
like the keywork "invoke" is what I was looking for. I think I can
successfully bind my buttons now to keyboard shortcuts! When the Figure
window has focus, that is.

Thanks Enrico!

Steve, Denmark

coolsti

unread,
Aug 29, 2006, 6:21:00 AM8/29/06
to
On Tue, 29 Aug 2006 08:14:24 +0200, coolsti wrote:


Nope, I am unfortunately still lost. I just tried the example Enrico gave,
and it works fine for checkboxes. But for the life of me, I cannot guess
the correct binding keyword to use for a pushbutton instead of "toggle". I
have tried "click" and "push" but those don't work. I also have spent some
time with Google searching, but apparently the answer to this question
requires some more involvement in TCL programming than I have time for at
the moment. At least the answer doesn't reveal itself easilly with a
Google search.

Does anyone by any chance know what the binding keyword is for a
pushbutton?

Much thanks in advance,
Steve, Denmark

Enrico Segre

unread,
Aug 29, 2006, 9:42:58 AM8/29/06
to
from http://www.tcl.tk/man/tcl8.4/TkCmd/button.htm I desume that for
tcl buttons (what scilab "pusbutton"s are mapped to), valid invocations
are

pathName flash # which gives just a visual effect, and
pathName invoke # which executes the command associated to the
button (in scilab terms, the scilab instructons of the "callback"
field.

You might therefore want, paraphrasing my previous example, something
like

uicontrol(n,"style","pushbutton","position",[100 100 20
20],"tag","B",...
"callback","clf()\\;plot2d(rand(1,100))")


TCL_EvalStr("set widg_list [place slaves "+myFig+"]");
myButtons=tokens(TCL_GetVar("widg_list"))
LastButton=myButtons(1);

TCL_EvalStr("bind "+myFig+" <b> {"+LastButton+" flash;"+LastButton+"
invoke}")

since we're mentioning callbacks, please be aware of some potential
oddities with that -- as the tcl-scilab interface is imperfect and the
callback string is not passed literally as it should, you might have to
escape funnily some tcl sensible characters, such as [], {}, ";",
spaces and quotes, with multiple \ (which is the tcl escape). I
remember having seen and reported problems in this area, perhaps a look
in the newsgroup and in the bugzilla with search terms like
"uicontrol", "callback", etc. would give some word of wisdom.

hth, Enrico

coolsti

unread,
Aug 30, 2006, 1:55:22 AM8/30/06
to

Hi Enrico,

hope you didn't go through so much trouble with the last, as I soon found
out about "invoke" (and posted about it) after the post you replied to.

I haven't tried with any other keys than simple letters, but I will keep
your comment about multiple \ in mind. I am used to this from PHP where
you need to use four \\\\ in an ereg expression to denote only one \, so
there is definitely a double interpretation (and hence a need for a double
escaping) here as well.

Steve, Denmark

0 new messages