Putting the Squeeze on Python Application Development
Application development for Linux is, without question, a wide open opportunity. Some might say Linux has everything a person would need to get virtually any job done.
Developing custom applications for Linux is tells a different story. Microsoft's Visual Studio Integrated Development Environment (IDE) offers a wealth of tools for serious application development and deployment. A number of fine development tools do exist for Linux, but none of them seem to have the comprehensive level of features and support available from Microsoft.
Language choice is one area where Linux excels. You can find versions of most any computer programming language available for Linux. Python, for example, is ubiquitous on virtually every Linux distribution as well as Mac OS X. It's also available for all versions of the Windows operating system as a free download. Python is a mature language with many industry heavyweights, like Google, focusing a significant amount of attention and support in current and future versions.
The main Python site has a wealth of information about the language itself--tutorials, application domains, and links to additional information. Under the Success Stories link you'll find a large number of projects that have used Python as their language of choice. Of particular interest is the vast number of scientific applications using Python and third-party modules to solve complex problems.
A well-known example of Python in action is the One Laptop Per Child (OLPC) project. Sugar is the name of the primary user interface for the OLPC project, and it is written entirely in Python. At the core of Sugar is Python version 2.5 and PyGTK, a Python wrapper for the C-based GTK+ windowing toolkit. Another good example of a Python/GTk application is the update manager in Ubuntu.
Why Python
Eric Raymond wrote an article back in 2000 entitled “Why Python?” that articulated his venture into using Python for a number of programming tasks he needed to accomplish. Python has many uses, but it is really good at automating mundane tasks. While some may use Perl or a simple Linux shell script, Python brings an elegance and readability that many of these other solutions can't deliver.
One of the biggest reasons for using Python is the enormous amount of user-contributed code. A quick Google search with Python and the specific problem you're trying to solve will produce many pages of results. SciPy is a repository of open source Python software for mathematics, science and engineering. It is widely used in the university research community and counts NASA's Jet Propulsion Laboratory (JPL) as one of its sponsors.
Python is also being used in many universities as a first language for new computer science students to teach them the fundamentals of programming. In Python everything is an object, making it an ideal language to help students learn object-oriented concepts from the start. It also comes with a command line interpreter, making it easy to try out simple instructions and get immediate feedback. As a result, there is a small army of recent graduates with strong Python skills waiting to put them to good use.
The Python language has a rich set of native data types. Some of these will be new to many developers coming from a C or C++ background. For example, the list data type provides a standard way of handling a list of items. The individual items are in turn any supported Python type including another list. Python's dictionary data type is defined in the documentation this way: "These represent finite sets of objects indexed by nearly arbitrary values."
Learning Python
For those outside of the university environment, there is a wealth of resources to learn Python. Both Google video and YouTube have hundreds of tutorials with varying levels of quality. ShowMeDo is another resource for tutorials and screencasts.
You'll find a good listing of learning resources on the Python.org website. Learning about the standard Python library and the available modules will help give you a big head start on what you can do with the language. One of the better web resources to help with this task is the eff-bot guide to the Standard Python Library. This resource, although a little dated, is available in book form from O'Reilly and on the web as a PDF download. It provides a wealth of examples to demonstrate the various features of the standard library. It also does a good job of providing real-world problems solved with Python code.
One of the first things you'll learn about Python early on is that white space matters. Python uses line indentation as a part of the program structure. This mandatory formatting helps to make Python code much more readable. Using a good visual editor will help keep you straight here.
Building Desktop Applications
Python plays very nicely with a number of Graphical User Interface (GUI) tools for Linux application development. Glade is one GUI-builder tool that Python interfaces with. Glade uses GTK+ (The GIMP Toolkit) as the foundation for all elements needed to create a typical application. PyGTK is a Python wrapper that functions as a go-between to marry the Python programming language and the C-based GTK+ libraries.
One of the concepts you'll need to master when learning to build applications with Python / GTK+ is the concept of widgets and signals. Every user interface item in a GTK+ window is a widget and has a number of signals attached to it. For example, a simple button will have a signal for when the user clicks on it. Each signal must in turn have a handler in Python code to take the proper action in response to the user's input.
GTK+ uses the basic design principle of containers. Each user application is basically one or more containers with widgets placed inside. Containers give the programmer a way of separating things like menus, toolbars, and other elements in a logical manner. By default, each container will scale proportionately when a user resizes the application window.
When you run the Glade tool you will be presented with three separate windows. A widget pallet displays all available elements you can use in your application. The properties window displays specific properties for a selected widget and is where you manually edit things like the name of the item. A design canvas window provides a surface for use in creating the actual user interface design.
GTK+ widgets can also be created on the fly with code. This is quite useful for modal windows such as a dialog box or a file selector. These windows appear, take input from the user and then disappear. The output of a Glade design is basically an XML document. Each node in the XML document represents a widget in the application.
Final Thoughts
This article has barely scratched the surface of the Python language and developing applications based on Python. Other GUI toolkits do exist that you can use in conjunction with Python including Qt from Trolltech. Qt has had some licensing issues in the past causing some open source developers to avoid it although the company was recently acquired by Nokia and does offer versions under the GPL.
Python is a fun language to learn and program in. It's a good language to learn for beginning programmers and for experienced ones as well. Python's cross platform capability makes it a good choice for any application that needs to run on any operating system.


