Am Wed, 25 Jul 2012 18:04:24 +0200
schrieb Rubyist Rohit <lists at ruby-forum.com>:
> 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
> 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
`<main>''
>
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 ()
- Stoppt HTML-E-Mail /\ | - Against HTML E-Mail /\
- Stoppt propriet?re Anh?nge | - Against proprietary attachments
www.asciiribbon.org/index-de.html | www.asciiribbon.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL:
<http://rubyforge.org/pipermail/wxruby-users/attachments/20120725/82f8c3da/attachment.bin>