Home arrow Python arrow Page 4 - Deleting Email and More with the PyMailGUI Client

PyMailGUI Implementation - Python

Continuing our tour through PyMailGUI, this week we show you how to delete email, explain POP message numbers and synchronization, and finally begin talking about the code. This article, the fourth of six parts, 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. Deleting Email and More with the PyMailGUI Client
  2. POP Message Numbers and Synchronization
  3. Multiple Windows and Status Messages
  4. PyMailGUI Implementation
By: O'Reilly Media
Rating: starstarstarstarstar / 1
August 02, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Last but not least, we get to the code. PyMailGUI consists of the nine new modules listed at the start of this chapter; the source code for these modules is listed in this section.

Code Reuse

Besides the code here, PyMailGUI also gets a lot of mileage out of reusing modules we wrote earlier and won’t repeat here:mailtoolsfor mail loads, composition, parsing, and delete operations;threadtoolsfor managing server and local file access threads; the GUI section’sTextEditorfor displaying and editing mail message text; and so on.

In addition, standard Python modules and packages such aspoplib,smtplib, andemail hide most of the details of pushing bytes around the Net and extracting and building message components. As usual, theTkinterstandard library module also implements GUI components in a portable fashion.

Code Structure

As mentioned earlier, PyMailGUI applies code factoring and OOP to leverage code reuse. For instance, list view windows are implemented as a common superclass that codes most actions, along with one subclass for the server inbox list window and one for local save-file list windows. The subclasses customize the common superclass for their specific mail media.

This design reflects the operation of the GUI itself—server list windows load mail over POP, and save-file list windows load from local files. The basic operation of list window layout and actions, though, is similar for both and is shared in the common superclass to avoid redundancy and simplify the code. Message view windows are similarly factored: a common view window superclass is reused and customized for write, reply, and forward view windows.

To make the code easier to follow, it is divided into two main modules that reflect the structure of the GUI—one for the implementation of list window actions and one for view window actions. If you are looking for the implementation of a button that appears in a mail view or edit window, for instance, see the view window module and search for a method whose name begins with the word on—the convention used for callback handler methods. Button text can also be located in name/callback tables used to build the windows. Actions initiated on list windows are coded in the list window module instead.

In addition, the message cache is split off into an object and module of its own, and potentially reusable tools are coded in importable modules (e.g., line wrapping and utility popups). PyMailGUI also includes a main module that defines startup window classes, a module that contains the help text as a string, and themailconfiguser settings module (a version specific to PyMailGUI is used here).

The next few sections list all of PyMailGUI’s code for you to study; as you read, refer back to the demo earlier in this chapter and run the program live to map its behavior back to its code. PyMailGUI also includes a__init__.pyfile so that it can be used as a package—some of its modules may be useful in other programs. The __init__.py is empty in this package, so we omit it here.

Please check back next week for the continuation of this article.



 
 
>>> 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: