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

(yzsuai) #1

New in 3.0: supports Unicode encodings for main text + text attachments sent.
New in 3.0: PyEdit supports arbitrary Unicode for message parts viewed.
New in 3.0: supports Unicode/mail encodings for headers in mails sent.


TBD: could avoid verifying quits unless text area modified (like PyEdit2.0),
but these windows are larger, and would not catch headers already changed.
TBD: should Open dialog in write windows be program-wide? (per-window now).
###############################################################################
"""


from SharedNames import * # program-wide global objects


###############################################################################


message view window - also a superclass of write, reply, forward


###############################################################################


class ViewWindow(windows.PopupWindow, mailtools.MailParser):
"""
a Toplevel, with extra protocol and embedded TextEditor;
inherits saveParts,partsList from mailtools.MailParser;
mixes in custom subclass logic by direct inheritance here;
"""


class attributes


modelabel = 'View' # used in window titles
from mailconfig import okayToOpenParts # open any attachments at all?
from mailconfig import verifyPartOpens # ask before open each part?
from mailconfig import maxPartButtons # show up to this many + '...'
from mailconfig import skipTextOnHtmlPart # 3.0: just browser, not PyEdit?
tempPartDir = 'TempParts' # where 1 selected part saved


all view windows use same dialog: remembers last dir


partsDialog = Directory(title=appname + ': Select parts save directory')


def init(self, headermap, showtext, origmessage=None):
"""
header map is origmessage, or custom hdr dict for writing;
showtext is main text part of the message: parsed or custom;
origmessage is parsed email.message.Message for view mail windows
"""
windows.PopupWindow.init(self, appname, self.modelabel)
self.origMessage = origmessage
self.makeWidgets(headermap, showtext)


def makeWidgets(self, headermap, showtext):
"""
add headers, actions, attachments, text editor
3.0: showtext is assumed to be decoded Unicode str here;
it will be encoded on sends and saves as directed/needed;
"""
actionsframe = self.makeHeaders(headermap)
if self.origMessage and self.okayToOpenParts:
self.makePartButtons()
self.editor = textEditor.TextEditorComponentMinimal(self)


1086 | Chapter 14: The PyMailGUI Client

Free download pdf