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

(yzsuai) #1

May, 2010 (2.1 January, 2006)

Programming Python, 4th Edition

Mark Lutz, for O'Reilly Media, Inc.



PyMailGUI is a multiwindow interface for processing email, both online and
...rest of file omitted...

altconfigs: Configuring for Multiple Accounts


Though not an “official” part of the system, I use a few additional short files to launch
and test it. If you have multiple email accounts, it can be inconvenient to change a
configuration file every time you want to open one in particular. Moreover, if you open
multiple PyMailGUI sessions for your accounts at the same time, it would be better if
they could use custom appearance and behavior schemes to make them distinct.


To address this, the altconfigs directory in the examples source directory provides a
simple way to select an account and configurations for it at start-up time. It defines a
new top-level script which tailors the module import search path, along with a mail
config that prompts for and loads a custom configuration module whose suffix is
named by console input. A launcher script is also provided to run without module
search path configurations—from PyGadgets or a desktop shortcut, for example, with-
out requiring PYTHONPATH settings for the PP4E root. Examples 14-13 through
14-17 list the files involved.


Example 14-13. PP4E\Internet\PyMailGui\altconfigs\PyMailGui.py


import sys # ..\PyMailGui.py or 'book' for book configs
sys.path.insert(1, '..') # add visibility for real dir
exec(open('../PyMailGui.py').read()) # do this, but get mailconfig here


Example 14-14. PP4E\Internet\PyMailGui\altconfigs\mailconfig.py


above = open('../mailconfig.py').read() # copy version above here (hack?)
open('mailconfigbook.py', 'w').write(above) # used for 'book' and as others' base
acct = input('Account name?') # book, rmi, train
exec('from mailconfig
%s import *' % acct) #. is first on sys.path


Example 14-15. PP4E\Internet\PyMailGui\altconfigs\mailconfig_rmi.py


from mailconfig_book import * # get base in. (copied from ..)
popservername = 'pop.rmi.net' # this is a big inbox: 4800 emails!
popusername = 'lutz'
myaddress = '[email protected]'
listbg = 'navy'
listfg = 'white'
listHeight = 20 # higher initially
viewbg = '#dbbedc'
viewfg = 'black'
wrapsz = 80 # wrap at 80 cols
fetchlimit = 300 # load more headers


1114 | Chapter 14: The PyMailGUI Client

Free download pdf