#!/usr/local/bin/ruby # # Demoscript with Ruby and GTK-server 1.3 using STDIN # The STDIN interface is preferred with the GTK-server # # Tested with "Ruby 1.8.2 (2004-12-25) [i686-linux]" # on Slakcware Linux 10.0 # # Feb 28, 2005 - PvE. # # Based on the Ruby TCP demo by Mark Janssen #---------------------------------------------------- # Define complete GTK module module GTK # Start GTK-server with STDIN interface def startup $pipe = IO.popen("gtk-server -stdin", "r+") end # Commands to shutdown GTK-server and pipe def shutdown gtk("gtk_server_exit") $pipe.close end # Communication function def gtk(str) $pipe.puts(str + "\n") $pipe.gets end # Mainloop def mainloop event = 0 while (event != $win and event != $but) event = gtk("gtk_server_callback wait") end end # Building the GTK application class Application @title = nil @handle = nil def initialize gtk("gtk_init NULL NULL") $win = gtk("gtk_window_new 0") gtk("gtk_window_set_title #{$win} \"Ruby GTK-server demo\"") gtk("gtk_widget_set_usize #{$win} 300 100") gtk("gtk_window_set_position #{$win} 1") $tbl = gtk("gtk_table_new 20 20 1") gtk("gtk_container_add #{$win} #{$tbl}") $but = gtk("gtk_button_new_with_label \"Click to Quit\"") gtk("gtk_table_attach_defaults #{$tbl} #{$but} 12 19 12 19") $lab = gtk("gtk_label_new \"Ruby uses GTK now!!\"") gtk("gtk_table_attach_defaults #{$tbl} #{$lab} 1 15 1 10") super end def show gtk("gtk_widget_show_all #{$win}") end end end # Start program, instantiate if __FILE__ == $0 include GTK startup mywindow = Application.new mywindow.show mainloop shutdown end