This file is indexed.

/usr/share/doc/python-gtk2-tutorial/html/sec-Notebooks.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>10.12. Notebooks</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="ch-ContainerWidgets.html" title="Chapter 10. Container Widgets"><link rel="previous" href="sec-Toolbar.html" title="10.11. Toolbar"><link rel="next" href="sec-PlugsAndSockets.html" title="10.13. Plugs and Sockets"></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">10.12. Notebooks</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-Toolbar.html">Prev</a> </td><th width="60%" align="center">Chapter 10. Container Widgets</th><td width="20%" align="right"> <a accesskey="n" href="sec-PlugsAndSockets.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-Notebooks"></a>10.12. Notebooks</h2></div></div><div></div></div><p>The <tt class="classname">NoteBook</tt> Widget is a collection of
"pages" that overlap each other; each page contains different information
with only one page visible at a time. This widget has become more common
lately in GUI programming, and it is a good way to show blocks of similar
information that warrant separation in their display.</p><p>The first function call you will need to know, as you can probably
guess by now, is used to create a new notebook widget.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook = gtk.Notebook()
</pre></td></tr></table><p>Once the notebook has been created, there are a number of
methods that operate on the notebook widget. Let's look at them
individually.</p><p>The first one we will look at is how to position the page
indicators. These page indicators or "tabs" as they are referred to, can be
positioned in four ways: top, bottom, left, or right.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.set_tab_pos(<b class="parameter"><tt>pos</tt></b>)
</pre></td></tr></table><p><i class="parameter"><tt>pos</tt></i> will be one of the following, which are
pretty self explanatory:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  POS_LEFT
  POS_RIGHT
  POS_TOP
  POS_BOTTOM
</pre></td></tr></table><p><tt class="literal">POS_TOP</tt> is the default.</p><p>Next we will look at how to add pages to the notebook. There are
three ways to add pages to a <tt class="classname">NoteBook</tt>. Let's look at
the first two together as they are quite similar.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.append_page(<b class="parameter"><tt>child</tt></b>, <b class="parameter"><tt>tab_label</tt></b>)

  notebook.prepend_page(<b class="parameter"><tt>child</tt></b>, <b class="parameter"><tt>tab_label</tt></b>)
</pre></td></tr></table><p>These methods add pages to the notebook by inserting them from
the back of the notebook (append), or the front of the notebook (prepend).
<i class="parameter"><tt>child</tt></i> is the widget that is placed within the notebook
page, and <i class="parameter"><tt>tab_label</tt></i> is the label for the page being
added. The <i class="parameter"><tt>child</tt></i> widget must be created separately, and
is typically a set of options setup within one of the other container
widgets, such as a table.</p><p>The final method for adding a page to the notebook contains all
of the properties of the previous two, but it allows you to specify what
position you want the page to be in the notebook.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.insert_page(<b class="parameter"><tt>child</tt></b>, <b class="parameter"><tt>tab_label</tt></b>, <b class="parameter"><tt>position</tt></b>)
</pre></td></tr></table><p>The parameters are the same as <tt class="methodname">append</tt>()
and <tt class="methodname">prepend</tt>() except it contains an extra
parameter, <i class="parameter"><tt>position</tt></i>. This parameter is used to
specify what place this page will be inserted into; the first page having
position zero.</p><p>Now that we know how to add a page, lets see how we can remove a
page from the notebook.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.remove_page(<b class="parameter"><tt>page_num</tt></b>)
</pre></td></tr></table><p>This method takes the page specified by
<i class="parameter"><tt>page_num</tt></i> and removes it from the widget pointed to by
<i class="parameter"><tt>notebook</tt></i>.</p><p>To find out what the current page is in a notebook use the
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  page = notebook.get_current_page()
</pre></td></tr></table><p>These next two methods are simple calls to move the notebook
page forward or backward. Simply provide the respective method call with the
notebook widget you wish to operate on.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.next_page()

  notebook.prev_page()
</pre></td></tr></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>When the <i class="parameter"><tt>notebook</tt></i> is currently on the last
page, and <tt class="methodname">next_page</tt>() is called, nothing happens.
Likewise, if the <i class="parameter"><tt>notebook</tt></i> is on the first page, and
<tt class="methodname">prev_page</tt>() is called, nothing happens.</p></div><p>This next method sets the "active" page. If you wish the
notebook to be opened to page 5 for example, you would use this method.
Without using this method, the notebook defaults to displaying the first
page.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.set_current_page(<b class="parameter"><tt>page_num</tt></b>)
</pre></td></tr></table><p>The next two methods add or remove the notebook page tabs and
the notebook border respectively.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.set_show_tabs(<b class="parameter"><tt>show_tabs</tt></b>)

  notebook.set_show_border(<b class="parameter"><tt>show_border</tt></b>)
