annotate Lib/lib-tk/Dialog.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 847ae40074d4
children 90c77b8af1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Dialog.py -- Tkinter interface to the tk_dialog script.
2830
bd79cd768ff8 Tk 4.0 and Tcl 7.4 are now standard
Guido van Rossum <guido@python.org>
parents: 1853
diff changeset
2
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 from Tkinter import *
2883
51c9cfff31f3 keyword parameter changes
Guido van Rossum <guido@python.org>
parents: 2830
diff changeset
4 from Tkinter import _cnfmerge
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
2883
51c9cfff31f3 keyword parameter changes
Guido van Rossum <guido@python.org>
parents: 2830
diff changeset
6 if TkVersion <= 3.6:
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
7 DIALOG_ICON = 'warning'
2830
bd79cd768ff8 Tk 4.0 and Tcl 7.4 are now standard
Guido van Rossum <guido@python.org>
parents: 1853
diff changeset
8 else:
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
9 DIALOG_ICON = 'questhead'
2830
bd79cd768ff8 Tk 4.0 and Tcl 7.4 are now standard
Guido van Rossum <guido@python.org>
parents: 1853
diff changeset
10
bd79cd768ff8 Tk 4.0 and Tcl 7.4 are now standard
Guido van Rossum <guido@python.org>
parents: 1853
diff changeset
11
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 class Dialog(Widget):
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
13 def __init__(self, master=None, cnf={}, **kw):
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
14 cnf = _cnfmerge((cnf, kw))
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
15 self.widgetName = '__dialog__'
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
16 Widget._setup(self, master, cnf)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
17 self.num = self.tk.getint(
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
18 apply(self.tk.call,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
19 ('tk_dialog', self._w,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
20 cnf['title'], cnf['text'],
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
21 cnf['bitmap'], cnf['default'])
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
22 + cnf['strings']))
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
23 try: Widget.destroy(self)
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
24 except TclError: pass
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
25 def destroy(self): pass
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 def _test():
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
28 d = Dialog(None, {'title': 'File Modified',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
29 'text':
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
30 'File "Python.h" has been modified'
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
31 ' since the last time it was saved.'
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
32 ' Do you want to save it before'
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
33 ' exiting the application.',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
34 'bitmap': DIALOG_ICON,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
35 'default': 0,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
36 'strings': ('Save File',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
37 'Discard Changes',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
38 'Return to Editor')})
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
39 print d.num
1691
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
d88af58e95cd Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 if __name__ == '__main__':
15308
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
43 t = Button(None, {'text': 'Test',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
44 'command': _test,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
45 Pack: {}})
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
46 q = Button(None, {'text': 'Quit',
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
47 'command': t.quit,
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
48 Pack: {}})
847ae40074d4 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 2883
diff changeset
49 t.mainloop()