Forum: wxRuby Adding Menu Bar and Menu on Window

Eb460fbf2920a94d448cba8169c8ba41?d=identicon&s=25 Rubyist Rohit (rpk2006)
on 2012-07-25 18:04
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>'
85991f138ede6236f35eb98da22b7b01?d=identicon&s=25 Marvin Gülker (quintus)
on 2012-07-25 19:30
(Received via mailing list)
Attachment: signature.asc (489 Bytes)
Am Wed, 25 Jul 2012 18:04:24 +0200
schrieb Rubyist Rohit <lists@ruby-forum.com>:

>         @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 `<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
Eb460fbf2920a94d448cba8169c8ba41?d=identicon&s=25 Rubyist Rohit (rpk2006)
on 2012-07-25 19:34
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.
32bf7f25f16ad6469ffd361709baf241?d=identicon&s=25 Nathan Hilogogifts (hilogogifts)
on 2014-03-13 11:03
what's more you can learn from here hilogogifts  .  com
This topic is locked and can not be replied to.