# Ruby-gnome2: catching middle clicks on tabs

**URL:** <https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027>\
**Category:** Ruby\
**Created:** [December 12, 2005, 10:34am UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027 "2005-12-12T10:34:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 12, 2005, 10:34am UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/1 "2005-12-12T10:34:40Z")

</div>

What I am trying to do is capture the button-press-event when a person  
middle-clicks on a tab(similar to how Firefox tabs work). As I learned  
in #gtk+ using the EventBox should be able to do this  
After a quick scouting of the web for an example, I found this:  
[http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq17.003.htp](http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq17.003.htp)

## Unfortunately, I had problems with what I came up with. By using the following, when middle clicking on any of the tabs it finds the page\_num to be -1 …

#!/usr/local/bin/ruby --verbose  
require ‘gtk2’  
include Gtk  
init  
win = Window.new  
win.set\_default\_size 300, 300

hbox = HBox.new( false, 0)  
win.add(hbox)

nb = Notebook.new  
hbox.add(nb)

def add\_page nb  
vbox = VBox.new( false, 0)  
tab\_label\_box = EventBox.new  
label = Label.new(‘test’)  
tab\_label\_box.add(label)  
tab\_label\_box.show\_all  
tab\_label\_box.signal\_connect(‘button-press-event’) do |widget,  
event|  
if event.event\_type==Gdk::Event::BUTTON\_PRESS and  
event.button==2  
puts nb.page\_num(widget) # ← not recognizing as a child ?  
end  
end  
nb.append\_page( vbox, tab\_label\_box)  
end

add\_page nb  
add\_page nb  
add\_page nb

win.show\_all  
main

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 12, 2005, 2:44pm UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/2 "2005-12-12T14:44:45Z")

</div>

Hi,

“tab\_label” is not “child” of Gtk::Notebook.  
Try code below.

HTH.

On Mon, 12 Dec 2005 18:32:38 +0900  
“Clayton Smith” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> tab_label_box.add(label)
> tab_label_box.show_all
> tab_label_box.signal_connect('button-press-event') do |widget,
> 
> ```
> 
> event|  
> if event.event\_type==Gdk::Event::BUTTON\_PRESS and  
> event.button==2  
> puts nb.page\_num(widget) # ← not recognizing as a child ?

```
         puts nb.page_num(vbox) # FIXED!

```

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 12, 2005, 4:54pm UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/3 "2005-12-12T16:54:41Z")

</div>

On Monday 12 December 2005 08:42 am, Masao M. wrote:

> > #!/usr/local/bin/ruby --verbose  
> > require ‘gtk2’

Where does one get the gtk2 module?

SteveT

Steve L.

> **[Troubleshooters.Com](http://www.troubleshooters.com)**
>
> The process and mindset of troubleshooting.

removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 12, 2005, 6:09pm UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/4 "2005-12-12T18:09:54Z")

</div>

ok, but when I do:  
puts nb==widget.parent # true

…

Clayton

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 12, 2005, 6:12pm UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/5 "2005-12-12T18:12:55Z")

</div>

> **[The source of https://ruby-gnome.github.io/](https://ruby-gnome.github.io/)**
>
> The source of https://ruby-gnome.github.io/

Clayton

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 13, 2005, 12:26am UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/6 "2005-12-13T00:26:20Z")

</div>

Hi,

On Tue, 13 Dec 2005 02:07:38 +0900  
“Clayton Smith” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ok, but when I do:  
> puts nb==widget.parent # true

Strictly speaking, both of vbox and tab\_label\_box are  
children of nb.

I meant vbox is the “child” in the API reference.

Gtk::Notebook#append\_page(child, tab\_label = nil)  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ANotebook#append\_page](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ANotebook#append_page)

Gtk::Notebook#page\_num(child)  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ANotebook#page\_num](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ANotebook#page_num)

Sorry for incomplete answer.

---

<div class="post-metadata">

**Author:** ![Clayton\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Clayton\_Smith](https://www.ruby-forum.com/u/Clayton_Smith)\
**Post date:** [December 13, 2005, 12:50am UTC](https://www.ruby-forum.com/t/ruby-gnome2-catching-middle-clicks-on-tabs/50027/7 "2005-12-13T00:50:29Z")

</div>

> Sorry for incomplete answer.  
> No need to be sorry. I greatly appreciate the help.

Clayton
