~ubuntu-branches/ubuntu/wily/lua-lgi/wily

« back to all changes in this revision

Viewing changes to samples/gtk-demo/demo-menus.lua

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2012-04-02 13:16:07 UTC
  • Revision ID: package-import@ubuntu.com-20120402131607-qcd5l8n9rx8lsq59
Tags: upstream-0.4+29+g74cbbb1
ImportĀ upstreamĀ versionĀ 0.4+29+g74cbbb1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
return function(parent, dir)
 
2
 
 
3
local lgi = require 'lgi'
 
4
local Gtk = lgi.Gtk
 
5
 
 
6
local function create_menu(depth, tearoff)
 
7
   if depth < 1 then return nil end
 
8
   local menu = Gtk.Menu()
 
9
   if tearoff then
 
10
      menu:append(Gtk.TearoffMenuItem { visible = true })
 
11
   end
 
12
   local group = nil
 
13
   for i = 1, 5 do
 
14
      local item = Gtk.RadioMenuItem {
 
15
         group = group,
 
16
         label = ("item %2d - %d"):format(depth, i),
 
17
         submenu = create_menu(depth - 1, true),
 
18
         sensitive = (i ~= 4),
 
19
      }
 
20
      if not group then group = item end
 
21
      menu:append(item)
 
22
   end
 
23
   return menu
 
24
end
 
25
 
 
26
local window = Gtk.Window {
 
27
   title = "Menus",
 
28
   Gtk.Box {
 
29
      orientation = 'VERTICAL',
 
30
      Gtk.MenuBar {
 
31
         id = 'menubar',
 
32
         Gtk.MenuItem {
 
33
            label = "test\nline2",
 
34
            visible = true,
 
35
            submenu = create_menu(2, true),
 
36
         },
 
37
         Gtk.MenuItem {
 
38
            label = "foo",
 
39
            visible = true,
 
40
            submenu = create_menu(3),
 
41
         },
 
42
         Gtk.MenuItem {
 
43
            label = "bar",
 
44
            visible = true,
 
45
            submenu = create_menu(4, true),
 
46
         },
 
47
      },
 
48
      Gtk.Box {
 
49
         orientation = 'VERTICAL',
 
50
         spacing = 10,
 
51
         border_width = 10,
 
52
         Gtk.Button {
 
53
            id = 'flip',
 
54
            label = "Flip",
 
55
         },
 
56
         Gtk.Button {
 
57
            id = 'close',
 
58
            label = "Close",
 
59
         },
 
60
      },
 
61
   },
 
62
}
 
63
 
 
64
function window.child.close:on_clicked()
 
65
   window:destroy()
 
66
end
 
67
 
 
68
function window.child.flip:on_clicked()
 
69
   local menubar = window.child.menubar
 
70
   local orientation = menubar.parent.orientation
 
71
   orientation = (orientation == 'HORIZONTAL'
 
72
                  and 'VERTICAL' or 'HORIZONTAL')
 
73
   menubar.parent.orientation = orientation
 
74
   menubar.pack_direction = (orientation == 'VERTICAL'
 
75
                             and 'LTR' or 'TTB')
 
76
end
 
77
 
 
78
window:show_all()
 
79
return window
 
80
end,
 
81
 
 
82
"Menus",
 
83
 
 
84
table.concat {
 
85
   [[There are several widgets involved in displaying menus. ]],
 
86
   [[The Gtk.MenuBar widget is a menu bar, which normally appears ]],
 
87
   [[horizontally at the top of an application, but can also be ]],
 
88
   [[layed out vertically. The Gtk.Menu widget is the actual menu ]],
 
89
   [[that pops up. Both Gtk.MenuBar and Gtk.Menu are subclasses ]],
 
90
   [[of Gtk.MenuShell; a Gtk.MenuShell contains menu items (Gtk.MenuItem). ]],
 
91
   [[Each menu item contains text and/or images and can be selected ]],
 
92
   [[by the user.
 
93
]],
 
94
   [[There are several kinds of menu item, including plain ]],
 
95
   [[Gtk.MenuItem, Gtk.CheckMenuItem which can be checked/unchecked, ]],
 
96
   [[Gtk.RadioMenuItem which is a check menu item that's in a mutually ]],
 
97
   [[exclusive group, Gtk.SeparatorMenuItem which is a separator bar, ]],
 
98
   [[Gtk.TearoffMenuItem which allows a Gtk.Menu to be torn off, ]],
 
99
   [[and Gtk.ImageMenuItem which can place a Gtk.Image or other widget ]],
 
100
   [[next to the menu text.
 
101
]],
 
102
   [[A Gtk.MenuItem can have a submenu, which is simply a Gtk.Menu ]],
 
103
   [[to pop up when the menu item is selected. Typically, all menu ]],
 
104
   [[items in a menu bar have submenus.
 
105
]],
 
106
   [[Gtk.UIManager provides a higher-level interface for creating ]],
 
107
   [[menu bars and menus; while you can construct menus manually, ]],
 
108
   [[most people don't do that. There's a separate demo for ]],
 
109
   [[Gtk.UIManager.]],
 
110
}