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

(yzsuai) #1
Operations such as individual sends and views that are largely independent can
overlap broadly, but deletions and mail header fetches cannot.
In addition, some potentially long-running save-mail operations are threaded to
avoid blocking the GUI, and this edition uses a set object to prevent fetch threads
for requests that include a message whose fetch is in progress in order to avoid
redundant work (see the 3.0 changes review earlier).

For more on why such things matter in general, be sure to see the discussion of threads
in GUIs in Chapters 5, 9, and 10. PyMailGUI is really just a concrete realization of
concepts we’ve explored earlier.


Load Server Interface


Let’s return to loading our email: because the load operation is really a socket operation,
PyMailGUI automatically connects to your email server using whatever connectivity
exists on the machine on which it is run. For instance, if you connect to the Net over
a modem and you’re not already connected, Windows automatically pops up the
standard connection dialog. On the broadband connections that most of us use today,
the interface to your email server is normally automatic.


After PyMailGUI finishes loading your email, it populates the main window’s scrolled
listbox with all of the messages on your email server and automatically scrolls to the
most recently received message. Figure 14-10 shows what the main window looks like
after selecting a message with a click and resizing—the text area in the middle grows
and shrinks with the window, revealing more header columns as it grows.


Figure 14-10. PyMailGUI main window resized


Technically, the Load button fetches all your mail’s header text the first time it is
pressed, but it fetches only newly arrived email headers on later presses. PyMailGUI
keeps track of the last email loaded, and requests only higher email numbers on later
loads. Already loaded mail is kept in memory, in a Python list, to avoid the cost of
downloading it again. PyMailGUI does not delete email from your server when it is


1030 | Chapter 14: The PyMailGUI Client

Free download pdf