print('spamSpamSPAM') # or could build a dialog...
def message2(self):
print('Ni! Ni!') # change me
self.method1() # access the 'Hello' instance...
Try running rad and editing the messages printed by radactions in another window;
you should see your new messages printed in the stdout console window each time the
GUI’s buttons are pressed. This example is deliberately simple to illustrate the concept,
but the actions reloaded like this in practice might build pop-up dialogs, new top-level
windows, and so on. Reloading the code that creates such windows would also let us
dynamically change their appearances.
There are other ways to change a GUI while it’s running. For instance, we saw in
Chapter 9 that appearances can be altered at any time by calling the widget config
method, and widgets can be added and deleted from a display dynamically with meth-
ods such as pack_forget and pack (and their grid manager relatives). Furthermore,
passing a new command=action option setting to a widget’s config method might reset
a callback handler to a new action object on the fly; with enough support code, this
may be a viable alternative to the indirection scheme used earlier to make reloads more
effective in GUIs.
Of course, not all GUIs need to be so dynamic. Imagine a game which allows character
modification, though—dynamic reloads in such a system can greatly enhance their
utility. (I’ll leave the task of extending this example with a massively multiplayer online
role-playing game server as suggested exercise.)
Wrapping Up Top-Level Window Interfaces
Top-level window interfaces were introduced in Chapter 8. This section picks up where
that introduction left off and wraps up those interfaces in classes that automate much
of the work of building top-level windows—setting titles, finding and displaying win-
dow icons, issuing proper close actions based on a window’s role, intercepting window
manager close button clicks, and so on.
Example 10-16 provides wrapper classes for the most common window types—a main
application window, a transient pop-up window, and an embedded GUI component
window. These window types vary slightly in terms of their close operations, but most
inherit common functionality related to window borders: icons, titles, and close but-
tons. By creating, mixing in, or subclassing the class for the type of window you wish
to make, you’ll get all its setup logic for free.
Example 10-16. PP4E\Gui\Tools\windows.py
"""
###############################################################################
Classes that encapsulate top-level interfaces.
Allows same GUI to be main, pop-up, or attached; content classes may inherit
630 | Chapter 10: GUI Coding Techniques