</pre></td></tr></table><p>The next method is useful when the you have a large number of
pages, and the tabs don't fit on the page. It allows the tabs to be scrolled
through using two arrow buttons.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  notebook.set_scrollable(<b class="parameter"><tt>scrollable</tt></b>)
</pre></td></tr></table><p><i class="parameter"><tt>show_tabs</tt></i>,
<i class="parameter"><tt>show_border</tt></i> and <i class="parameter"><tt>scrollable</tt></i> can
be either <tt class="literal">TRUE</tt> or <tt class="literal">FALSE</tt>.</p><p>Now let's look at an example.
The <a href="examples/notebook.py" target="_top"><span><b class="command">notebook.py</b></span></a>
program creates a window with a notebook and six buttons. The notebook
contains 11 pages, added in three different ways, appended, inserted, and
prepended. The buttons allow you rotate the tab positions, add or remove the
tabs and border, remove a page, change pages in both a forward and backward
manner, and exit the program.
<a href="sec-Notebooks.html#notebookfig" title="Figure 10.9. Notebook Example">Figure 10.9, &#8220;Notebook Example&#8221;</a> illustrates the program display:</p><div class="figure"><a name="notebookfig"></a><p class="title"><b>Figure 10.9. Notebook Example</b></p><div class="mediaobject" align="center"><img src="figures/notebook.png" align="middle" alt="Notebook Example"></div></div><p>The source code for <a href="examples/notebook.py" target="_top"><span><b class="command">notebook.py</b></span></a> is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
    1	#!/usr/bin/env python
    2	
    3	# example notebook.py
    4	
    5	import pygtk
    6	pygtk.require('2.0')
    7	import gtk
    8	
    9	class NotebookExample:
   10	    # This method rotates the position of the tabs
   11	    def rotate_book(self, button, notebook):
   12	        notebook.set_tab_pos((notebook.get_tab_pos()+1) %4)
   13	
   14	    # Add/Remove the page tabs and the borders
   15	    def tabsborder_book(self, button, notebook):
   16	        tval = False
   17	        bval = False
   18	        if self.show_tabs == False:
   19		    tval = True 
   20	        if self.show_border == False:
   21		    bval = True
   22	
   23	        notebook.set_show_tabs(tval)
   24	        self.show_tabs = tval
   25	        notebook.set_show_border(bval)
   26	        self.show_border = bval
   27	
   28	    # Remove a page from the notebook
   29	    def remove_book(self, button, notebook):
   30	        page = notebook.get_current_page()
   31	        notebook.remove_page(page)
   32	        # Need to refresh the widget -- 
   33	        # This forces the widget to redraw itself.
   34	        notebook.queue_draw_area(0,0,-1,-1)
   35	
   36	    def delete(self, widget, event=None):
   37	        gtk.main_quit()
   38	        return False
   39	
   40	    def __init__(self):
   41	        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   42	        window.connect("delete_event", self.delete)
   43	        window.set_border_width(10)
   44	
   45	        table = gtk.Table(3,6,False)
   46	        window.add(table)
   47	
   48	        # Create a new notebook, place the position of the tabs
   49	        notebook = gtk.Notebook()
   50	        notebook.set_tab_pos(gtk.POS_TOP)
   51	        table.attach(notebook, 0,6,0,1)
   52	        notebook.show()
   53	        self.show_tabs = True
   54	        self.show_border = True
   55	
   56	        # Let's append a bunch of pages to the notebook
   57	        for i in range(5):
   58	            bufferf = "Append Frame %d" % (i+1)
   59	            bufferl = "Page %d" % (i+1)
   60	
   61	            frame = gtk.Frame(bufferf)
   62	            frame.set_border_width(10)
   63	            frame.set_size_request(100, 75)
   64	            frame.show()
   65	
   66	            label = gtk.Label(bufferf)
   67	            frame.add(label)
   68	            label.show()
   69	
   70	            label = gtk.Label(bufferl)
   71	            notebook.append_page(frame, label)
   72	      
   73	        # Now let's add a page to a specific spot
   74	        checkbutton = gtk.CheckButton("Check me please!")
   75	        checkbutton.set_size_request(100, 75)
   76	        checkbutton.show ()
   77	
   78	        label = gtk.Label("Add page")
   79	        notebook.insert_page(checkbutton, label, 2)
   80	
   81	        # Now finally let's prepend pages to the notebook
   82	        for i in range(5):
   83	            bufferf = "Prepend Frame %d" % (i+1)
   84	            bufferl = "PPage %d" % (i+1)
   85	
   86	            frame = gtk.Frame(bufferf)
   87	            frame.set_border_width(10)
   88	            frame.set_size_request(100, 75)
   89	            frame.show()
   90	
   91	            label = gtk.Label(bufferf)
   92	            frame.add(label)
   93	            label.show()
   94	
   95	            label = gtk.Label(bufferl)
   96	            notebook.prepend_page(frame, label)
   97	    
   98	        # Set what page to start at (page 4)
   99	        notebook.set_current_page(3)
  100	
  101	        # Create a bunch of buttons
  102	        button = gtk.Button("close")
  103	        button.connect("clicked", self.delete)
  104	        table.attach(button, 0,1,1,2)
  105	        button.show()
  106	
  107	        button = gtk.Button("next page")
  108	        button.connect("clicked", lambda w: notebook.next_page())
  109	        table.attach(button, 1,2,1,2)
  110	        button.show()
  111	
  112	        button = gtk.Button("prev page")
  113	        button.connect("clicked", lambda w: notebook.prev_page())
  114	        table.attach(button, 2,3,1,2)
  115	        button.show()
  116	
  117	        button = gtk.Button("tab position")
  118	        button.connect("clicked", self.rotate_book, notebook)
  119	        table.attach(button, 3,4,1,2)
  120	        button.show()
  121	
  122	        button = gtk.Button("tabs/border on/off")
  123	        button.connect("clicked", self.tabsborder_book, notebook)
  124	        table.attach(button, 4,5,1,2)
  125	        button.show()
  126	
  127	        button = gtk.Button("remove page")
  128	        button.connect("clicked", self.remove_book, notebook)
  129	        table.attach(button, 5,6,1,2)
  130	        button.show()
  131	
  132	        table.show()
  133	        window.show()
  134	
  135	def main():
  136	    gtk.main()
  137	    return 0
  138	
  139	if __name__ == "__main__":
  140	    NotebookExample()
  141	    main()
  </pre></td></tr></table><p>I hope this helps you on your way with creating notebooks for your
PyGTK applications.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-Toolbar.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch-ContainerWidgets.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-PlugsAndSockets.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">10.11. Toolbar </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 10.13. Plugs and Sockets</td></tr></table></div></body></html>