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

(yzsuai) #1

"""
if delete of all msgnums works, remove deleted entries
from mail cache, but don't reload either the headers list
or already viewed mails text: cache list will reflect the
changed msg nums on server; if delete fails for any reason,
caller should forceably reload all hdrs next, because some
server msg nums may have changed, in unpredictable ways;
2.1: this now checks msg hdrs to detect out of synch msg
numbers, if TOP supported by mail server; runs in thread
"""
try:
self.deleteMessagesSafely(msgnums, self.allHdrs(), progress)
except mailtools.TopNotSupported:
mailtools.MailFetcher.deleteMessages(self, msgnums, progress)


no errors: update index list


indexed = enumerate(self.msglist)
self.msglist = [msg for (ix, msg) in indexed if ix+1 not in msgnums]


class GuiMessageCache(MessageCache):
"""
add any GUI-specific calls here so cache usable in non-GUI apps
"""


def setPopPassword(self, appname):
"""
get password from GUI here, in main thread
forceably called from GUI to avoid pop ups in threads
"""
if not self.popPassword:
prompt = 'Password for %s on %s?' % (self.popUser, self.popServer)
self.popPassword = askPasswordWindow(appname, prompt)


def askPopPassword(self):
"""
but don't use GUI pop up here: I am run in a thread!
when tried pop up in thread, caused GUI to hang;
may be called by MailFetcher superclass, but only
if passwd is still empty string due to dialog close
"""
return self.popPassword


popuputil: General-Purpose GUI Pop Ups


Example 14-6 implements a handful of utility pop-up windows in a module, in case
they ever prove useful in other programs. Note that the same windows utility module
is imported here, to give a common look-and-feel to the pop ups (icons, titles, and
so on).


1098 | Chapter 14: The PyMailGUI Client

Free download pdf