| 1 | title = 'Pmw.Dialog demonstration' |
| 2 | |
| 3 | # Import Pmw from this directory tree. |
| 4 | import sys |
| 5 | sys.path[:0] = ['../../..'] |
| 6 | |
| 7 | import Tkinter |
| 8 | import Pmw |
| 9 | |
| 10 | class Demo: |
| 11 | def __init__(self, parent): |
| 12 | # Create two buttons to launch the dialog. |
| 13 | w = Tkinter.Button(parent, text = 'Show application modal dialog', |
| 14 | command = self.showAppModal) |
| 15 | w.pack(padx = 8, pady = 8) |
| 16 | |
| 17 | w = Tkinter.Button(parent, text = 'Show global modal dialog', |
| 18 | command = self.showGlobalModal) |
| 19 | w.pack(padx = 8, pady = 8) |
| 20 | |
| 21 | w = Tkinter.Button(parent, text = 'Show dialog with "no grab"', |
| 22 | command = self.showDialogNoGrab) |
| 23 | w.pack(padx = 8, pady = 8) |
| 24 | |
| 25 | w = Tkinter.Button(parent, text = |
| 26 | 'Show toplevel window which\n' + |
| 27 | 'will not get a busy cursor', |
| 28 | command = self.showExcludedWindow) |
| 29 | w.pack(padx = 8, pady = 8) |
| 30 | |
| 31 | # Create the dialog. |
| 32 | self.dialog = Pmw.Dialog(parent, |
| 33 | buttons = ('OK', 'Apply', 'Cancel', 'Help'), |
| 34 | defaultbutton = 'OK', |
| 35 | title = 'My dialog', |
| 36 | command = self.execute) |
| 37 | self.dialog.withdraw() |
| 38 | |
| 39 | # Add some contents to the dialog. |
| 40 | w = Tkinter.Label(self.dialog.interior(), |
| 41 | text = 'Pmw Dialog\n(put your widgets here)', |
| 42 | background = 'black', |
| 43 | foreground = 'white', |
| 44 | pady = 20) |
| 45 | w.pack(expand = 1, fill = 'both', padx = 4, pady = 4) |
| 46 | |
| 47 | # Create the window excluded from showbusycursor. |
| 48 | self.excluded = Pmw.MessageDialog(parent, |
| 49 | title = 'I still work', |
| 50 | message_text = |
| 51 | 'This window will not get\n' + |
| 52 | 'a busy cursor when modal dialogs\n' + |
| 53 | 'are activated. In addition,\n' + |
| 54 | 'you can still interact with\n' + |
| 55 | 'this window when a "no grab"\n' + |
| 56 | 'modal dialog is displayed.') |
| 57 | self.excluded.withdraw() |
| 58 | Pmw.setbusycursorattributes(self.excluded.component('hull'), |
| 59 | exclude = 1) |
| 60 | |
| 61 | def showAppModal(self): |
| 62 | self.dialog.activate(geometry = 'centerscreenalways') |
| 63 | |
| 64 | def showGlobalModal(self): |
| 65 | self.dialog.activate(globalMode = 1) |
| 66 | |
| 67 | def showDialogNoGrab(self): |
| 68 | self.dialog.activate(globalMode = 'nograb') |
| 69 | |
| 70 | def showExcludedWindow(self): |
| 71 | self.excluded.show() |
| 72 | |
| 73 | def execute(self, result): |
| 74 | print 'You clicked on', result |
| 75 | if result not in ('Apply', 'Help'): |
| 76 | self.dialog.deactivate(result) |
| 77 | |
| 78 | ###################################################################### |
| 79 | |
| 80 | # Create demo in root window for testing. |
| 81 | if __name__ == '__main__': |
| 82 | root = Tkinter.Tk() |
| 83 | Pmw.initialise(root) |
| 84 | root.title(title) |
| 85 | |
| 86 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) |
| 87 | exitButton.pack(side = 'bottom') |
| 88 | widget = Demo(root) |
| 89 | root.mainloop() |