Adding Menu Bar and Menu on Window

I referred to wxRuby documentation to add Menu Bar and Menu on a Window,
but the code is not working.

I tried:

========== [CODE] ===========
class MinimalApp < App
def on_init
@frame = MDIParentFrame.new(nil,-1,‘RubyPIM - [Main
Window]’,Point.new(100,100),Size.new(1200,800)).show()
@menubar = MenuBar.new

    @file = Menu.new
    @open = @file.append("Open", "open")
    @menubar.append(@file, "File")
    @frame.set_menu_bar(@menubar)
end

end

I am getting error:

D:/Aptana Projects/RubyPIM/MainWindow.rb:13:in on_init': undefined methodset_menu_bar’ for true:TrueClass (NoMethodError)
from D:/Aptana Projects/RubyPIM/MainWindow.rb:18:in main_loop' from D:/Aptana Projects/RubyPIM/MainWindow.rb:18:in

Am Wed, 25 Jul 2012 18:04:24 +0200
schrieb Rubyist R. [email protected]:

    @menubar = MenuBar.new

D:/Aptana Projects/RubyPIM/MainWindow.rb:13:in on_init': undefined method set_menu_bar’ for true:TrueClass (NoMethodError)
from D:/Aptana Projects/RubyPIM/MainWindow.rb:18:in main_loop' from D:/Aptana Projects/RubyPIM/MainWindow.rb:18:in

If you’re just starting out with wxRuby, why do you use MDI windows?
These are quite complex windows, and for the beginning you’re far
better off using ordinary frames.

In your above code, @frame is set to `true’, which is the return value
of show. true doesn’t have a method #set_menu_bar, hence the exception.

As said, for a minimal app you don’t want MDI windows. Try something
like this:

================================================
require “wx”

class MinimalApp < Wx::App
include Wx

def on_init
@frame = Frame.new(nil, title: “Main window”)

@menubar = MenuBar.new
menu     = Menu.new
@menubar.append(menu, "File")
@frame.menu_bar = @menubar

@frame.show

end

end

MinimalApp.new.main_loop

Oh, and please read this one:
http://wxruby.rubyforge.org/doc/wxruby_intro.html

You don’t have to obey the C+±derived method documentation directly.
wxRuby adds some nice and more rubyish wrappers around them.

Vale,
Marvin


Blog: http://pegasus-alpha.eu/blog

ASCII-Ribbon-Kampagne () | ASCII Ribbon Campaign ()

I am new to Ruby and wxRuby as well. I started writing a real
application which will make learning interesting. I therefore need an
MDIWindow.