Forum: Ruby-Gnome 2 Ruby gnome 2 and signal_connect method

51358341da0e605dc7ee46210a7e2eeb?d=identicon&s=25 Silkmoth Silkmoth (silkmoth)
on 2011-05-06 21:12
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
5e3ddca8ea910cea06245c7b3c38007a?d=identicon&s=25 jake kaiden (lljk)
on 2011-05-07 14:57
hi Silkmoth -

  i answered you in the main ruby post, and suggested that you post here
- though i see you already found it!  sorry ;)

  once again, here's what i came up with:

############
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
51358341da0e605dc7ee46210a7e2eeb?d=identicon&s=25 Silkmoth Silkmoth (silkmoth)
on 2011-05-07 20:04
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
5e3ddca8ea910cea06245c7b3c38007a?d=identicon&s=25 jake kaiden (lljk)
on 2011-05-07 20:14
Silkmoth Silkmoth 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.