On to our next GUI coding technique: in response to the challenge posed at the end of the last section, the script in Example 10-12 arranges to map input and output sources to pop-up windows in a GUI application, much as we did with strings in the stream redirection topics in Chapter 3. Although this module is really just a first-cut prototype and needs improvement itself (e.g., each input line request pops up a new input dialog—not exactly award winning ergonomics!), it demonstrates the concepts in general.
GuiInput objects define methods that allow
them to masquerade as files in any interface that expects a real file.
As we learned earlier in Chapter 3,
this includes both the
input built-in functions for
accessing standard streams, as well as explicit calls to the
write methods of file objects. The two
top-level interfaces in this module handle common use cases:
function uses this plug-and-play file compatibility to run a
function with its standard input and output streams mapped
completely to pop-up windows rather than to the console window (or
wherever streams would otherwise be mapped in the system
function similarly routes the output of a spawned shell command
line to a pop-up window. It can be used to display the output of
any program in a GUI—including that printed by a Python
GuiOutput classes ...