# Glade callbacks and handlers

**URL:** <https://www.ruby-forum.com/t/glade-callbacks-and-handlers/78472>\
**Category:** Ruby-Gnome 2\
**Created:** [December 6, 2006, 12:57am UTC](https://www.ruby-forum.com/t/glade-callbacks-and-handlers/78472 "2006-12-06T00:57:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![williej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@williej](https://www.ruby-forum.com/u/williej)\
**Post date:** [December 6, 2006, 12:57am UTC](https://www.ruby-forum.com/t/glade-callbacks-and-handlers/78472/1 "2006-12-06T00:57:14Z")

</div>

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

Any help?

Thanks

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![williej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@williej](https://www.ruby-forum.com/u/williej)\
**Post date:** [December 6, 2006, 8:58am UTC](https://www.ruby-forum.com/t/glade-callbacks-and-handlers/78472/2 "2006-12-06T08:58:35Z")

</div>

William J. wrote:

> end
> 
> 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.

L8ers,  
Mario S.

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![williej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@williej](https://www.ruby-forum.com/u/williej)\
**Post date:** [December 6, 2006, 6:25pm UTC](https://www.ruby-forum.com/t/glade-callbacks-and-handlers/78472/3 "2006-12-06T18:25:17Z")

</div>

Mario S. wrote:

> > def on\_servers\_treeview\_select\_cursor\_row(widget, arg0)  
> > to look at, is the fact that it’ll work with the name of the control,
> 
> L8ers,  
> Mario S.

Sweet! It worked. Thanks a lot!

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
