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

(yzsuai) #1

from tkinter import *
from tkinter.simpledialog import askstring
from tkinter.filedialog import SaveAs, Open, Directory
from tkinter.messagebox import showinfo, showerror, askyesno


reuse book examples


from PP4E.Gui.Tools import windows # window border, exit protocols
from PP4E.Gui.Tools import threadtools # thread callback queue checker
from PP4E.Internet.Email import mailtools # load,send,parse,build utilities
from PP4E.Gui.TextEditor import textEditor # component and pop up


modules defined here


import mailconfig # user params: servers, fonts, etc.
import popuputil # help, busy, passwd pop-up windows
import wraplines # wrap long message lines
import messagecache # remember already loaded mail
import html2text # simplistic html->plaintext extract
import PyMailGuiHelp # user documentation


def printStack(exc_info):
"""
debugging: show exception and stack traceback on stdout;
3.0: change to print stack trace to a real log file if print
to sys.stdout fails: it does when launched from another program
on Windows; without this workaround, PMailGUI aborts and exits
altogether, as this is called from the main thread on spawned
thread failures; likely a Python 3.1 bug: it doesn't occur in
2.5 or 2.6, and the traceback object works fine if print to file;
oddly, the print() calls here work (but go nowhere) if spawned;
"""
print(exc_info[0])
print(exc_info[1])
import traceback
try:
traceback.print_tb(exc_info[2], file=sys.stdout) # ok unless spawned!
except:
log = open('_pymailerrlog.txt', 'a') # use a real file
log.write('-'*80) # else gui may exit
traceback.print_tb(exc_info[2], file=log) # in 3.X, not 2.5/6


thread busy counters for threads run by this GUI


sendingBusy shared by all send windows, used by main window quit


loadingHdrsBusy = threadtools.ThreadCounter() # only 1
deletingBusy = threadtools.ThreadCounter() # only 1
loadingMsgsBusy = threadtools.ThreadCounter() # poss many
sendingBusy = threadtools.ThreadCounter() # poss many


ListWindows: Message List Windows


The code in Example 14-3 implements mail index list windows—for the server inbox
window and for one or more local save-mail file windows. These two types of windows
look and behave largely the same, and in fact share most of their code in common in a


PyMailGUI Implementation| 1067
Free download pdf