def init(self):
windows.ComponentWindow.init(self)
PyMailServer.init(self)
class PyMailFileWindow(PyMailFile, windows.PopupWindow):
"a Toplevel, with extra protocol and mixed-in methods"
def init(self, filename):
windows.PopupWindow.init(self, appname, filename)
PyMailFile.init(self, filename)
###############################################################################
when run as a top-level program: create main mail-server list window
###############################################################################
if name == 'main':
rootwin = PyMailServerWindow() # open server window
if len(sys.argv) > 1: # 3.0: fix to add len()
for savename in sys.argv[1:]:
rootwin.onOpenMailFile(savename) # open save file windows (demo)
rootwin.lift() # save files loaded in threads
rootwin.mainloop()
SharedNames: Program-Wide Globals
The module in Example 14-2 implements a shared, system-wide namespace that col-
lects resources used in most modules in the system and defines global objects that span
files. This allows other files to avoid redundantly repeating common imports and en-
capsulates the locations of package imports; it is the only file that must be updated if
paths change in the future. Using globals can make programs more difficult to under-
stand in general (the source of some names is not as clear), but it is reasonable if all
such names are collected in a single expected module such as this one, because there
is only one place to search for unknown names.
Example 14-2. PP4E\Internet\Email\PyMailGui\SharedNames.py
"""
##############################################################################
objects shared by all window classes and main file: program-wide globals
##############################################################################
"""
used in all window, icon titles
appname = 'PyMailGUI 3.0'
used for list save, open, delete; also for sent messages file
saveMailSeparator = 'PyMailGUI' + ('-'*60) + 'PyMailGUI\n'
currently viewed mail save files; also for sent-mail file
openSaveFiles = {} # 1 window per file,{name:win}
standard library services
import sys, os, email.utils, email.message, webbrowser, mimetypes
1066 | Chapter 14: The PyMailGUI Client