class MenusDemo

# Copyright © 2015-2016 Ruby-GNOME2 Project Team # This program is licenced under the same licence as Ruby-GNOME2. #

Menus

There are several widgets involved in displaying menus. The
GtkMenuBar widget is a menu bar, which normally appears horizontally
at the top of an application, but can also be layed out vertically.
The GtkMenu widget is the actual menu that pops up. Both GtkMenuBar
and GtkMenu are subclasses of GtkMenuShell; a GtkMenuShell contains
menu items (GtkMenuItem). Each menu item contains text and/or images
and can be selected by the user.

There are several kinds of menu item, including plain GtkMenuItem,
GtkCheckMenuItem which can be checked/unchecked, GtkRadioMenuItem
which is a check menu item that's in a mutually exclusive group,
GtkSeparatorMenuItem which is a separator bar, GtkTearoffMenuItem
which allows a GtkMenu to be torn off, and GtkImageMenuItem which
can place a GtkImage or other widget next to the menu text.

A GtkMenuItem can have a submenu, which is simply a GtkMenu to pop
up when the menu item is selected. Typically, all menu items in a menu bar
have submenus.

Public Class Methods

new(main_window) click to toggle source
# File gtk3/sample/gtk-demo/menus.rb, line 27
def initialize(main_window)
  @window = Gtk::Window.new(:toplevel)
  @window.screen = main_window.screen
  @window.title = "Menus"

  accel_group = Gtk::AccelGroup.new
  @window.add_accel_group(accel_group)

  box = Gtk::Box.new(:horizontal, 0)
  @window.add(box)

  box1 = Gtk::Box.new(:horizontal, 0)
  box.add(box1)

  @menubar = Gtk::MenuBar.new
  @menubar.expand = true
  box1.pack_start(@menubar, :expand => false, :fill => true, :padding => 0)

  { "test\nline2" => 2, "foo" => 3, "bar" => 4 }.each do |k, v|
    create_menu_item(k, v)
  end

  box2 = Gtk::Box.new(:vertical, 10)
  box1.pack_start(box2, :expand => false, :fill => true, :padding => 0)

  button = generate_flip_button
  box2.pack_start(button, :expand => true, :fill => true, :padding => 0)
  button = generate_close_button
  box2.pack_start(button, :expand => true, :fill => true, :padding => 0)
end

Public Instance Methods

run() click to toggle source
# File gtk3/sample/gtk-demo/menus.rb, line 58
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end