Class: GladeXML
- Defined in:
- lib/knj/jruby-gtk2/gladexml.rb,
lib/knj/ironruby-gtk2/gladexml.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](wname) ⇒ Object
- #auto_connect(data) ⇒ Object
- #find_window(data) ⇒ Object
- #get_widget(wname) ⇒ Object
-
#initialize(filename, &block) ⇒ GladeXML
constructor
A new instance of GladeXML.
Constructor Details
#initialize(filename, &block) ⇒ GladeXML
Returns a new instance of GladeXML.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 5 def initialize(filename, &block) @obs = {} if filename.index("interface>") == nil cont = File.read(filename) @data = XmlSimple.xml_in(cont) window_name = self.find_window(data) @glade = org.gnome.glade.Glade::parse(filename, window_name) else cont = filename @data = XmlSimple.xml_in(cont) window_name = self.find_window(data) Php4r.file_put_contents("temp.glade", cont) @glade = org.gnome.glade.Glade::parse("temp.glade", window_name) FileUtils.rm("temp.glade") end if block_given? @block = block self.auto_connect(@data) end end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
2 3 4 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 2 def block @block end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 3 def data @data end |
Instance Method Details
#[](wname) ⇒ Object
96 97 98 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 96 def [](wname) return self.(wname) end |
#auto_connect(data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 28 def auto_connect(data) data.each do |item| if item[0] == "widget" if item[1][0]["signal"] tha_class = item[1][0]["class"] tha_id = item[1][0]["id"] func_name = item[1][0]["signal"][0]["handler"] name = item[1][0]["signal"][0]["name"] method = @block.call(func_name) object = self.(tha_id) object.signal_connect(name) do |*paras| #Convert arguments to fit the arity-count of the Proc-object (the block, the method or whatever you want to call it). newparas = [] 0.upto(method.arity - 1) do |number| if paras[number] newparas << paras[number] end end method.call(*newparas) end end end if item.is_a?(Array) or item.is_a?(Hash) self.auto_connect(item) end end end |
#find_window(data) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/knj/jruby-gtk2/gladexml.rb', line 60 def find_window(data) data.each do |item| if item[0] == "widget" class_str = item[1][0]["class"] if class_str == "GtkWindow" ret = item[1][0]["id"] if ret.is_a?(String) return ret end end elsif item.is_a?(Array) or item.is_a?(Hash) ret = self.find_window(item) if ret.is_a?(String) return ret end end end end |