Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4050 > unrolled thread

Ruby Gtk2 and signal_connect method

Started bySilkmoth Silkmoth <phasme@gmx.fr>
First post2011-05-06 14:09 -0500
Last post2011-05-07 07:39 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.ruby


Contents

  Ruby Gtk2 and signal_connect method Silkmoth Silkmoth <phasme@gmx.fr> - 2011-05-06 14:09 -0500
    Re: Ruby Gtk2 and signal_connect method jake kaiden <jakekaiden@yahoo.com> - 2011-05-07 07:39 -0500

#4050 — Ruby Gtk2 and signal_connect method

FromSilkmoth Silkmoth <phasme@gmx.fr>
Date2011-05-06 14:09 -0500
SubjectRuby Gtk2 and signal_connect method
Message-ID<14fe31c992d1702a259c05ab9ba0b550@ruby-forum.com>
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

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#4064

Fromjake kaiden <jakekaiden@yahoo.com>
Date2011-05-07 07:39 -0500
Message-ID<2a021cce7c48eff89cbddcf07e321fbb@ruby-forum.com>
In reply to#4050
hi Silkmoth,

  i use gtk2 quite a bit, and have found that the "Gnome 2" section of
this forum (under "Misc" on the top right,) is extremely helpful - and
is probably a better place to post questions about gtk2.

  in answer to your question - you could try something like this, which
will give you the filename of the file within the event box you click
on.  i've used images in my example rather than icons, but you should
get the idea....

######
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
##############

  ...

  -j

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web