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

(yzsuai) #1

if exc_info[0] == mailtools.MessageSynchError: # synch inbox/index
self.onLoadServer(forceReload=True) # new thread: reload


def onLoadMsgsProgress(self, i, n, after, popup, toLoad):
popup.changeText('%d of %d' % (i, n))


def getMessage(self, msgnum):
return self.cache.getMessage(msgnum) # full mail text


def headersMaps(self):


list of email.message.Message objects, 3.x requires list() if map()


return [self.parseHeaders(h) for h in self.cache.allHdrs()]


return list(map(self.parseHeaders, self.cache.allHdrs()))


def mailSize(self, msgnum):
return self.cache.getSize(msgnum)


def okayToQuit(self):


any threads still running?


filesbusy = [win for win in openSaveFiles.values() if win.openFileBusy]
busy = loadingHdrsBusy or deletingBusy or sendingBusy or loadingMsgsBusy
busy = busy or filesbusy
return not busy


ViewWindows: Message View Windows


Example 14-4 lists the implementation of mail view and edit windows. These windows
are created in response to actions in list windows—View, Write, Reply, and Forward
buttons. See the callbacks for these actions in the list window module of Exam-
ple 14-3 for view window initiation calls.


As in the prior module (Example 14-3), this file is really one common class and a handful
of customizations. The mail view window is nearly identical to the mail edit window,
used for Write, Reply, and Forward requests. Consequently, this example defines the
common appearance and behavior in the view window superclass, and extends it by
subclassing for edit windows.


Replies and forwards are hardly different from the write window here, because their
details (e.g., From and To addresses and quoted message text) are worked out in the
list window implementation before an edit window is created.


Example 14-4. PP4E\Internet\Email\PyMailGui\ViewWindows.py


"""
###############################################################################
Implementation of View, Write, Reply, Forward windows: one class per kind.
Code is factored here for reuse: a Write window is a customized View window,
and Reply and Forward are custom Write windows. Windows defined in this
file are created by the list windows, in response to user actions.


Caveat:'split' pop ups for opening parts/attachments feel nonintuitive.
2.1: this caveat was addressed, by adding quick-access attachment buttons.
New in 3.0: platform-neutral grid() for mail headers, not packed col frames.


PyMailGUI Implementation| 1085
Free download pdf