WordPy offline blogging tool

Topics covered in this tutorial:

  • Glade
  • PyGTK
  • gtk.FileChooserDialog
  • gtk.FileFilter
  • gtk.TextView
  • gtk.TextBuffer
  • gtk.TextMark
  • gtk.MessageDialog

You can download the full source for this tutorial here.

One of the things that I found the other day while I was surfing the web looking for information on Python was this WordPress Python library. Since I use WordPress for this site I thought that I’d play with it a bit. The result is this tutorial about using the WordPress library, PyGTK, and Glade.

The first think to do is download the library, extract it form the archive, and install it. Enter the following on the command line in the directory you downloaded the library to in order to install it:

python setup.py install

Now you have the library installed. The next step is to create the GUI that we will use to interact with the library. The GUI will be created using Glade, if you are new to Glade or PyGTK you might want to read over my two turorials on the subject: Creating a GUI using PyGTK and Glade and Building an Application with PyGTK and Glade.

Continue reading WordPy offline blogging tool

Writing a Custom Widget Using PyGTK

One of the things that I wanted to add to my simple PyWine application was an easy way for people to rate their wine. There were lots of different ways to do it but since I was looking for a tutorial to write I decided that I wanted to do it the way that you rate songs in iTunes. If you’ve never used iTunes before, you can rate songs on a sliding scale from zero to five using stars. It basically functions like a slider or a Horizontal Scale except that when drawing it’s not a line, it’s a row of stars.

Python PyGTK Windows

The full source for this tutorial can be downloaded here.

The three the most useful links that I found on this subject were: A song for the lovers, the writing a widget turotial on the PyGTK website, and the widget.py example in the PyGTK cvs.

The skeleton of the following code will be mostly based off of the widget.py example, but since this example will try to accomplish a bit more there will be some extra code. In order to understand this tutorial better I suggest you give widget.py a couple of reads.

The starting point is a file names starhscale.py which starts off with some rather standard python stuff:

#!/usr/bin/env python

try:
	import gtk
  	import gobject
  	from gtk import gdk
except:
	raise SystemExit

import pygtk
if gtk.pygtk_version < (2, 0):
  	print "PyGtk 2.0 or later required for this widget"
  	raise SystemExit

Continue reading Writing a Custom Widget Using PyGTK

Just a quick post before I leave

I’ve been meaning to do this for a while but simply couldn’t find the time up until right before I leave on my trip. Here is a quick screenshot of my last tutorial running on Windows:

Python PyGTK Windows

Since I’ve been showing mostly Mac and Linux screenshots I thought I’d post a Windows just to balance things out a bit more.

Well, I’m off…happy programming everyone!

Building an Application with PyGTK and Glade

After working with PyGTK and Glade for my first tutorial, I decided to write another more complex tutorial but I couldn’t think of a topic (Note: If you have any suggestions for any tutorials or posts I’d love to hear them) so I decided to work on creating a simple application and hopefully useful topics would arise from there.

The idea I came up with (which will hopefully be simple) is to create a program that will allow me to keep track of the different types of wine that I drink and how much I like them. It’s something I’ve wanted to write for a while so I thought it would be good to combine learning PyGTK and doing it.

I’m going to call the project PyWine. The full source and Glade file for this tutorial can be found here

The first thing to do is start a new Glade project in the projects directory called PyWine. Create a new Window, call it “mainWindow,” and set the title to be “PyWine”. Then add a handler to the destroy signal just like in the first tutorial.

Next I add a Vertical Box to the Window with 4 rows, (from top to bottom) one row for a Menu bar, one row for a Toolbar, one row for a Tree or List View, and the final row for a Status Bar. Name the Tree View “wineView”

Python Glade

Continue reading Building an Application with PyGTK and Glade

Creating a GUI using PyGTK and Glade

After spending some time creating a GUI using TKinter and having it be pretty easy, but getting frustrated by how linked my code and the GUI was, I decided to look into creating a GUI using another toolkit. After looking around at the options for a while I settled on using PyGTK and Glade

The reason I decided upon using these two technologies is because they are cross platform and using GLADE satisfies my wish to separate the code form the GUI.

If you’ve never heard of Glade before, it’s “a User Interface Builder for GTK+ and GNOME”. It generates XML files which describe the desired GUI.

I’ll let the pyGTK website describe what PyGTK is:

PyGTK provides a convenient wrapper for the GTK+ library for use in Python programs, taking care of many of the boring details such as managing memory and type casting. When combined with PyORBit and gnome-python, it can be used to write full featured Gnome applications.

So there you go, I’m writing this on my freshly installed Debian system. If you are running Debian, or a Debian based distribution getting PyGTK and Glade is pretty simple:

apt-get install python-gtk2 python-glade2

Now lets create our first simple GUI, this is what you will be greeted with when you first start GLADE:

Python RSS Reader

Continue reading Creating a GUI using PyGTK and Glade