[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

invoke a event in ruby/tk

Jesus Jesus

6/2/2009 4:46:00 PM

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.
--
Posted via http://www.ruby-....

4 Answers

Hidetoshi NAGAI

6/3/2009 4:11:00 AM

0

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,
-----------------------------------------------------------
table.takefocus false
table.bind('FocusIn'){entry.focus}
-----------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Jesus Jesus

6/3/2009 5:01:00 AM

0

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

--
Posted via http://www.ruby-....

Hidetoshi NAGAI

6/3/2009 8:11:00 AM

0

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
----------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Jesus Jesus

6/4/2009 12:46:00 AM

0



Thanks, is what I was expecting
--
Posted via http://www.ruby-....