Saturday, November 13, 2010

Programming wxRuby (2) - Add Menubar

1. I added a menu bar to the wxRuby program. This menu bar has only one menu (File) and one item (Exit).

#!/usr/bin/env ruby
# menu01.rb
#
require 'rubygems'
require 'wx'
 
class AppFrame < Wx::Frame

 def initialize
  super(nil)
  window_settings
  menu_settings
 end
 
 def window_settings
  set_title 'Testing Menubar'
  set_size 400,300
 end
 
 def menu_settings
  mbar = Wx::MenuBar.new
  file = Wx::Menu.new
  file.append( Wx::ID_EXIT, "E&xit\tAlt-X", "Quit" )
  mbar.append( file, "&File" )
  self.menu_bar = mbar
  evt_menu( Wx::ID_EXIT, :on_quit )
 end
 
 def on_quit
  close
 end
  
end
 
class MyApp < Wx::App
 def on_init
  @frame = AppFrame.new
  @frame.show
 end
end
 
app = MyApp.new
app.main_loop
 

2. Here is a resulted window with a menu bar.



3. References http://ruby.about.com/od/gui/a/wxrubymenu.htm

No comments:

Post a Comment