wxPython

wxPython is a GUI toolkit for the Python programming language that works like a wrapper to the wxWindows C library. It is written in Python and uses the LPGL license. wxPython is a relatively fast cross-platform toolkit, and maybe it hasn't become the standard Python GUI yet because Tkinter is more portable. As a matter of fact, wxPython is the second most common GUI, coming just after Tkinter. Currently only Win32 and UNIX-like systems with GTK are supported. There are plans to support...

The Tkinter Module

Tkinter is Python's de facto standard GUI toolkit. It's the most cross-platform GUI. Many applications are written using Tkinter because it is a very powerful and flexible tool. Maybe the most notable features are its geometry management, which is much better than standard windows, and its efficient Text and Canvas widgets. Many toolkits support as good as or better geometry management some of them are listed in this chapter . Tkinter, which stands for Tk interface, is the standard Python...

Python DB API

The quest to provide a standard way to interface to database systems drove a group of people to develop Python Database API. The Python DB API is maintained by the Database Special Interest Group DB-SIG . For more information, check out their Web site at http www.python.org sigs db-sig . The following list shows all the database modules that currently implement the Python DB API specification proposed by the DB-SIG. This means that after you understand the API, you will be able to handle, in a...

Instead of using the command line interpreter you can also use a graphical user

Figure 2.3. idle is Python's GUI interpreter. python 1.5.2 C cip Apr 13 1999, 10 51 12 msc 3 2 bit lintel on Copyright 1 amp 91-199E Stichting Mattieinatisen Centrum, Ainscertfani See Chapter 16, Development Environment, for details about using IDLE. As you can see by looking at the coding area in both Figures 2.2 and 2.3, the interpreter's primary prompt is a gt gt gt . Let's start interacting with Python by running a variation of the standard hello world program. gt gt gt print Hello Python...

Code Examples 1

This example generates a Python COM server that exposes a parking lot object. The example uses a Visual Basic graphical interface to manipulate the vehicles of this parking lot. Each vehicle is a Python Object that is also defined as a Python COM Server object. The first thing to do is to generate two clsids one for each object. gt gt gt import pythoncom gt gt gt print pythoncom.CreateGuid BD2CB7C0-3BB9-11D4-804E-00 50 041A5111 gt gt gt print pythoncom.CreateGuid BD2CB7C1-3BB9-11D4-804E-00 50...

UploadingUploaded Files

Sometimes, it is necessary to receive files from users through the Web. This next example shows how to send a file across an HTTP connection using an HTML page, and how to later interpret it. form cgi.FieldStorage if not form print Content-Type text html form action cgi-bin uploadfiles.py method POST lt input type file name filename gt lt input type submit gt elif form.has_key filename item form filename if item.file print Content-Type text html When a certain form field represents an uploaded...

Embedding Python in Other Applications

On Windows, Python itself is implemented in a DLL called Python15.dll. Note that the file Python.exe is a small program that calls all the routines stored in the DLL. This is a good example showing that it must be easy to embed Python because it already embeds itself. Besides all this talk about embedding Python in C and C applications, Python can also be embedded Dr. Dietmar Budelsky and Morgan Martinet merged their two separate projects and created The Python for Delphi project. The purpose...

Grail Web Browser

Grail is a free Web browser written entirely in Python, using the Tkinter GUI Tk, which is a free UI toolkit developed by John Ousterhout . Grail has the capability to manipulate SGML, HTML, URL's, images, and sound. Besides, it is easily extended to offer new functionality. Being written in Python helps Grail to have a high adhesion to the Python language. Something similar happens to HotJava, which is a browser written entirely in Java. For documentation and downloads, check out the following...

audiodev Module

The audiodev module provides a generic interface for audio output, which is used by Macintoshes, the SGI UNIX IRIX and SunOS Solaris platforms. Note that there is a module called linuxaudiodev specific for Linux systems. gt gt gt afile aifc.open test.aifc, r gt gt gt dev audiodev.AudioDev gt gt gt data frames afile.readframes data The setoutrate method defines the frequency rate of the sound wave in this case, it is set to 22.05Khz. The setsampwidth method defines the sample width in number of...

Dynamic Namespace

Maybe you haven't noticed yet, but Python uses dynamic namespace concepts. Each function, module, and class defines its own namespace when it is created. When you inform an instruction, command, or statement to Python, it searches first inside the local namespace and afterwards inside the global namespace. Python has the following namespaces Built-in names int, string, def, print, and so on Global names Declared as global and assigned at the top-level of a module Local names Assigned inside a...

