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

(yzsuai) #1

self.hdrFields = []
for (i, header) in enumerate(showhdrs):
lab = Label(middle, text=header+':', justify=LEFT)
ent = Entry(middle)
lab.grid(row=i, column=0, sticky=EW)
ent.grid(row=i, column=1, sticky=EW)
middle.rowconfigure(i, weight=1)
hdrvalue = headermap.get(header, '?') # might be empty


3.0: if encoded, decode per email+mime+unicode


if header not in addrhdrs:
hdrvalue = self.decodeHeader(hdrvalue)
else:
hdrvalue = self.decodeAddrHeader(hdrvalue)
ent.insert('0', hdrvalue)
self.hdrFields.append(ent) # order matters in onSend
middle.columnconfigure(1, weight=1)
return left


def actionButtons(self): # must be method for self
return [('Cancel', self.destroy), # close view window silently
('Parts', self.onParts), # multiparts list or the body
('Split', self.onSplit)]


def makePartButtons(self):
"""
add up to N buttons that open attachments/parts
when clicked; alternative to Parts/Split (2.1);
okay that temp dir is shared by all open messages:
part file not saved till later selected and opened;
partname=partname is required in lambda in Py2.4;
caveat: we could try to skip the main text part;
"""
def makeButton(parent, text, callback):
link = Button(parent, text=text, command=callback, relief=SUNKEN)
if mailconfig.partfg: link.config(fg=mailconfig.partfg)
if mailconfig.partbg: link.config(bg=mailconfig.partbg)
link.pack(side=LEFT, fill=X, expand=YES)


parts = Frame(self)
parts.pack(side=TOP, expand=NO, fill=X)
for (count, partname) in enumerate(self.partsList(self.origMessage)):
if count == self.maxPartButtons:
makeButton(parts, '...', self.onSplit)
break
openpart = (lambda partname=partname: self.onOnePart(partname))
makeButton(parts, partname, openpart)


def onOnePart(self, partname):
"""
locate selected part for button and save and open;
okay if multiple mails open: resaves each time selected;
we could probably just use web browser directly here;
caveat: tempPartDir is relative to cwd - poss anywhere;
caveat: tempPartDir is never cleaned up: might be large,


1088 | Chapter 14: The PyMailGUI Client

Free download pdf