Invoke a event in ruby/tk

here is the problem.

i have a TkEntry and A TkTable and i need to invoke the events of “Up”
and “Down” of the TkTable To change the selection of cell as well as if
it were selected. for reasons unnecessary to explain i need to hold the
focus in the Tkentry.Please write a suggestion on how to do this.

From: Jesus J. [email protected]
Subject: invoke a event in ruby/tk
Date: Wed, 3 Jun 2009 01:46:17 +0900
Message-ID: [email protected]

i have a TkEntry and A TkTable and i need to invoke the events of “Up”
and “Down” of the TkTable To change the selection of cell as well as if
it were selected. for reasons unnecessary to explain i need to hold the
focus in the Tkentry.Please write a suggestion on how to do this.

For example,

Hidetoshi NAGAI wrote:

From: Jesus J. [email protected]
Subject: invoke a event in ruby/tk
Date: Wed, 3 Jun 2009 01:46:17 +0900
Message-ID: [email protected]

i have a TkEntry and A TkTable and i need to invoke the events of “Up”
and “Down” of the TkTable To change the selection of cell as well as if
it were selected. for reasons unnecessary to explain i need to hold the
focus in the Tkentry.Please write a suggestion on how to do this.

For example,

require “tk”
require ‘tkextlib/tktable’
root=TkRoot.new
entry=TkEntry.new(root).place(:x=>0,:y=>0)
table=Tk::TkTable.new(root).place(:x=>0,:y=>40)
table[‘selecttype’]=‘row’
table.selection_set(‘0,0’)
entry.focus
#here is my doubt
#entry.bind(“Up”,proc{call Tktable.bind(“Up”)})???
#remember that we cant to lose the focus from the entry
#my intention is replic the event up and down when Tktable has the focus
#my first idea was invoke a default event. in this case ‘up’ ‘Down’
#i dont know if this is possble
#do you have a better idea?
Tk.mainloop

From: Jesus J. [email protected]
Subject: Re: invoke a event in ruby/tk
Date: Wed, 3 Jun 2009 14:00:35 +0900
Message-ID: [email protected]

#here is my doubt
#entry.bind(“Up”,proc{call Tktable.bind(“Up”)})???
#remember that we cant to lose the focus from the entry
#my intention is replic the event up and down when Tktable has the focus
#my first idea was invoke a default event. in this case ‘up’ ‘Down’
#i dont know if this is possble
#do you have a better idea?

I see.
Usually, when want to send event, use “event_generate” method.
But Key events have no effect without focus.
So, you will need a little tricky call.

For example,

require “tk”
require ‘tkextlib/tktable’
root=TkRoot.new
entry=TkEntry.new(root).place(:x=>0,:y=>0)
table=Tk::TkTable.new(root).place(:x=>0,:y=>40)
table[‘selecttype’]=‘row’
table.selection_set(‘0,0’)
entry.focus

table.activate(‘0,0’) # without ‘active’ element, Up/Down key may not
work
entry.bind(‘KeyPress-Up’){
table.focus # force mode “table.focus(true)” may be required
table.event_generate(‘KeyPress-Up’)
entry.focus # force mode “entry.focus(true)” may be required
}
entry.bind(‘KeyPress-Down’){
table.focus # force mode “table.focus(true)” may be required
table.event_generate(‘KeyPress-Down’)
entry.focus # force mode “entry.focus(true)” may be required
}

Tk.mainloop

If you use a TkVirtualEvent object,

require “tk”
require ‘tkextlib/tktable’
root=TkRoot.new
entry=TkEntry.new(root).place(:x=>0,:y=>0)
table=Tk::TkTable.new(root).place(:x=>0,:y=>40)
table[‘selecttype’]=‘row’
table.selection_set(‘0,0’)
entry.focus

virtual_event = TkVirtualEvent.new(‘KeyPress-Up’, ‘KeyPress-Down’)

table.activate(‘0,0’) # without ‘active’ element, Up/Down key may not
work
entry.bind(virtual_event, :keysym){|keysym|
table.focus # force mode “table.focus(true)” may be required
table.event_generate(keysym) #or table.event_generate(‘KeyPress-’ <<
keysym)
entry.focus # force mode “entry.focus(true)” may be required
}

Tk.mainloop

Thanks, is what I was expecting