XDR Data Exchange Format

XDR is best described as a standard for data description and encoding. It uses a implicit typing language to describe intricate data formats in a concise manner note that this language is not a programming language. Protocols such as Sun RPC Remote Procedure Call and the NFS Network File System, which was initially built on top of RPC use XDR to describe the format of their data because XDR is useful for transferring data between different computer architectures. XDR has been used to...

Index terms contained in this section Vdg

- pathname a2b hex function b2a hex function binascii module binhex inputfile, outputfile function generic conversion functions 2nd 3rd 4th 5th decode in file , out file , mode function deletefolder name method Ellinghouse, Lance encode in file, out file , name , mode function error format , method 2nd Folder mh, name method folder objects functions a2b hex b2a hex binascii module binhex module binhex inputfile, outputfile decode in file , out file , mode encode in file, out file , name , mode...

Handling Tkinter Events

Usually, when you create a graphical interface for your application, you want to handle all the possible events that happen there, such as reading in each key in the keyboard including the F1-F12 set, Ctrl, Alt, and Shift keys , tracking the actions upon the mouse button, or even controlling the window redraw events fired by the window manager. Tkinter handles that by allowing you to create bindings for every specific object. Actually, you can bind events to the widget instance itself, to the...

It executes a given function passing the arguments provided

basic syntax apply function, tuple of positional arguments , dictionary of keywords arguments gt gt gt apply raise_salary, 6000 , ,employee, ,JohnI, 'id' 13 gt gt gt a b c 10 gt gt gt string.atof s gt gt gt 20 lt x lt 40 gt gt gt x,y,z 5,4,3 gt gt gt a,b b,a Parallel assignment example 2 Note that starting at Python 1.6, the functionality of apply is now available with normal function calling, such as gt gt gt kwargs ,employee, ,John', 'id' 13 gt gt gt raise_salary args, kwargs coerce is used...

Ftp

FTP is a popular way to transfer files from machine to machine across a network. It is convenient because there are FTP clients and FTP servers written for all the popular platforms. FTP servers can work with both private users and anonymous users. The difference is that a private FTP server allows only system users to be able to connect via FTP, whereas an anonymous FTP server allows anyone on the network to connect to it and transfer files without having an account. Keep in mind that...

COM Interfaces

The COM technology is very broad and complex. Basically, it enables objects to be shared among many applications, without applications knowing the implementation details of the objects. Objects that implement the COM technology can communicate with each other without the need for knowing the others'details. COM components do business with interfaces. An interface defines functionality, but not implementation. Objects must handle the implementation. COM objects are small pieces of self-contained...

LJ Jj

Now, check out the code that works behind the scenes to organize the widgets Label root, text Last Name .grid row 0, sticky W Label root, text First Name .grid row 1, sticky W Label root, text Phone .grid row 2, sticky W Label root, text email .grid row 3, sticky W entry_ln Entry root entry_fn Entry root entry_ph Entry root entry_ln.grid row 0, column 1 entry_fn.grid row 1, column 1 entry_ph.grid row 2, column 1 entry_em.grid row 3, column 1 Label root .grid row 4, sticky W Label root, text...

string

The string module supports common string operations by providing several functions and constants that manipulate Python strings. This function splits a string into a list. If the delimiter is omitted, white-spaces are used. basic syntax string.split string ,delimiter gt gt gt print string,split a b c It converts a string to a floating number. basic syntax string.atof string string.atoi It converts a string to an integer. atoi takes an optional second argument base. If omitted, the start of the...

Stdwin

STDWIN stands for Standard Window Interface. It is a platform-independent interface to C-based window systems. Currently, STDWIN is obsolete and unsupported, without any further development effort being made. The stdwin module has been removed for Python 2.0. The Python people say that if you want to use stdwin, you should grab an older Python release. There is not really any reason you would want to use this toolkit. Python's stdwin module defines several new object types and functions that...

Protocols

The mechanism called protocol handler is responsible for the communication between the window manager and your application. Handling these protocols, you can intercept the messages provided by the system, and define exactly what you want to happen. Usually, the protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, and WM_SAVE_YOURSELF are the ones mostly used. For details about the other supported protocols, see the Inter-Client Communication Conventions Manual ICCCM at Although this convention was...

PyOpenGL

OpenGL is the premier environment for developing portable, interactive 2D and 3D graphics applications from modeling to scientific to games. Since its introduction in 1992, OpenGL has become the industry's most widely used and supported 2D and 3D graphics application programming interface API , bringing thousands of applications to a wide variety of computer platforms. OpenGL fosters innovation and speeds application development by incorporating a broad set of rendering, texture mapping,...

