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

(yzsuai) #1

  • Copying alternative module variables to mailconfig attributes using dict and
    setattr

  • Using a class for configuration to better support customization in subclasses

  • Issuing a pop-up in the GUI to prompt for an account name after or before the
    main window appears


And so on. The separate subdirectory scheme used here was chosen to minimize im-
pacts on existing code in general; to avoid changes to the existing mailconfig module
specifically (which works fine for the single account case); to avoid requiring extra user
input of any kind in single account cases; and to allow for the fact that an “import
module1 as module2” statement doesn’t prevent “module1” from being imported di-
rectly later. This last point is more fraught with peril than you might expect—importing
a customized version of a module is not merely a matter of using the “as” renaming
extension:


import m1 as m2 # custom import: load m1 as m2 alternative
print(m2.attr) # prints attr in m1.py

import m2 # later imports: loads m2.py anyhow!
print(m2.attr) # prints attr in m2.py

In other words, this is a quick-and-dirty solution that I originally wrote for testing
purposes, and it seems a prime candidate for improvement—along with the other ideas
in the next section’s chapter wrap up.


Ideas for Improvement


Although I use the 3.0 version of PyMailGUI as is on a regular basis for both personal
and business communications, there is always room for improvement to software, and
this system is no exception. If you wish to experiment with its code, here are a few
suggested projects to close out this chapter:


Column sorts and list layout
Mail list windows could be sorted by columns on demand. This may require a more
sophisticated list window structure which presents columns more distinctly. The
current display of mail lists seems like the most obvious candidate for cosmetic
upgrade in general, and any column sorting solution would likely address this as
well. tkinter extensions such as the Tix HList widget may show promise here, and
the third-party TkinterTreectrl supports multicolumn sortable listboxes, too, but
is available only for Python 2.X today; consult the Web and other resources for
pointers and details.


Mail save file (and sent file) size
The implementation of save-mail files limits their size by loading them into memory
all at once; a DBM keyed-access implementation may work around this constraint.
See the list windows module comments for ideas. This also applies to sent-mail


1116 | Chapter 14: The PyMailGUI Client

Free download pdf