Focus problems...

From: Harvey J. Stein <abel_at_netvision.net.il>
Date: Wed, 16 Oct 1996 21:14:34 +0200

I'm having trouble controlling the focus. Maybe someone could help
me.

The following code illustrates the problem.

First, I make two entry widgets and a button, and pack the button
between the entry widgets:

(require "Tk-classes")
(define e1 (make <Entry> ))
(define e2 (make <Entry> ))
(define b (make <button>))
(pack e1 b e2)

 I find the tabbing a little weird in this situation. Even though the
button is visually between e1 & e2, the focus moves from e1 to e2 to b
& back to e1 when tabbing.

I presume this is because the tk:focus-next gets it's order from some
list of subwidgets of the frame, and this list is basically in the
order that the widgets were created.

So, first question. Is there any way to easily change this?

Now, I try to set things up so that when I tab in one entry, the focus
moves to the other entry, and the focus never moves to the button:

(bind e1 "<Key-Tab>" (lambda () (focus e2)))
(bind e2 "<Key-Tab>" (lambda () (focus e1)))

Now for the first problem. After doing the above bindings, I would
think that if I'm in 1 entry widget and I hit <tab>, I'd end up in the
other entry widget. But, this doesn't happen! Instead, the focus
still insists on going from the 2nd entry widget to the button!

Figuring there must be some other binding involved, I looked at
the binding tag list for e2, and got:

STk> (bindtags e2)
(#[Tk-command .v2] "Entry" #[Tk-command .] "all")

Checking the binding for key-tab in each of these, I saw:

STk> (bind "Entry" "<Key-Tab>")
(#[closure 80d81bc])
STk> (procedure-body (car (bind "Entry" "<Key-Tab>")))
(lambda () (#quote ()))
STk> (bind *root* "<Key-Tab>")
()
STk> (bind *root*)
()
STk> (bind "all" "<Key-Tab>")
(#[closure 80d06f8] |W|)
STk> (procedure-body (car (bind "all" "<Key-Tab>")))
(lambda (|W|) (focus (tk:focus-next |W|)))
STk>

This makes it looks like the problem might be that after my binding on
e2, the "all" binding for <key-tab> is getting run, which then flips
the focus to the button.

So, I wiped out the binding for <key-tab> on all:

STk> (bind "all" "<Key-Tab>" "")
()

Then I verified that it was gone:

STk> (bind "all" "<Key-Tab>")
()

Then I hit tab in the STk window, and the binding for <Key-Tab> on
"all" magically reappears:

STk> (bind "all" "<Key-Tab>")
(#[closure 8175d38] |W|)
STk> (procedure-body (car (bind "all" "<Key-Tab>")))
(lambda (|W|) (focus (tk:focus-next |W|)))

So my second question is, why in the world does this happen?!?!?
Also, how can I get the thing to tab from one entry to the other, and
never to the button? I suppose I could redefine tk:focus-next, but
I'd rather not override library functions...

Now for the second problem. When I'm holding down the tab key (so as
to rapidly move the focus from widget to widget due to a fast
autorepeat), and I also move around the mouse inside the STk window, I
start getting errors such as:

*** Background error:
eval: bad function in : (#[unknown 19 80c2e98] .v1)
**** Tk error ("") "\n (command bound to event)"

Each time, the number after "unknown 19" changes. Sometimes it even
happens without moving the mouse. However, I notice pauses in moving
of the focus. Could it be that gc is interrupting event processing
poorly, or that the event stream is interrupting gc, thus causing the
error?

Anyone have any ideas?

Thanks,

Dr. Harvey J. Stein
Berger Financial Research
abel_at_netvision.net.il
Received on Wed Oct 16 1996 - 21:26:12 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST