| 1 | # Based on iwidgets2.2.0/messagedialog.itk code. |
| 2 | |
| 3 | import Tkinter |
| 4 | import Pmw |
| 5 | |
| 6 | class MessageDialog(Pmw.Dialog): |
| 7 | def __init__(self, parent = None, **kw): |
| 8 | |
| 9 | # Define the megawidget options. |
| 10 | INITOPT = Pmw.INITOPT |
| 11 | optiondefs = ( |
| 12 | ('borderx', 20, INITOPT), |
| 13 | ('bordery', 20, INITOPT), |
| 14 | ('iconmargin', 20, INITOPT), |
| 15 | ('iconpos', None, INITOPT), |
| 16 | ) |
| 17 | self.defineoptions(kw, optiondefs) |
| 18 | |
| 19 | # Initialise the base class (after defining the options). |
| 20 | Pmw.Dialog.__init__(self, parent) |
| 21 | |
| 22 | # Create the components. |
| 23 | interior = self.interior() |
| 24 | |
| 25 | self._message = self.createcomponent('message', |
| 26 | (), None, |
| 27 | Tkinter.Label, (interior,)) |
| 28 | |
| 29 | iconpos = self['iconpos'] |
| 30 | iconmargin = self['iconmargin'] |
| 31 | borderx = self['borderx'] |
| 32 | bordery = self['bordery'] |
| 33 | border_right = 2 |
| 34 | border_bottom = 2 |
| 35 | if iconpos is None: |
| 36 | self._message.grid(column = 1, row = 1) |
| 37 | else: |
| 38 | self._icon = self.createcomponent('icon', |
| 39 | (), None, |
| 40 | Tkinter.Label, (interior,)) |
| 41 | if iconpos not in 'nsew': |
| 42 | raise ValueError, \ |
| 43 | 'bad iconpos option "%s": should be n, s, e, or w' \ |
| 44 | % iconpos |
| 45 | |
| 46 | if iconpos in 'nw': |
| 47 | icon = 1 |
| 48 | message = 3 |
| 49 | else: |
| 50 | icon = 3 |
| 51 | message = 1 |
| 52 | |
| 53 | if iconpos in 'ns': |
| 54 | # vertical layout |
| 55 | self._icon.grid(column = 1, row = icon) |
| 56 | self._message.grid(column = 1, row = message) |
| 57 | interior.grid_rowconfigure(2, minsize = iconmargin) |
| 58 | border_bottom = 4 |
| 59 | else: |
| 60 | # horizontal layout |
| 61 | self._icon.grid(column = icon, row = 1) |
| 62 | self._message.grid(column = message, row = 1) |
| 63 | interior.grid_columnconfigure(2, minsize = iconmargin) |
| 64 | border_right = 4 |
| 65 | |
| 66 | interior.grid_columnconfigure(0, minsize = borderx) |
| 67 | interior.grid_rowconfigure(0, minsize = bordery) |
| 68 | interior.grid_columnconfigure(border_right, minsize = borderx) |
| 69 | interior.grid_rowconfigure(border_bottom, minsize = bordery) |
| 70 | |
| 71 | |
| 72 | # Check keywords and initialise options. |
| 73 | self.initialiseoptions() |