This file is indexed.

/usr/share/doc/python-gtk2-tutorial/html/ch-MenuWidget.html is in python-gtk2-tutorial 2.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 11. Menu Widget</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="up" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="previous" href="sec-PlugsAndSockets.html" title="10.13. Plugs and Sockets"><link rel="next" href="sec-ManualMenuExample.html" title="11.2. Manual Menu Example"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 11. Menu Widget</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-PlugsAndSockets.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="sec-ManualMenuExample.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ch-MenuWidget"></a>Chapter 11. Menu Widget</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch-MenuWidget.html#sec-ManualMenuCreation">11.1. Manual Menu Creation</a></span></dt><dt><span class="sect1"><a href="sec-ManualMenuExample.html">11.2. Manual Menu Example</a></span></dt><dt><span class="sect1"><a href="sec-UsingItemFactory.html">11.3. Using ItemFactory</a></span></dt><dt><span class="sect1"><a href="sec-ItemFactoryExample.html">11.4. Item Factory Example</a></span></dt></dl></div><p>There are two ways to create menus: there's the easy way, and
there's the hard way. Both have their uses, but you can usually use the
<tt class="classname">ItemFactory</tt> (the easy way). The "hard" way is to
create all the menus using the calls directly. The easy way is to use the
<tt class="classname">gtk.ItemFactory</tt> calls. This is much simpler, but there
are advantages and disadvantages to each approach.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>In PyGTK 2.4 ItemFactory is deprecated - use the UIManager
instead.</p></div><p>The <tt class="classname">ItemFactory</tt> is much easier to use, and
to add new menus to, although writing a few wrapper functions to create
menus using the manual method could go a long way towards usability. With
the <tt class="classname">Itemfactory</tt>, it is not possible to add images or
the character '/' to the menus.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-ManualMenuCreation"></a>11.1. Manual Menu Creation</h2></div></div><div></div></div><p>In the true tradition of teaching, we'll show you the hard way
first. :)</p><p>There are three widgets that go into making a menubar and
submenus:</p><div class="itemizedlist"><ul type="none"><li style="list-style-type: none"><p>a menu item, which is what the user wants to select, e.g., "Save"</p></li><li style="list-style-type: none"><p>a menu, which acts as a container for the menu items, and</p></li><li style="list-style-type: none"><p>a menubar, which is a container for each of the individual menus.</p></li></ul></div><p>This is slightly complicated by the fact that menu item widgets
are used for two different things. They are both the widgets that are packed
into the menu, and the widget that is packed into the menubar, which, when
selected, activates the menu.</p><p>Let's look at the functions that are used to create menus and
menubars. This first function is used to create a new menubar:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_bar = gtk.MenuBar()
</pre></td></tr></table><p>This rather self explanatory function creates a new menubar. You
use the <tt class="classname">gtk.Container</tt> <tt class="methodname">add</tt>()
method to pack this into a window, or the <tt class="classname">gtk.Box</tt> pack
methods to pack it into a box - the same as buttons.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu = gtk.Menu()
</pre></td></tr></table><p>This function returns a reference to a new menu; it is never
actually shown (with the <tt class="methodname">show</tt>() method), it is just a
container for the menu items. I hope this will become more clear when you
look at the example below.</p><p>The next function is used to create menu items that are packed
into the menu (and menubar):</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_item = gtk.MenuItem(<b class="parameter"><tt>label</tt></b>=None)
</pre></td></tr></table><p>The <i class="parameter"><tt>label</tt></i>, if any, will be parsed for
mnemonic characters. This call is used to create the menu items that are to
be displayed. Remember to differentiate between a "menu" as created with
<tt class="function">gtk.Menu</tt>() and a "menu item" as created by the
<tt class="function">gtk.MenuItem</tt>() functions. The menu item will be an
actual button with an associated action, whereas a menu will be a container
holding menu items.</p><p>Once you've created a menu item you have to put it into a menu.
This is done using the <tt class="methodname">append</tt>() method. In order to
capture when the item is selected by the user, we need to connect to the
"activate" signal in the usual way. So, if we wanted to create a standard
<span class="guimenu">File</span> menu, with the options
<span class="guimenuitem">Open</span>,
<span class="guimenuitem"><span class="guimenuitem">Save</span>, and </span>Quit, the
code would look something like:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  file_menu = gtk.Menu()    # Don't need to show menus

  # Create the menu items
  open_item = gtk.MenuItem("Open")
  save_item = gtk.MenuItem("Save")
  quit_item = gtk.MenuItem("Quit")

  # Add them to the menu
  file_menu.append(open_item)
  file_menu.append(save_item)
  file_menu.append(quit_item)

  # Attach the callback functions to the activate signal
  open_item.connect_object("activate", menuitem_response, "file.open")
  save_item.connect_object("activate", menuitem_response, "file.save")

  # We can attach the Quit menu item to our exit function
  quit_item.connect_object ("activate", destroy, "file.quit")

  # We do need to show menu items
  open_item.show()
  save_item.show()
  quit_item.show()
