Home arrow Python arrow Page 2 - The PyMailGUI Client

Source Code Modules - Python

PyMailGUI is a Python program that sends, receives, composes, and parses Internet email messages. This article, the first of six parts, introduces the PyMailGUI client. It is excerpted from chapter 15 of the book Programming Python, Third Edition, written by Mark Lutz (O'Reilly, 2006; ISBN: 0596009259). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. The PyMailGUI Client
  2. Source Code Modules
  3. Why PyMailGUI?
  4. Running PyMailGUI
By: O'Reilly Media
Rating: starstarstarstarstar / 3
July 12, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

This chapter is something of a self-study exercise. Because PyMailGUI is fairly large and mostly applies concepts we’ve already learned, we won’t go into much detail about its actual code. Instead, it is listed for you to read on your own. I encourage you to study the source and comments and to run this program on your own to get a feel for its operation. Also, be sure to refer back to the modules we introduced earlier in the book and are reusing here, to gain a full understanding of the system. For reference, here are the major examples that will see new action in this chapter:  

Example 14-21: PP3E.Internet.Email.mailtools (package)
   Server sends and receives, parsing, construction
   (Chapter 14)

Example 11-17: PP3E.Gui.Tools.threadtools.py
   Thread queue management for GUI callbacks
   (Chapter 11)

Example 11-13: PP3E.Gui.Tools.windows.py
   Border configuration for top-level window (Chapter
   11)

Example 12-4: PP3E.Gui.TextEditor.textEditor.py
  
Text widget used in mail view windows, and in some 
   pop ups (Chapter 12)

Some of these modules in turn use additional examples we coded earlier, but that are not imported by PyMailGUI itself (textEditor, for instance, usesguimakerto create its windows and toolbar). We’ll also be coding new modules here. The following new modules are intended to be useful in other programs:

utilities.py
   Various pop-up windows, written for general use

messagecache.py 
   A cache that keeps track of mail already loaded

wraplines.py 
   A utility for wrapping long lines of messages

mailconfig.py 
   User configuration parameters—server names, fonts,
   and so on (augmented here)

Finally, the following are new modules coded in this chapter and are specific to the PyMailGUI program:

SharedNames.py 
   Program-wide globals used by multiple files

ViewWindows.py
   The implementation of View, Write, Reply, and 
   Forward message view windows

ListWindows.py
   The implementation of mail-server and local-file 
   message list windows

PyMailGuiHelp2.py
   User-oriented help text, opened by the main 
   window’s bar button

PyMailGui2.py
   The main, top-level file of the program, run to launch
   the main window

All told, PythonMailGUI comprises the nine new modules in the preceding two lists and is composed of some 2,200 lines of source code (including comments, whitespace, and 530 lines of help text). This doesn’t include the four other book examples in the previous list that are reused in PyMailGUI, which themselves constitute 1,600 additional lines.* This is the largest example we’ll see in this book, but you shouldn’t be deterred by its size. Because it uses modular and OOP techniques, the code is simpler than you may think:

  1. Python’s modules allowus to divide the system into files that have a cohesive purpose, with minimal coupling between them—code is easier to locate and understand if your modules have a logical, self-contained structure.
  2. Python’s OOP support allows us to factor code for reuse, and avoid redundancy—as you’ll see, code is customized, not repeated, and the classes we will code reflect the actual components of the GUI to make them easy to follow.

For instance, the implementation of mail list windows is easy to read and change, because it has been factored into a common shared superclass, which is customized by subclasses for mail-server and save-file lists; since these are mostly just variations on a theme, most of the code appears in just one place. Similarly, the code that implements the message view window is a superclass shared by write, reply, and forward composition windows; subclasses simply tailor it for writing rather than viewing.

Although we’ll deploy these techniques in the context of a mail processing program here, such techniques will apply to any nontrivial program you’ll write in Python.

To help get you started, thePyMailGuiHelp2.pymodule listed last in this chapter includes a help text string that describes how this program is used, as well as its major features. Experimenting with the system, while referring to its code, is probably the best and quickest way to uncover its secrets.



 
 
>>> More Python Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: