יום ראשון, 2 ביוני 2013

Custom button in gtk

A simple GTK program that demonstrate the constructing of custom button.

  1: require 'gtk'
  2: require 'gdk_pixbuf'
  3: 
  4: #Returns image from image file 
  5: def load_image_from_file(file_path)
  6:     
  7:   pixbuf = Gdk::Pixbuf.new file_path
  8:     
  9:   pixmap, mask = pixbuf.render_pixmap_and_mask
 10:     
 11:   image  = Gtk::Pixmap.new(pixmap, mask)
 12: end
 13: 
 14: window = Gtk::Window.new Gtk::WINDOW_TOPLEVEL
 15: 
 16: window.signal_connect('delete_event') { Gtk.main_quit }
 17: 
 18: window.border_width 20
 19: 
 20: window.set_title "Custom button"
 21: 
 22: button = Gtk::Button.new
 23: 
 24: vbox = Gtk::VBox.new
 25: 
 26: button.add vbox
 27: 
 28: label = Gtk::Label.new "Press the Lion bellow"
 29: 
 30: vbox.pack_start label
 31: 
 32: image = load_image "Lion.png"
 33: 
 34: vbox.pack_start image
 35: 
 36: window.add button
 37: 
 38: window.show_all
 39: 
 40: Gtk.main

Sources:
http://ruby-gnome.sourceforge.net/tutorial/c429.html
http://zetcode.com/tutorials/gtktutorial/gtkevents/

אין תגובות:

הוסף רשומת תגובה