[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

for (name, commandLine) in mytools:
PortableLauncher(name, commandLine)() # call now to start now
print('One moment please...')
if sys.platform[:3] == 'win': # windows: keep console 10 secs
for i in range(10):
time.sleep(1); print('.' 5 (i+1))


def runLauncher(mytools):
"""
pop up a simple launcher bar for later use
"""
root = MainWindow('PyGadgets PP4E') # or root = Tk() if prefer
for (name, commandLine) in mytools:
b = Button(root, text=name, fg='black', bg='beige', border=2,
command=PortableLauncher(name, commandLine))
b.pack(side=LEFT, expand=YES, fill=BOTH)
root.mainloop()


mytools = [
('PyEdit', 'Gui/TextEditor/textEditor.py'),
('PyCalc', 'Lang/Calculator/calculator.py'),
('PyPhoto', 'Gui/PIL/pyphoto1.py Gui/PIL/images'),
('PyMail', 'Internet/Email/PyMailGui/PyMailGui.py'),
('PyClock', 'Gui/Clock/clock.py -size 175 -bg white'
' -picture Gui/gifs/pythonPowered.gif'),
('PyToe', 'Ai/TicTacToe/tictactoe.py'
' -mode Minimax -fg white -bg navy'),
('PyWeb', 'LaunchBrowser.pyw'
' -live index.html learning-python.com')]
#' -live PyInternetDemos.html localhost:80')]
#' -file')] # PyInternetDemos assumes local server started


if name == 'main':
prestart, toolbar = True, False
if prestart:
runImmediate(mytools)
if toolbar:
runLauncher(mytools)


By default, PyGadgets starts programs immediately when it is run. To run PyGadgets
in launcher bar mode instead, Example 10-32 simply imports and calls the appropriate
function with an imported program list. Because it is a .pyw file, you see only the
launcher bar GUI it constructs initially, not a DOS console streams window—nice for
regular use, but not if you want to see error messages (use a .py).


Example 10-32. PP4E\PyGadgets_bar.pyw


"""
run a PyGadgets toolbar only, instead of starting all the gadgets immediately;
filename avoids DOS pop up on Windows: rename to '.py' to see console messages;
"""


import PyGadgets
PyGadgets.runLauncher(PyGadgets.mytools)


The PyDemos and PyGadgets Launchers | 669
Free download pdf