class TextPak2(DictMenuGui):
def init(self):
self.myMenu = {'Pack ': runPackDialog, # or use input here...
'Unpack': runUnpackDialog, # instead of in dialogs
'Mtool ': self.notdone}
DictMenuGui.init(self)
if name == 'main': # self-test code...
from sys import argv # 'menugui.py list|^'
if len(argv) > 1 and argv[1] == 'list':
print('list test')
TextPak1().mainloop()
else:
print('dict test')
TextPak2().mainloop()
The classes in this module are specific to a particular tool set; to display a different set
of tool names, simply code and run a new subclass. By separating out application logic
into distinct subclasses and modules like this, software can become widely reusable.
Figure 10-5 shows the main ShellGui window created when the mytools script is run
with its list-based menu layout class on Windows 7, along with menu tear-offs so that
you can see what they contain. This window’s menu and toolbar are built by Gui
Maker, and its Quit and Help buttons and menu selections trigger quit and help methods
inherited from GuiMixin through the ShellGui module’s superclasses. Are you starting
to see why this book preaches code reuse so often?
Figure 10-5. mytools items in a ShellGui window
616 | Chapter 10: GUI Coding Techniques