| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
from Tkinter import * |
| 12 |
|
| 13 |
class Dialog: |
| 14 |
|
| 15 |
command = None |
| 16 |
|
| 17 |
def __init__(self, master=None, **options): |
| 18 |
|
| 19 |
|
| 20 |
if TkVersion < 4.2: |
| 21 |
raise TclError, "this module requires Tk 4.2 or newer" |
| 22 |
|
| 23 |
self.master = master |
| 24 |
self.options = options |
| 25 |
if not master and options.get('parent'): |
| 26 |
self.master = options['parent'] |
| 27 |
|
| 28 |
def _fixoptions(self): |
| 29 |
pass |
| 30 |
|
| 31 |
def _fixresult(self, widget, result): |
| 32 |
return result |
| 33 |
|
| 34 |
def show(self, **options): |
| 35 |
|
| 36 |
|
| 37 |
for k, v in options.items(): |
| 38 |
self.options[k] = v |
| 39 |
|
| 40 |
self._fixoptions() |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
w = Frame(self.master) |
| 45 |
|
| 46 |
try: |
| 47 |
|
| 48 |
s = w.tk.call(self.command, *w._options(self.options)) |
| 49 |
|
| 50 |
s = self._fixresult(w, s) |
| 51 |
|
| 52 |
finally: |
| 53 |
|
| 54 |
try: |
| 55 |
|
| 56 |
w.destroy() |
| 57 |
except: |
| 58 |
pass |
| 59 |
|
| 60 |
return s |