</pre></td></tr></table><p>At this point we have our menu. Now we need to create a menubar
and a menu item for the <span class="guimenu">File</span> entry, to which we add our
menu. The code looks like this:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_bar = gtk.MenuBar()
  window.add(menu_bar)
  menu_bar.show()

  file_item = gtk.MenuItem("File")
  file_item.show()
</pre></td></tr></table><p>Now we need to associate the menu with
<i class="parameter"><tt>file_item</tt></i>. This is done with the method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_item.set_submenu(<b class="parameter"><tt>submenu</tt></b>)
</pre></td></tr></table><p>So, our example would continue with:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  file_item.set_submenu(file_menu)
</pre></td></tr></table><p>All that is left to do is to add the menu to the menubar, which
is accomplished using the method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_bar.append(<b class="parameter"><tt>child</tt></b>)
</pre></td></tr></table><p>which in our case looks like this:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_bar.append(file_item)
</pre></td></tr></table><p>If we wanted the menu right justified on the menubar, such as
help menus often are, we can use the following method (again on
<i class="parameter"><tt>file_item</tt></i> in the current example) before attaching it to
the menubar.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  menu_item.set_right_justified(right_justified)
</pre></td></tr></table><p>Here is a summary of the steps needed to create a menu bar with
menus attached:</p><div class="itemizedlist"><ul type="none"><li style="list-style-type: none"><p>Create a new menu using <tt class="function">gtk.Menu</tt>()</p></li><li style="list-style-type: none"><p>Use multiple calls to <tt class="function">gtk.MenuItem</tt>()
for each item you wish to have on your menu. And use the
<tt class="methodname">append</tt>() method to put each of these new items on to
the menu.</p></li><li style="list-style-type: none"><p>Create a menu item using
<tt class="function">gtk.MenuItem</tt>(). This will be the root of the menu, the
text appearing here will be on the menubar itself.</p></li><li style="list-style-type: none"><p>Use the <tt class="methodname">set_submenu</tt>() method to attach
the menu to the root menu item (the one created in the above step).</p></li><li style="list-style-type: none"><p>Create a new menubar using
<tt class="function">gtk.MenuBar</tt>(). This step only needs to be done once
when creating a series of menus on one menu bar.</p></li><li style="list-style-type: none"><p> Use the <tt class="methodname">append</tt>() method to put the
root menu onto the menubar.</p></li></ul></div><p>Creating a popup menu is nearly the same. The difference is that
the menu is not posted "automatically" by a menubar, but explicitly by
calling the <tt class="methodname">popup</tt>() method from a button-press
event, for example. Take these steps:</p><div class="itemizedlist"><ul type="none"><li style="list-style-type: none"><p>Create an event handling callback. It needs to have the
format:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  def handler(widget, event):
</pre></td></tr></table></li><li style="list-style-type: none"><p>and it will use the event to find out where to pop up the
menu.</p></li><li style="list-style-type: none"><p>In the event handler, if the event is a mouse button press,
treat event as a button event (which it is) and use it as shown in the
sample code to pass information to the <tt class="methodname">popup</tt>()
method.</p></li><li style="list-style-type: none"><p>Bind that event handler to a widget with:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  widget.connect_object("event", handler, menu)
</pre></td></tr></table></li><li style="list-style-type: none"><p>where widget is the widget you are binding to, handler is
the handling function, and menu is a menu created with
<tt class="function">gtk.Menu</tt>(). This can be a menu which is also posted by a
menu bar, as shown in the sample code.</p></li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-PlugsAndSockets.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-ManualMenuExample.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">10.13. Plugs and Sockets </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 11.2. Manual Menu Example</td></tr></table></div></body></html>