‏הצגת רשומות עם תוויות Gtk. הצג את כל הרשומות
‏הצגת רשומות עם תוויות Gtk. הצג את כל הרשומות

יום ראשון, 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/

יום ראשון, 12 במאי 2013

Displaying a window using ruby and gtk

require 'gtk'

window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)

pressmebtn = Gtk::Button.new("Press me please!!")

window.set_title("Displaying a window using ruby and gtk on linux")

window.border_width(5)

# Connect the signals 'destroy_event'
window.signal_connect('destroy') {
puts "destroy event received"
Gtk.main_quit
}

# Connect the button to a callback.
pressmebtn.signal_connect('clicked') { puts "pressmebtn was clicked" }

# Connect the signals 'delete_event'
window.signal_connect('delete_event') {
puts "delete_event received"
false
}

window.add button
window.show_all
Gtk.main