more ruby/tk questions

F

Ferenc Engard

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
 
F

Ferenc Engard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,804
Members
47,349
Latest member
jojonoy597

Latest Threads

Top