[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-mnstbs-mnub

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 11月 5日 (月) 12:36:24 JST


-------------------------
REMOTE_ADDR = 184.145.95.170
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnub
-------------------------
@@ -4,7 +4,7 @@
 == Menu Bars
 
 
-{{image_right("mnstbs-mnub-01.png")}}
+{{image_right("menubars.png")}}
 
 
 Gtk::MenuBar is a widget that organizes multiple pop-up menus into a horizontal or vertical row. Each root element is a Gtk::MenuItem that pops down into a submenu. An instance of Gtk::MenuBar is usually displayed along the top of the main application window to provide access to functionality provided by the application.
@@ -17,11 +17,10 @@
  #!/usr/bin/env ruby
  require 'gtk2'
  
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
+ window = Gtk::Window.new("Menu Bar w/submenus (1)")
  window.resizable = true
- window.title = "Menu Bars"
  window.border_width = 10
- window.signal_connect('delete_event') { Gtk.main_quit }
+ window.signal_connect('destroy') { Gtk.main_quit }
  window.set_size_request(250, -1)
  
  group = Gtk::AccelGroup.new
@@ -29,18 +28,21 @@
  
  filemenu = Gtk::Menu.new
  editmenu = Gtk::Menu.new
+ orgmenu  = Gtk::Menu.new
  helpmenu = Gtk::Menu.new
-
+ 
  file = Gtk::MenuItem.new("File")
  edit = Gtk::MenuItem.new("Edit")
+ org  = Gtk::MenuItem.new("Organize")
  help = Gtk::MenuItem.new("Help")
-
+ 
  file.submenu = filemenu
  edit.submenu = editmenu
+ org.submenu  = orgmenu
  help.submenu = helpmenu
-
+ 
  menubar.append(file)
  menubar.append(edit)
+ menubar.append(org)
  menubar.append(help)
  
  # Create the File menu content.
@@ -50,25 +53,52 @@
  filemenu.append(open)
  
  # Create the Edit menu content.
- cut   = Gtk::ImageMenuItem.new(Gtk::Stock::CUT, group);
- copy  = Gtk::ImageMenuItem.new(Gtk::Stock::COPY, group);
- paste = Gtk::ImageMenuItem.new(Gtk::Stock::PASTE, group);
+ cut   = Gtk::ImageMenuItem.new(Gtk::Stock::CUT, group)
+ copy  = Gtk::ImageMenuItem.new(Gtk::Stock::COPY, group)
+ paste = Gtk::ImageMenuItem.new(Gtk::Stock::PASTE, group)
  editmenu.append(cut)
  editmenu.append(copy)
  editmenu.append(paste)
  
+ # Create Language sub menu
+ langmenu = Gtk::Menu.new
+ 
+ english = Gtk::MenuItem.new("English")
+ french  = Gtk::MenuItem.new("French")
+ german  = Gtk::MenuItem.new("German")
+ russian = Gtk::MenuItem.new("Russian")
+ italian = Gtk::MenuItem.new("Italian")
+ 
+ langmenu.append(english)
+ langmenu.append(french)
+ langmenu.append(german)
+ langmenu.append(russian)
+ langmenu.append(italian)
+ 
+ # Create Organize submenu
+ preferences = Gtk::MenuItem.new("Preferences")
+ languages   = Gtk::MenuItem.new("Languages")
+ orgmenu.append(preferences)
+ orgmenu.append(languages)
+ languages.submenu = langmenu
+ 
  # Create the Help menu content.
-   
+ 
  contents = Gtk::ImageMenuItem.new(Gtk::Stock::HELP, group)
  about    = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT, group)
  helpmenu.append(contents)
  helpmenu.append(about)
-   
+ 
  window.add_accel_group(group)
  
  window.add(menubar)
  window.show_all
  Gtk.main
+
+
 
 A new menu bar widget is created with Gtk::MenuBar.new. This creates an empty menu shell into which you add content. After you have created a menu bar you can set a pack direction with Gtk::MenuBar#pack_direction=(pack_dir), where pack_dir is one of the constants defined in Gtk::MenuBar::PackDirection. By default pack direction is left to right (Gtk::MenuBar::PACK_DIRECTION_LTR). Gtk::MenuBar class provides also child_pack_direction=(pack_dir) instance method, which sets how widgets should be packed inside the children of a menubar.
 




ruby-gnome2-cvs メーリングリストの案内
Back to archive index