Glade interface tutorial - NoMethodError for .show_all

Hi Everyone,

I get a NoMethodError message for the .show_all instruction whilst
following the Glade Interface tutorial
(http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dynui).

Please help, I’m stuck!

Here’s what I did:

  1. I followed the guide (to the letter) and saved as ‘browser.glade’

  2. I use the ‘ruby-glade-create-template browser.glade > browser.rb’
    command to create the ruby file.

  3. Followed the instructions to edit the browser.rb to display the
    window by capturing the BrowserGlade object into a variable:
    o = BrowserGlade.new(PROG_PATH, nil, PROG_NAME)

then adding the following to display the window:
window = o.glade.get_widget(“window”)
window.show_all

  1. However, when I try to run the code ‘ruby browser.rb’, I get the
    following terminal message:
    browser.rb:58: undefined method `show_all’ for nil:NilClass
    (NoMethodError)

OK, so I thought I’ve made a silly mistake - I just need to find out
what I did wrong. However, all interfaces I design in Glade (however
simple) end up the same. I cannot get them to display by running the
ruby script - I always get the same NoMethodError message.

To make matters more confusing; if I copy and paste the original xml
text (posted within the tutorial) into a new .glade file and try the
process again - it works great???

I guess I’m doing something wrong within Glade - but I’ve no idea what?
Any help would be appreciated.

(I’ve attached my browser.glade file if its any help)

Many thanks,
Craig.

browser.rb:58: undefined method `show_all’ for nil:NilClass

This suggests that get_widget(“window”) returned nil. Is “window” the
right name?

-Ian

On Thu, Sep 17, 2009 at 1:00 PM, Craig Parylo

Ian, you’re a genius!

“window” wasn’t the right widget to get. My main window was auto-labeled
as “window1” in the glade file.

I replaced “window” with “window1” in:
get_widget(“window”)
…and it worked perfectly! :slight_smile:

Thank you very much for your help!