Python
  Home arrow Python arrow Page 2 - The PyMailGUI Client
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

The PyMailGUI Client
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-07-12

    Table of Contents:
  • The PyMailGUI Client
  • Source Code Modules
  • Why PyMailGUI?
  • Running PyMailGUI

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The PyMailGUI Client - Source Code Modules


    (Page 2 of 4 )

    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


       · This article is an excerpt from the book "Programming Python, Third Edition,"...
     

    Buy this book now. This article is excerpted from chapter 15 of the book Programming Python, Third Edition, written by Mark Lutz (O'Reilly, 2006; ISBN: 0596009259). Check it out today at your favorite bookstore. Buy this book now.

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway