This file is indexed.

/usr/share/doc/python-gtk2-tutorial/html/sec-TextViews.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>13.2. TextViews</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-TextViewWidget.html" title="Chapter 13. TextView Widget"><link rel="previous" href="ch-TextViewWidget.html" title="Chapter 13. TextView Widget"><link rel="next" href="sec-TextBuffers.html" title="13.3. Text Buffers"></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">13.2. TextViews</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch-TextViewWidget.html">Prev</a> </td><th width="60%" align="center">Chapter 13. TextView Widget</th><td width="20%" align="right"> <a accesskey="n" href="sec-TextBuffers.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-TextViews"></a>13.2. TextViews</h2></div></div><div></div></div><p>There is only one function for creating a new
<tt class="classname">TextView</tt> widget.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview = gtk.TextView(<b class="parameter"><tt>buffer</tt></b>=None)
</pre></td></tr></table><p>When a <tt class="classname">TextView</tt> is created it will create
an associated <tt class="classname">TextBuffer</tt> and
<tt class="classname">TextTagTable</tt> by default. If you want to use an
existing <tt class="classname">TextBuffer</tt> in a
<tt class="classname">TextView</tt> specify it in the above method. To change
the <tt class="classname">TextBuffer</tt> used by a
<tt class="classname">TextView</tt> use the following method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_buffer(<b class="parameter"><tt>buffer</tt></b>)
</pre></td></tr></table><p>Use the following method to retrieve a reference to the
<tt class="classname">TextBuffer</tt> from a
<tt class="classname">TextView</tt>:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  buffer = textview.get_buffer()
</pre></td></tr></table><p>A <tt class="classname">TextView</tt> widget doesn't have scrollbars
to adjust the view in case the text is larger than the window. To provide
scrollbars, you add the <tt class="classname">TextView</tt> to a
<tt class="classname">ScrolledWindow</tt> (see <a href="sec-ScrolledWindows.html" title="10.9. Scrolled Windows">Section 10.9, &#8220;Scrolled Windows&#8221;</a>).</p><p>A <tt class="classname">TextView</tt> can be used to allow the user
to edit a body of text, or to display multiple lines of read-only text to
the user. To switch between these modes of operation, the use the following
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_editable(<b class="parameter"><tt>setting</tt></b>)
</pre></td></tr></table><p>The <i class="parameter"><tt>setting</tt></i> argument is a
<tt class="literal">TRUE</tt> or <tt class="literal">FALSE</tt> value that specifies
whether the user is permitted to edit the contents of the
<tt class="classname">TextView</tt> widget. The editable mode of the
<tt class="classname">TextView</tt> can be overridden in text ranges within the
<tt class="classname">TextBuffer</tt> by <tt class="classname">TextTag</tt>s.</p><p>You can retrieve the current editable setting using the
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  setting = textview.get_editable()
</pre></td></tr></table><p>When the <tt class="classname">TextView</tt> is not editable, you
probably should hide the cursor using the method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_cursor_visible(<b class="parameter"><tt>setting</tt></b>)
</pre></td></tr></table><p>The <i class="parameter"><tt>setting</tt></i> argument is a
<tt class="literal">TRUE</tt> or <tt class="literal">FALSE</tt> value that specifies
whether the cursor should be visible The <tt class="classname">TextView</tt> can
wrap lines of text that are too long to fit onto a single line of the
display window. Its default behavior is to not wrap lines. This can be
changed using the next method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_wrap_mode(<b class="parameter"><tt>wrap_mode</tt></b>)
</pre></td></tr></table><p>This method allows you to specify that the text widget should
wrap long lines on word or character boundaries. The
<i class="parameter"><tt>word_wrap</tt></i> argument is one of:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  gtk.WRAP_NONE
  gtk.WRAP_CHAR
  gtk.WRAP_WORD
</pre></td></tr></table><p>The default justification of the text in a
<tt class="classname">TextView</tt> can be set and retrieved using the
methods:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_justification(<b class="parameter"><tt>justification</tt></b>)
  justification = textview.get_justification()
</pre></td></tr></table><p>where <i class="parameter"><tt>justification</tt></i> is one of:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  gtk.JUSTIFY_LEFT
  gtk.JUSTIFY_RIGHT
  gtk.JUSTIFY_CENTER
</pre></td></tr></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The <i class="parameter"><tt>justification</tt></i> will be
<tt class="literal">JUSTIFY_LEFT</tt> if the <i class="parameter"><tt>wrap_mode</tt></i> is
<tt class="literal">WRAP_NONE</tt>. Tags in the associated
<tt class="classname">TextBuffer</tt> may override the default
justification.</p></div><p>Other default attributes that can be set and retrieved in a
<tt class="classname">TextView</tt> are: left margin, right margin, tabs, and
paragraph indentation using the following methods:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  textview.set_left_margin(<b class="parameter"><tt>left_margin</tt></b>)
  left_margin = textview.get_left_margin()
  
  textview.set_right_margin(<b class="parameter"><tt>right_margin</tt></b>)
  right_margin = textview.get_right_margin()
  
  textview.set_indent(<b class="parameter"><tt>indent</tt></b>)
  indent = textview.get_indent()
  
  textview.set_pixels_above_lines(<b class="parameter"><tt>pixels_above_line</tt></b>)
  pixels_above_line = textview.get_pixels_above_lines()
  
  textview.set_pixels_below_lines(<b class="parameter"><tt>pixels_below_line</tt></b>)
  pixels_below_line = textview.get_pixels_below_lines()
  
  textview.set_pixels_inside_wrap(<b class="parameter"><tt>pixels_inside_wrap</tt></b>)
  pixels_inside_wrap = textview.get_pixels_inside_wrap()
  
  textview.set_tabs(<b class="parameter"><tt>tabs</tt></b>)
  tabs = textview.get_tabs()
</pre></td></tr></table><p><i class="parameter"><tt>left_margin</tt></i>,
<i class="parameter"><tt>right_margin</tt></i>, <i class="parameter"><tt>indent</tt></i>,
<i class="parameter"><tt>pixels_above_lines</tt></i>,
<i class="parameter"><tt>pixels_below_lines</tt></i> and
<i class="parameter"><tt>pixels_inside_wrap</tt></i> are specified in pixels. These
default values may be overridden by tags in the associated
<tt class="classname">TextBuffer</tt>.  <i class="parameter"><tt>tabs</tt></i> is a
<tt class="classname">pango.TabArray</tt>.</p><p>The <a href="examples/textview-basic.py" target="_top"><span><b class="command">textview-basic.py</b></span></a> 
example program illustrates basic use of the <tt class="classname">TextView</tt>
widget:</p><div class="figure"><a name="textviewbasicfig"></a><p class="title"><b>Figure 13.1. Basic TextView Example</b></p><div class="mediaobject" align="center"><img src="figures/textview-basic.png" align="middle" alt="Basic TextView Example"></div></div><p>The source code for the program is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
    1	#!/usr/bin/env python
    2	
    3	# example textview-basic.py
    4	
    5	import pygtk
    6	pygtk.require('2.0')
    7	import gtk
    8	
    9	class TextViewExample:
   10	    def toggle_editable(self, checkbutton, textview):
   11	        textview.set_editable(checkbutton.get_active())
   12	
   13	    def toggle_cursor_visible(self, checkbutton, textview):
   14	        textview.set_cursor_visible(checkbutton.get_active())
   15	
   16	    def toggle_left_margin(self, checkbutton, textview):
   17	        if checkbutton.get_active():
   18	            textview.set_left_margin(50)
   19	        else:
   20	            textview.set_left_margin(0)
   21	
   22	    def toggle_right_margin(self, checkbutton, textview):
   23	        if checkbutton.get_active():
   24	            textview.set_right_margin(50)
   25	        else:
   26	            textview.set_right_margin(0)
   27	
   28	    def new_wrap_mode(self, radiobutton, textview, val):
   29	        if radiobutton.get_active():
   30	            textview.set_wrap_mode(val)
   31	
   32	    def new_justification(self, radiobutton, textview, val):
   33	        if radiobutton.get_active():
   34	            textview.set_justification(val)
   35	
   36	    def close_application(self, widget):
   37	        gtk.main_quit()
   38	
   39	    def __init__(self):
   40	        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   41	        window.set_resizable(True)  
   42	        window.connect("destroy", self.close_application)
   43	        window.set_title("TextView Widget Basic Example")
   44	        window.set_border_width(0)
   45	
   46	        box1 = gtk.VBox(False, 0)
   47	        window.add(box1)
   48	        box1.show()
   49	
   50	        box2 = gtk.VBox(False, 10)
   51	        box2.set_border_width(10)
   52	        box1.pack_start(box2, True, True, 0)
   53	        box2.show()
   54	
   55	        sw = gtk.ScrolledWindow()
   56	        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
   57	        textview = gtk.TextView()
   58	        textbuffer = textview.get_buffer()
   59	        sw.add(textview)
   60	        sw.show()
   61	        textview.show()
   62	
   63	        box2.pack_start(sw)
   64	        # Load the file textview-basic.py into the text window
   65	        infile = open("textview-basic.py", "r")
   66	
   67	        if infile:
   68	            string = infile.read()
   69	            infile.close()
   70	            textbuffer.set_text(string)
   71	
   72	        hbox = gtk.HButtonBox()
   73	        box2.pack_start(hbox, False, False, 0)
   74	        hbox.show()
   75	
   76	        vbox = gtk.VBox()
   77	        vbox.show()
   78	        hbox.pack_start(vbox, False, False, 0)
   79	        # check button to toggle editable mode
   80	        check = gtk.CheckButton("Editable")
   81	        vbox.pack_start(check, False, False, 0)
   82	        check.connect("toggled", self.toggle_editable, textview)
   83	        check.set_active(True)
   84	        check.show()
   85	        # check button to toggle cursor visiblity
   86	        check = gtk.CheckButton("Cursor Visible")
   87	        vbox.pack_start(check, False, False, 0)
   88	        check.connect("toggled", self.toggle_cursor_visible, textview)
   89	        check.set_active(True)
   90	        check.show()
   91	        # check button to toggle left margin
   92	        check = gtk.CheckButton("Left Margin")
   93	        vbox.pack_start(check, False, False, 0)
   94	        check.connect("toggled", self.toggle_left_margin, textview)
   95	        check.set_active(False)
   96	        check.show()
   97	        # check button to toggle right margin
   98	        check = gtk.CheckButton("Right Margin")
   99	        vbox.pack_start(check, False, False, 0)
  100	        check.connect("toggled", self.toggle_right_margin, textview)
  101	        check.set_active(False)
  102	        check.show()
  103	        # radio buttons to specify wrap mode
  104	        vbox = gtk.VBox()
  105	        vbox.show()
  106	        hbox.pack_start(vbox, False, False, 0)
  107	        radio = gtk.RadioButton(None, "WRAP__NONE")
  108	        vbox.pack_start(radio, False, True, 0)
  109	        radio.connect("toggled", self.new_wrap_mode, textview, gtk.WRAP_NONE)
  110	        radio.set_active(True)
  111	        radio.show()
  112	        radio = gtk.RadioButton(radio, "WRAP__CHAR")
  113	        vbox.pack_start(radio, False, True, 0)
  114	        radio.connect("toggled", self.new_wrap_mode, textview, gtk.WRAP_CHAR)
  115	        radio.show()
  116	        radio = gtk.RadioButton(radio, "WRAP__WORD")
  117	        vbox.pack_start(radio, False, True, 0)
  118	        radio.connect("toggled", self.new_wrap_mode, textview, gtk.WRAP_WORD)
  119	        radio.show()
  120	
  121	        # radio buttons to specify justification
  122	        vbox = gtk.VBox()
  123	        vbox.show()
  124	        hbox.pack_start(vbox, False, False, 0)
  125	        radio = gtk.RadioButton(None, "JUSTIFY__LEFT")
  126	        vbox.pack_start(radio, False, True, 0)
  127	        radio.connect("toggled", self.new_justification, textview,
  128	                      gtk.JUSTIFY_LEFT)
  129	        radio.set_active(True)
  130	        radio.show()
  131	        radio = gtk.RadioButton(radio, "JUSTIFY__RIGHT")
  132	        vbox.pack_start(radio, False, True, 0)
  133	        radio.connect("toggled", self.new_justification, textview,
  134	                      gtk.JUSTIFY_RIGHT)
  135	        radio.show()
  136	        radio = gtk.RadioButton(radio, "JUSTIFY__CENTER")
  137	        vbox.pack_start(radio, False, True, 0)
  138	        radio.connect("toggled", self.new_justification, textview,
  139	                      gtk.JUSTIFY_CENTER)
  140	        radio.show()
  141	
  142	        separator = gtk.HSeparator()
  143	        box1.pack_start(separator, False, True, 0)
  144	        separator.show()
  145	
  146	        box2 = gtk.VBox(False, 10)
  147	        box2.set_border_width(10)
  148	        box1.pack_start(box2, False, True, 0)
  149	        box2.show()
  150	
  151	        button = gtk.Button("close")
  152	        button.connect("clicked", self.close_application)
  153	        box2.pack_start(button, True, True, 0)
  154	        button.set_flags(gtk.CAN_DEFAULT)
  155	        button.grab_default()
  156	        button.show()
  157	        window.show()
  158	
  159	def main():
  160	    gtk.main()
  161	    return 0       
  162	
  163	if __name__ == "__main__":
  164	    TextViewExample()
  165	    main()
</pre></td></tr></table><p>Lines 10-34 define the callbacks for the radio and check buttons
used to change the default attributes of the
<tt class="classname">TextView</tt>. Lines 55-63 create a
<tt class="classname">ScrolledWindow</tt> to contain the
<tt class="classname">TextView</tt>. The <tt class="classname">ScrolledWindow</tt>
is packed into a <tt class="classname">VBox</tt> with the check and radio
buttons created in lines 72-140. The <tt class="classname">TextBuffer</tt>
associated with the <tt class="classname">TextView</tt> is loaded with the
contents of the source file in lines 64-70.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch-TextViewWidget.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch-TextViewWidget.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-TextBuffers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 13. TextView Widget </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 13.3. Text Buffers</td></tr></table></div></body></html>