I am trying to get a program to run and while I got the glade window to
show, when I tried to make buttons execute code I started getting
errors. I seem to be having problems with this line:
glade = GladeXML.new(‘main_window.glade’, nil, nil, nil, GladeXML::FILE)
{|handler| method(handler)}
Especially the last handler bit. That should connect the defs I have
later such as:
def on_servers_treeview_select_cursor_row(widget, arg0)
puts “on_servers_treeview_select_cursor_row() is not implemented
yet.”
end
def on_main_window_destroy_event(widget, arg0)
puts “on_main_window_destroy_event() is not implemented yet.”
end
When I run my code I get this:
main_window.rb:9:in method': undefined method on_main_window_destroy_event’ for class Object' (NameError) from main_window.rb:9 from /usr/local/lib/site_ruby/1.8/libglade2.rb:33:in connect’
from main_window.rb:9
def on_main_window_destroy_event(widget, arg0)
puts “on_main_window_destroy_event() is not implemented yet.”
end
Your very close to what you want to do. Basically, you need to look at
how the Ruby-GNOME2 Bindings translate between the two. The main thing
to look at, is the fact that it’ll work with the name of the control,
and the event, so, for example, the on_main_window_destroy_event() is
right, the other, should proably be
on_servers_treeview_select_cursor_row_event() The most easiest way to
do it, is to create a Class definition, such as:
class MyGladeWindow < GladeXML
def initialize()
super(‘main_window.glade’,nil,nil,nil,GladeXML::File) { |handler|
method(handler) }
end
def on_main_window_destroy_event(widget, arg0)
puts "on_main_window_destroy_event() is not implemented yet."
end
end
This should get the effect your wanting, and ensures your not polluting
the mainObject namespace with methods that only have to deal with your
Window Management.