PageRenderTime 66ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/ruby-gnome2-all-0.90.4/gtk2/sample/misc/t-gtksocket.rb

#
Ruby | 65 lines | 44 code | 7 blank | 14 comment | 2 complexity | b26cfe52ab0d293f6d830d9189eb0b98 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. #!/usr/bin/env ruby
  2. =begin
  3. Sample script using Gtk::Socket and Gtk::Plug.
  4. $ ruby t-gtksocket.rb
  5. Written by Alex Boussinet <mailto:dbug@wanadoo.fr> for testing purpose only.
  6. Copyright (c) 2003-2006 Ruby-GNOME2 Project Team
  7. This program is licenced under the same licence as Ruby-GNOME2.
  8. $Id: t-gtksocket.rb,v 1.5 2006/06/17 13:18:12 mutoh Exp $
  9. =end
  10. require 'gtk2'
  11. class MyGtkSocket < Gtk::Window
  12. def initialize
  13. super("Gtk::Socket Test")
  14. set_window_position(Gtk::Window::POS_CENTER)
  15. signal_connect("delete_event"){Gtk::main_quit}
  16. @buttons = []
  17. 6.times {|n|
  18. @buttons << Gtk::Button.new("Plug #{n}")
  19. @buttons.last.signal_connect("clicked"){ plug(n) }
  20. }
  21. @table = Gtk::Table.new(1, 2)
  22. @table.set_size_request(320, 200)
  23. add(@table)
  24. @vbox = Gtk::VBox.new(true, 5)
  25. @buttons.each{|b| @vbox.add(b) }
  26. @vbox.set_size_request(150, 190)
  27. @table.attach(@vbox, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL, 5, 5)
  28. @socket = Gtk::Socket.new
  29. @table.attach(@socket, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL, 5, 5)
  30. @socket.set_size_request(150, 150)
  31. show_all
  32. @xid = @socket.id
  33. @pid = 0
  34. end
  35. def plug(arg)
  36. if @pid != 0
  37. Process.kill("SIGKILL", @pid)
  38. Process.waitpid(@pid)
  39. begin
  40. @table.remove(@socket) unless @socket.destroyed?
  41. rescue ArgumentError
  42. # socket has been destroyed because child process finished unexpectedly
  43. end
  44. @socket = Gtk::Socket.new
  45. @table.attach(@socket, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL, 5, 5)
  46. @socket.set_size_request(150, 190)
  47. @socket.show
  48. @xid = @socket.id
  49. end
  50. @pid = fork { exec "ruby t-gtkplug.rb -x #{@xid} Plug#{arg}" }
  51. end
  52. end
  53. MyGtkSocket.new
  54. Gtk.main