WordPy 0.2 – Using XML to Save and Load Data

All right, so we have our base WordPy application running, so let’s try to extend it a bit more by letting you load and save blog posts to and from an xml file. Please note that this tutorial simply shows one method of saving and loading data using xml, there are many different methods and this method was chosen for its simplicity.

If you are unfamiliar with the first WordPy tutorial you should probably read it fist in order to have a better understanding of some of what happens in this tutorial.

You can download the complete code for this tutorial here.


The first thing we need to-do is open up the wordpy glade project and make some changes:

  1. We’ll start off by adding another item to our VBox in Glade. You can do this by holding down shift and clicking on the WordPy window until you see the GTKVBox come up in the properties window. Then simply change it’s size value from 4 to 5.
  2. In the empty space add a menu bar. Then on the Packing tab of the menu bar’s properties set the position to be zero, so that the menu is at the top of the window.
  3. Then edit the menu so that only the File, Edit, and Help menu’s remain.
  4. Add handlers to each of the files menu items: on_file_new, on_file_open, on_file_save, on_file_save_as

GLADE Window PyWine

The Code

That’s it for editing the GUI, now we have to go and edit the code. The first step is to connect all of the menu events with our code:

dic = {"on_wndMain_destroy" : self.quit
		, "on_btnBold_clicked" : self.on_btnBold_clicked
		, "on_btnItalic_clicked" : self.on_btnItalic_clicked
		, "on_btnLink_clicked" : self.on_btnLink_clicked
		, "on_btnBlockQuote_clicked" : self.on_btnBlockQuote_clicked
		, "on_btnDel_clicked" : self.on_btnDel_clicked
		, "on_btnIns_clicked" : self.on_btnIns_clicked
		, "on_btnImage_clicked" : self.on_btnImage_clicked
		, "on_btnUnorderedList_clicked" : self.on_btnUnorderedList_clicked
		, "on_btnOrderedList_clicked" : self.on_btnOrderedList_clicked
		, "on_btnListItem_clicked" : self.on_btnListItem_clicked
		, "on_btnCode_clicked" : self.on_btnCode_clicked
		, "on_btnMore_clicked" : self.on_btnMore_clicked
		, "on_btnSettings_clicked" : self.on_btnSettings_clicked
		, "on_btnpost_clicked" : self.on_btnpost_clicked
		, "on_file_new" : self.on_file_new
		, "on_file_open" : self.on_file_open
		, "on_file_save" : self.on_file_save
		, "on_file_save_as": self.on_file_save_as}
def on_file_new(self, widget):

def on_file_open(self, widget):

def on_file_save(self, widget):

def on_file_save_as(self. widget):

Continue reading WordPy 0.2 – Using XML to Save and Load Data

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