annotate Lib/lib-tk/ScrolledText.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents af51604d00db
children 90c77b8af1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # A ScrolledText widget feels like a text widget but also has a
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # vertical scroll bar on its right. (Later, options may be added to
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # add a horizontal bar as well, to make the bars disappear
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # automatically when not needed, to move them to the other side of the
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # window, etc.)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # Configuration options are passed to the Text widget.
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # A Frame widget is inserted between the master and the text, to hold
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # the Scrollbar widget.
1712
2ef9d50ab654 Totally changed, now it is actually derived from Text
Guido van Rossum <guido@python.org>
parents: 1708
diff changeset
10 # Most methods calls are inherited from the Text widget; Pack methods
2ef9d50ab654 Totally changed, now it is actually derived from Text
Guido van Rossum <guido@python.org>
parents: 1708
diff changeset
11 # are redirected to the Frame widget however.
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 from Tkinter import *
1712
2ef9d50ab654 Totally changed, now it is actually derived from Text
Guido van Rossum <guido@python.org>
parents: 1708
diff changeset
14 from Tkinter import _cnfmerge
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
1712
2ef9d50ab654 Totally changed, now it is actually derived from Text
Guido van Rossum <guido@python.org>
parents: 1708
diff changeset
16 class ScrolledText(Text):
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
17 def __init__(self, master=None, cnf=None, **kw):
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
18 if cnf is None:
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
19 cnf = {}
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
20 if kw:
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
21 cnf = _cnfmerge((cnf, kw))
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
22 fcnf = {}
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
23 for k in cnf.keys():
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
24 if type(k) == ClassType or k == 'name':
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
25 fcnf[k] = cnf[k]
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
26 del cnf[k]
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
27 self.frame = apply(Frame, (master,), fcnf)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
28 self.vbar = Scrollbar(self.frame, name='vbar')
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
29 self.vbar.pack(side=RIGHT, fill=Y)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
30 cnf['name'] = 'text'
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
31 apply(Text.__init__, (self, self.frame), cnf)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
32 self.pack(side=LEFT, fill=BOTH, expand=1)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
33 self['yscrollcommand'] = self.vbar.set
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
34 self.vbar['command'] = self.yview
1712
2ef9d50ab654 Totally changed, now it is actually derived from Text
Guido van Rossum <guido@python.org>
parents: 1708
diff changeset
35
21331
2a7d5ffece1c SF patch #491183 (Jeff Epler): ScrolledText.grid() doesn't work
Guido van Rossum <guido@python.org>
parents: 15308
diff changeset
36 # Copy geometry methods of self.frame -- hack!
21369
af51604d00db Fix for SF #491953 (Andrew Dalke): ScrolledText.py has TabError
Guido van Rossum <guido@python.org>
parents: 21331
diff changeset
37 methods = Pack.__dict__.keys()
af51604d00db Fix for SF #491953 (Andrew Dalke): ScrolledText.py has TabError
Guido van Rossum <guido@python.org>
parents: 21331
diff changeset
38 methods = methods + Grid.__dict__.keys()
af51604d00db Fix for SF #491953 (Andrew Dalke): ScrolledText.py has TabError
Guido van Rossum <guido@python.org>
parents: 21331
diff changeset
39 methods = methods + Place.__dict__.keys()
21331
2a7d5ffece1c SF patch #491183 (Jeff Epler): ScrolledText.grid() doesn't work
Guido van Rossum <guido@python.org>
parents: 15308
diff changeset
40
2a7d5ffece1c SF patch #491183 (Jeff Epler): ScrolledText.grid() doesn't work
Guido van Rossum <guido@python.org>
parents: 15308
diff changeset
41 for m in methods:
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
42 if m[0] != '_' and m != 'config' and m != 'configure':
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 11295
diff changeset
43 setattr(self, m, getattr(self.frame, m))