# Ruby gnome 2 and signal\_connect method

**URL:** <https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221>\
**Category:** Ruby-Gnome 2\
**Created:** [May 6, 2011, 9:12pm UTC](https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221 "2011-05-06T21:12:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![silkmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@silkmoth](https://www.ruby-forum.com/u/silkmoth)\
**Post date:** [May 6, 2011, 9:12pm UTC](https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221/1 "2011-05-06T21:12:11Z")

</div>

Hi,

I am writting a little script for displaying a list of icons and when i  
clic on one of the icon it should return the absolute path of the icon.

So i create a windows widget which contain a table widget. In each cell  
of the table I put an icon and create an event with this code:

#for a in 0…( @my\_icons\_files\_array.length - 1)

# my\_widget =Gtk::Image.new(@my\_icons\_files\_array[a])

# event\_box[a] = Gtk::EventBox.new.add(my\_widget)

# event\_box[a].signal\_connect(“button\_press\_event”) do

# …

# 

# end

# table.attach(event\_box[a],col\_begin,( col\_begin + 1 ), row\_begin,

(row\_begin + 1 ))  
#end

Is there a way to get a reference of the objet I have cliqued on in  
order to link this reference with the path used in Gtk::Image.new

Thanks

---

<div class="post-metadata">

**Author:** ![silkmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@silkmoth](https://www.ruby-forum.com/u/silkmoth)\
**Post date:** [May 7, 2011, 8:04pm UTC](https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221/2 "2011-05-07T20:04:09Z")

</div>

Hi jake,

Yes i found the Gnome 2 section but only after i have posted -\_-’.

Thanks a lot for your answers because it helps me a lot on a basic  
problem it seems.

This forum is very helpfull .

Bye

---

<div class="post-metadata">

**Author:** ![silkmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@silkmoth](https://www.ruby-forum.com/u/silkmoth)\
**Post date:** [May 7, 2011, 2:57pm UTC](https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221/3 "2011-05-07T14:57:08Z")

</div>

hi Silkmoth -

i answered you in the main ruby post, and suggested that you post here

- though i see you already found it! sorry 😉

############  
require ‘gtk2’

win = Gtk::Window.new()

@table = Gtk::Table.new(0, 0, false)  
@left = -1  
@top = 0

img0 = Gtk::Image.new(“konichiwa.jpeg”) #change these, obviously  
img1 = Gtk::Image.new(“ride.png”)  
img2 = Gtk::Image.new(“TradyBlix.png”)  
img3 = Gtk::Image.new(“arm.png”)

my\_imgs = [img0, img1, img2, img3]

my\_imgs.collect{|img|  
ebox = Gtk::EventBox.new()  
ebox.add(img)  
ebox.signal\_connect(“button\_press\_event”){p img.file} #or something  
more interesting  
@left = @left + 1  
@top = @top + 1 if @left == 2 #change this,  
@left = 0 if @left == 2 #and this, to define the number of columns in  
your table  
@right = @left + 1  
@bottom = @top + 1  
@table.resize(@right, @bottom)  
@table.attach\_defaults(ebox, @left, @right, @top, @bottom)  
}

win.add @table  
win.show\_all  
win.signal\_connect(“destroy”){Gtk.main\_quit}

Gtk.main  
###########

hope that helps…

- j

---

<div class="post-metadata">

**Author:** ![silkmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@silkmoth](https://www.ruby-forum.com/u/silkmoth)\
**Post date:** [May 7, 2011, 8:14pm UTC](https://www.ruby-forum.com/t/ruby-gnome-2-and-signal-connect-method/226221/4 "2011-05-07T20:14:48Z")

</div>

Silkmoth S. wrote in post #997243:

> Thanks a lot for your answers because it helps me a lot on a basic  
> problem it seems.

no problem, glad to help

> This forum is very helpfull .

it sure is!

- j
