ruby-****@sourc*****
ruby-****@sourc*****
2003年 9月 11日 (木) 01:18:29 JST
------------------------- REMOTE_ADDR = 218.231.205.39 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/?tips_toolbar_icon ------------------------- - = Change an icon on a button of a toolbar + = Changes an icon on a button of a toolbar Gtk::Toolbar and also a lot of widgets is a subclass of Gtk::Container or Gtk::Bin. They have child widgets and you can get each child widgets and send methods to the child widgets. Here is a sample script. require 'gtk2' Gtk.init toolbar = Gtk::Toolbar.new toolbar.append(Gtk::Stock::NEW) do toolbar.children[0].child.children[0].set(Gtk::Stock::QUIT, Gtk::IconSize::SMALL_TOOLBAR) #(1) end Gtk::Window.new.add(toolbar).show_all Gtk.main Click button, then icon will be changed. a line of (1) can also write like as follows: #Of course, you can use both way as you like. button = toolbar.children[0] vbox = button.child image = vbox.children[0] image.set(Gtk::Stock::QUIT, Gtk::IconSize::SMALL_TOOLBAR) And follow image shows these objects relationship. ((<Containers|URL:/ja/hiki.cgi?c=plugin;plugin=attach_download;p=tips_toolbar;file_name=containers.jpg>)) {{br}} (1) Gtk::Toolbar is a subclass of Gtk::Container. So you can get all child widgets by Gtk::Container#children. Then, the first child is the target object(Gtk::Button). So you get here by toolbar.children[0]. (2) Gtk::Button is a subclass of Gtk::Bin, so it has a child only. You can get the child widget by Gtk::Bin#child. In this case, the child widget is Gtk::VBox. (3) Gtk::VBox is a subclass of Gtk::Container, too. So you get Gtk::Image by vbox.children[0]. (4) Use Gtk::Image#set to change the icon. - - ((<Masao>)) + == ChangeLog + :2003-09-11 ((<Masao>)) + Initial release.