Figure 10-19. PyGadgets launcher bar
Because of its different role, PyGadgets takes a more data-driven approach to building
the GUI: it stores program names in a list and steps through it as needed instead of
using a sequence of precoded demoButton calls. The set of buttons on the launcher bar
GUI in Figure 10-19, for example, depends entirely upon the contents of the programs
list.
The source code behind this GUI is listed in Example 10-31. It’s not much because it
relies on other modules we wrote earlier to work most of its magic: launchmodes for
program spawns, windows for window icons and quits, and LaunchBrowser for web
browser starts. PyGadgets gets a clickable shortcut on my desktop and is usually open
on my machines. I use to gain quick access to Python tools that I use on a daily basis—
text editors, calculators, email and photo tools, and so on—all of which we’ll meet in
upcoming chapters.
To customize PyGadgets for your own use, simply import and call its functions with
program command-line lists of your own or change the mytools list of spawnable pro-
grams near the end of this file. This is Python, after all.
Example 10-31. PP4E\PyGadgets.py
"""
##############################################################################
Start various examples; run me at start time to make them always available.
This file is meant for starting programs you actually wish to use; see
PyDemos for starting Python/Tk demos and more details on program start
options. Windows usage note: this is a '.py' to show messages in a console
window when run or clicked (including a 10 second pause to make sure it's
visible while gadgets start if clicked). To avoid Windows console pop up,
run with the 'pythonw' program (not 'python'), rename to '.pyw' suffix,
mark with 'run minimized' window property, or spawn elsewhere (see PyDemos).
##############################################################################
"""
import sys, time, os, time
from tkinter import *
from launchmodes import PortableLauncher # reuse program start class
from Gui.Tools.windows import MainWindow # reuse window tools: icon, quit
def runImmediate(mytools):
"""
launch gadget programs immediately
"""
print('Starting Python/Tk gadgets...') # msgs to stdout (poss temp)
668 | Chapter 10: GUI Coding Techniques