[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

more ruby/tk questions

Ferenc Engard

10/23/2003 3:00:00 PM

Hello,

I am getting more into the GUI.

I have a form where I enter some values into entries, and when pushing
the Ok button I process them.

I put validatecommands on the entries where I need some checks about
their value, so they are validated when focus goes away from them, and
if the value is invalid, I put the focus to the entry again.

The first problem was that when I push a button it do not take focus, so
the last entry was not validated. I solved this by putting a
@btnOk.focus as the first row of the Ok button's callback.

The next problem is, that the entry's focusout validate callback handler
do not execute while I am in the callback of the OK button, i.e., after
the @btnOk.focus cmd the focus is on the button, and the entry's
validate proc (which would take away focus from the button) runs only
after I return from this proc.

So, this do not work in the button proc:

def btnOkHandler
@btnOk.focus
if Tk.focus != @btnOk
# the entry forcibly holds the focus because of error
return
end
# ... process data
end

What can I do instead? I have to call the validating proc directly? It
is not pretty, and even it is complicated to figure out what is it in my
program...

Thanks:
Ferenc
1 Answer

Ferenc Engard

10/24/2003 9:06:00 PM

0

> The next problem is, that the entry's focusout validate callback handler
> do not execute while I am in the callback of the OK button, i.e., after
> the @btnOk.focus cmd the focus is on the button, and the entry's
> validate proc (which would take away focus from the button) runs only
> after I return from this proc.
>
> So, this do not work in the button proc:
>
> def btnOkHandler
> @btnOk.focus
> if Tk.focus != @btnOk
> # the entry forcibly holds the focus because of error
> return
> end
> # ... process data
> end

Answer to myself:

def actOk(afterFocus=false)
if !afterFocus
@btnOk.focus
TkAfter.new().start('idle',proc {actOk(true)})
return
end
return if Tk.focus != @btnOk
...

Where actOk() is called without arguments from @btnOk's callback.

Ferenc