PageRenderTime 364ms CodeModel.GetById 181ms app.highlight 5ms RepoModel.GetById 176ms app.codeStats 0ms

/Lib/lib-tk/Dialog.py

http://unladen-swallow.googlecode.com/
Python | 49 lines | 41 code | 7 blank | 1 comment | 2 complexity | a26bfb1b284219a01d020264708ffbc4 MD5 | raw file
 1# dialog.py -- Tkinter interface to the tk_dialog script.
 2
 3from Tkinter import *
 4from Tkinter import _cnfmerge
 5
 6if TkVersion <= 3.6:
 7    DIALOG_ICON = 'warning'
 8else:
 9    DIALOG_ICON = 'questhead'
10
11
12class Dialog(Widget):
13    def __init__(self, master=None, cnf={}, **kw):
14        cnf = _cnfmerge((cnf, kw))
15        self.widgetName = '__dialog__'
16        Widget._setup(self, master, cnf)
17        self.num = self.tk.getint(
18                self.tk.call(
19                      'tk_dialog', self._w,
20                      cnf['title'], cnf['text'],
21                      cnf['bitmap'], cnf['default'],
22                      *cnf['strings']))
23        try: Widget.destroy(self)
24        except TclError: pass
25    def destroy(self): pass
26
27def _test():
28    d = Dialog(None, {'title': 'File Modified',
29                      'text':
30                      'File "Python.h" has been modified'
31                      ' since the last time it was saved.'
32                      ' Do you want to save it before'
33                      ' exiting the application.',
34                      'bitmap': DIALOG_ICON,
35                      'default': 0,
36                      'strings': ('Save File',
37                                  'Discard Changes',
38                                  'Return to Editor')})
39    print d.num
40
41
42if __name__ == '__main__':
43    t = Button(None, {'text': 'Test',
44                      'command': _test,
45                      Pack: {}})
46    q = Button(None, {'text': 'Quit',
47                      'command': t.quit,
48                      Pack: {}})
49    t.mainloop()