| 1 | title = 'Pmw toplevel megawidget 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 MessageInfo(Pmw.MegaToplevel): |
| 11 | |
| 12 | # Demo Pmw toplevel megawidget. |
| 13 | |
| 14 | def __init__(self, parent=None, **kw): |
| 15 | |
| 16 | # Define the megawidget options. |
| 17 | optiondefs = () |
| 18 | self.defineoptions(kw, optiondefs) |
| 19 | |
| 20 | # Initialise the base class (after defining the options). |
| 21 | Pmw.MegaToplevel.__init__(self, parent) |
| 22 | |
| 23 | # Create the components. |
| 24 | interior = self.interior() |
| 25 | |
| 26 | self._dismiss = self.createcomponent('dismiss', |
| 27 | (), None, |
| 28 | Tkinter.Button, (interior,), |
| 29 | text = 'Dismiss', |
| 30 | command = self.goodbye) |
| 31 | self._dismiss.pack(side = 'bottom', pady = 4) |
| 32 | |
| 33 | self._separator = self.createcomponent('separator', |
| 34 | (), None, |
| 35 | Tkinter.Frame, (interior,), |
| 36 | height = 2, |
| 37 | borderwidth = 1, |
| 38 | relief = 'sunken') |
| 39 | self._separator.pack(side = 'bottom', fill = 'x', pady = 4) |
| 40 | |
| 41 | self._icon = self.createcomponent('icon', |
| 42 | (), None, |
| 43 | Tkinter.Label, (interior,)) |
| 44 | self._icon.pack(side = 'left', padx = 8, pady = 8) |
| 45 | |
| 46 | self._infoFrame = self.createcomponent('infoframe', |
| 47 | (), None, |
| 48 | Tkinter.Frame, (interior,)) |
| 49 | self._infoFrame.pack( |
| 50 | side = 'left', |
| 51 | fill = 'both', |
| 52 | expand = 1, |
| 53 | padx = 4, |
| 54 | pady = 4) |
| 55 | |
| 56 | self._message = self.createcomponent('message', |
| 57 | (), None, |
| 58 | Tkinter.Label, (interior,)) |
| 59 | self._message.pack(expand = 1, fill = 'both', padx = 10, pady = 10) |
| 60 | |
| 61 | self.bind('<Return>', self.goodbye) |
| 62 | |
| 63 | # Check keywords and initialise options. |
| 64 | self.initialiseoptions() |
| 65 | |
| 66 | def goodbye(self, event = None): |
| 67 | self.destroy() |
| 68 | |
| 69 | class Demo: |
| 70 | def __init__(self, parent): |
| 71 | # Create button to launch the megawidget. |
| 72 | self.button = Tkinter.Button(parent, |
| 73 | command = self.showMessageInfo, |
| 74 | text = 'Show toplevel megawidget') |
| 75 | self.button.pack(padx = 8, pady = 8) |
| 76 | |
| 77 | self.count = 0 |
| 78 | self.parent = parent |
| 79 | |
| 80 | def showMessageInfo(self): |
| 81 | bitmaps = ('warning', 'hourglass', 'error', 'info', |
| 82 | 'gray25', 'gray50', 'question', 'questhead') |
| 83 | bitmap = bitmaps[self.count % len(bitmaps)] |
| 84 | |
| 85 | message = 'This is a demonstration of\na megawidget.\n' + \ |
| 86 | 'It contains a configurable\nmessage area and bitmap.\n' + \ |
| 87 | 'This instance is displaying\nthe "' + bitmap + '" bitmap.' |
| 88 | |
| 89 | # Make the toplevel window a child of this window, so that it |
| 90 | # is destroyed when the demo is destroyed. |
| 91 | MessageInfo(self.parent, message_text = message, icon_bitmap = bitmap) |
| 92 | |
| 93 | self.count = self.count + 1 |
| 94 | if self.count == 1: |
| 95 | self.button.configure(text = 'Show another\ntoplevel megawidget') |
| 96 | |
| 97 | ###################################################################### |
| 98 | |
| 99 | # Create demo in root window for testing. |
| 100 | if __name__ == '__main__': |
| 101 | root = Tkinter.Tk() |
| 102 | Pmw.initialise(root) |
| 103 | root.title(title) |
| 104 | |
| 105 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) |
| 106 | exitButton.pack(side = 'bottom') |
| 107 | widget = Demo(root) |
| 108 | root.mainloop() |