Index terms contained in this section Bns

sys.exec.tracebackQ sys.exec.valueQ sys.getrecursionlimitQ sys.last.valueQ sys.recursionlimitQ sys.version infoQ libraries sys module Python Services 2nd return code argument syntax sys.exitQ function sys module 2nd 3rd sys.exec.tracebackQ function sys.exec.valueQ function sys.getrecursionlimitQ function sys.last.valueQ function sys.recursionlimitQ function sys.version infoQ function 2002, O'Reilly amp Associates, Inc.

Tip Uew

Remember that you need to inform the new line character at the end of each command line to make sure that the interpreter validates the command. Py_Finalize Releases the internal resources and shuts down the interpreter. You should always call this function before leaving the program. PyRun_SimpleFile Executes Python commands that are stored in a file. This function reads from a FILE pointer. PySys_SetArgv int argc, char argv PyRun_SimpleString print 'Hello Python World' n PyRun_SimpleString...

Zope Web Application Server

The Z Object Publishing Environment, also known as Zope, is an open source object publishing system for the Web, developed by a company called Digital Creations. Zope is a complete dynamic Web site management Web platform used for building high-performance, dynamic Web sites. Essentially, it is a very complete framework for building Web applications, written in Python. Check out the following sites for details http www.digicool.com and http www.zope.org Zope is the leading Open Source...

Wpy

Wpy is a class library system, based on the Microsoft Foundation Classes, that is used for writing GUI code easily in Python. Wpy is designd for simplicity and portability. The Wpy Web site provides instructions about how to install the library and use it to run Python programs with windowing GUI capability on UNIX using Tk, Windows 3.1 16-bit native , and Windows 95, 98, and NT 32-bit native . The source code and the main standard binary ports are available for download. A Python Wpy Netscape...

Functions 1

The following list shows some general functions exposed by the cgi module. cgi.escape string ,quote Translates lt , amp , gt to amp lt , amp amp , amp gt . If you want to convert the double-quote character, you must set the quote flag to true. cgi.parse_qs string, keep_blank_values 0 Parses a query string such as country USA amp state PA to a dictionary-like format, for example, country USA , state PA , cgi.parse file , Parses query strings from default file locations such as, multiple file...

imaplib

The impalib module provides a low-level, client-side interface for connecting to an IMAP4 mail server using the IMAP4rev1 client protocol, as defined in the Internet standard RFC 2060. The nntplib module implements a low-level interface to the client side of the NNTP Network News Transfer Protocol protocol a service mostly known for implementing newsgroups. The smtplib module provides a low-level client interface to the SMTP protocol that can be used to send email to any machine in the Internet...

FXPy

FOX is a C based toolkit for developing GUIs easily and effectively. FOX runs on UNIX and Windows, and supports the LGPL kind of license. It offers a wide, and growing, collection of Controls and provides state of the art facilities such as drag and drop, selection, as well as OpenGL widgets for 3D graphical manipulation. FOX also implements icons, images, and user-convenience features such as status line help, and tooltips. Tooltips can even be used for 3D objects Considerable importance has...

Index terms contained in this section Kdk

passing data to CGI scripts from CGI Common Gateway Interface scripts 2nd 3rd cgi module Common Gateway Interface CGI scripts 2nd 3rd data passing from browsers to CGI scripts executing CGI scripts fork method GET method 2nd methods fork GET 2nd POST 2nd mod pyapache module mod python module modules cgi data from browsers to CGI scripts POST method 2nd processing Common Gateway Interface CGI 2nd 3rd transferring 2002, O'Reilly amp Associates, Inc.

Implementing COM Objects in Python

Python Form

In order to implement COM objects in the Python version of Windows, you need a set of extensions developed by Mark Hammond and Greg Stein. Part of the win32com package, these extensions enable you to do everything that is COM-related, including writing COM clients and COM servers. The following link takes you to the download page of these extensions All the Win32 extensions including the COM extensions are part of the win32all installation package. This package also installs the PythonWin IDE...

pyFLTK

FLTK Fast Light Tool Kit, pronounced fulltick is a C graphical user interface toolkit for X UNIX , OpenGL, and WIN32 Microsoft Windows NT 4.0, 95, or 98 . It is also largely compatible with the XForms library. FLTK is currently maintained by a small group of developers across the world with a central repository in the United States, and it is distributed under the GNU Library GPL LGPL . FLTK was originally created to build in-house applications at Digital Domain for image processing and 3D...