# Double-click in Gtk::Entry

**URL:** <https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077>\
**Category:** Ruby-Gnome 2\
**Created:** [March 20, 2012, 2:55pm UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077 "2012-03-20T14:55:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 20, 2012, 2:55pm UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077/1 "2012-03-20T14:55:56Z")

</div>

The following Gtk::Entry never gets Gdk::Event::BUTTON2\_PRESS:

class A \< Gtk::Entry  
def initialize  
super  
add\_events Gdk::Event::BUTTON\_PRESS\_MASK  
signal\_connect ‘button\_press\_event’ do |widget, event|  
select\_range 0, -1 if event.event\_type ==  
Gdk::Event::BUTTON2\_PRESS and event.button == 1  
false  
end  
end  
end

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [March 20, 2012, 7:17pm UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077/2 "2012-03-20T19:17:30Z")

</div>

Le 20 mars 2012 14:54, Nikolai W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a crit :

> end
> 
> * * *
> 
> ruby-gnome2-devel-en mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

Hi

I tried

signal\_connect ‘button\_press\_event’ do |widget, event|  
p “ok” if Gdk::Event::Type::BUTTON2\_PRESS==event.event\_type  
false  
end

and it works.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [March 21, 2012, 10:41am UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077/3 "2012-03-21T10:41:53Z")

</div>

On Tue, Mar 20, 2012 at 14:54, Nikolai W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> end  
> end
> 
> What am I doing wrong?

Here’s a complete example:

require ‘gtk2’

e = Gtk::Entry.new  
e.signal\_connect ‘button\_press\_event’ do |widget, event|  
p event.event\_type  
e.select\_range 0, -1 if  
event.event\_type == Gdk::Event::BUTTON2\_PRESS and  
event.button == 1  
end  
d = Gtk::Dialog.new  
d.vbox.add e  
d.show\_all  
Gtk.main

All I seem to get is two instances of #\<Gdk::Event::Type  
button-press\>. This is on Windows, by the way, but that shouldn’t be  
relevant.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [March 21, 2012, 5:59pm UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077/4 "2012-03-21T17:59:15Z")

</div>

On Wed, Mar 21, 2012 at 11:08, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Your example works for me as soon as I change “select\_range” to  
> “select\_region”. When I double click, I see:
> 
> #\<Gdk::Event::Type button-press\>  
> #\<Gdk::Event::Type button-press\>  
> #\<Gdk::Event::Type 2button-press\>

I guess there’s a bug in Gdk for Windows in the version I’m running,  
then.

That’s a bummer.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [March 21, 2012, 11:09am UTC](https://www.ruby-forum.com/t/double-click-in-gtk-entry/218077/5 "2012-03-21T11:09:16Z")

</div>

Your example works for me as soon as I change “select\_range” to  
“select\_region”. When I double click, I see:

#\<Gdk::Event::Type button-press\>  
#\<Gdk::Event::Type button-press\>  
#\<Gdk::Event::Type 2button-press\>

From: Nikolai W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: Ruby-GNOME2 Developers  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Date: 03/21/2012 05:41 AM  
Subject: Re: [ruby-gnome2-devel-en] Double-click in Gtk::Entry

On Tue, Mar 20, 2012 at 14:54, Nikolai W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> end  
> end
> 
> What am I doing wrong?

Here’s a complete example:

require ‘gtk2’

e = Gtk::Entry.new  
e.signal\_connect ‘button\_press\_event’ do |widget, event|  
p event.event\_type  
e.select\_range 0, -1 if  
event.event\_type == Gdk::Event::BUTTON2\_PRESS and  
event.button == 1  
end  
d = Gtk::Dialog.new  
d.vbox.add e  
d.show\_all  
Gtk.main

All I seem to get is two instances of #\<Gdk::Event::Type  
button-press\>. This is on Windows, by the way, but that shouldn’t be  
relevant.
