Forum: Ruby ruby-gnome2: catching middle clicks on tabs

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.
Clayton Smith (Guest)
on 2005-12-12 11:34
(Received via mailing list)
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=sho...

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
Masao M. (Guest)
on 2005-12-12 15:44
(Received via mailing list)
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> 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!
Steve L. (Guest)
on 2005-12-12 17:54
(Received via mailing list)
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.
http://www.troubleshooters.com
removed_email_address@domain.invalid
Clayton Smith (Guest)
on 2005-12-12 19:09
(Received via mailing list)
ok, but when I do:
puts nb==widget.parent # true

....

Clayton
Clayton Smith (Guest)
on 2005-12-12 19:12
(Received via mailing list)
Masao M. (Guest)
on 2005-12-13 01:26
(Received via mailing list)
Hi,

On Tue, 13 Dec 2005 02:07:38 +0900
"Clayton Smith" <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%...

Gtk::Notebook#page_num(child)
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%...

Sorry for incomplete answer.
Clayton Smith (Guest)
on 2005-12-13 01:50
(Received via mailing list)
> Sorry for incomplete answer.
No need to be sorry.  I greatly appreciate the help.

Clayton
This topic is locked and can not be replied to.