Forum: Ruby invoke a event in ruby/tk

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3759a90eac7bca9706dc1367b619f70e?d=identicon&s=25 Jesus Jesus (omaha)
on 2009-06-02 18:46
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.
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2009-06-03 06:11
(Received via mailing list)
From: Jesus Jesus <jesussalas187@hotmail.com>
Subject: invoke a event in ruby/tk
Date: Wed, 3 Jun 2009 01:46:17 +0900
Message-ID: <d7c15957a28cb1ffe1643309649ae705@ruby-forum.com>
> 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,
3759a90eac7bca9706dc1367b619f70e?d=identicon&s=25 Jesus Jesus (omaha)
on 2009-06-03 07:00
Hidetoshi NAGAI wrote:
> From: Jesus Jesus <jesussalas187@hotmail.com>
> Subject: invoke a event in ruby/tk
> Date: Wed, 3 Jun 2009 01:46:17 +0900
> Message-ID: <d7c15957a28cb1ffe1643309649ae705@ruby-forum.com>
>> 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
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2009-06-03 10:11
(Received via mailing list)
From: Jesus Jesus <jesussalas187@hotmail.com>
Subject: Re: invoke a event in ruby/tk
Date: Wed, 3 Jun 2009 14:00:35 +0900
Message-ID: <ae9487e505cd5fc4e0af26c5f1ef5a65@ruby-forum.com>
> #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
3759a90eac7bca9706dc1367b619f70e?d=identicon&s=25 Jesus Jesus (omaha)
on 2009-06-04 02:46

Thanks, is what I was expecting
This topic is locked and can not be replied to.