PyLan a GTD todo application written in python and PyGTK – part three

PyLan three

Hello welcome to the long-time-coming third article in this tutorial. I apologize to everyone (anyone?) that was waiting for it. I have been very busy as of late and have had much of my time taken up by a few other python projects, that I hope to be able to show you all soon.

If you want to follow along with the code in detail, and have not done so already, you should read part one and part two of this series.

Python GTD pyGTK

You can download the full source to this tutorial here.

This tutorial will teach you the following things:

  1. How to construct a simple theme engine, or at least how I would, hopefully it will give you some ideas!
  2. How to display icons in a gtk.TreeView
  3. How to catch the selection event in a gtk.TreeView.
  4. How to enable or disable widgets.
  5. How to remove the selection from a gtk.TreeView if the user clicks on the gtk.TreeView but not on a tree item.

Continue reading PyLan a GTD todo application written in python and PyGTK – part three

PyLan a GTD todo application written in python and PyGTK – part two

PyLan two

This is part two of the PyLan tutorial series, if you want to follow along with the code in detail, and have not done so already, you should read part one of this series.

In this tutorial I will go over the following items:

This tutorial is organized into the following sections:

  1. The GUI
  2. The todo.Task Object
  3. Adding a todo.Task object
  4. Showing the Calendar window
  5. Editing todo.Category and todo.Task items
  6. Pango markup in the gtk.TreeView
  7. Conclusion

Python GTD pyGTK

You can download the full source to this tutorial here.

Continue reading PyLan a GTD todo application written in python and PyGTK – part two

PyLan a GTD todo application written in python and PyGTK – part one

Introduction

All right, many of you have probably heard of, or read, David Allen’s book Getting Things Done if not it’s a pretty interesting book about how to organize the things in your life.

As I was reading it I thought that a simple todo list could be created using Python and PyGTK pretty easily, so I decided to create the application and write a tutorial surrounding it. Since the actual application is quite large I have decided to break it up into a series of tutorials, each highlighting a few specific tasks. The full goal of this series is to show everything that is required when creating a python/PyGTK based application, for the GUI setup all the way to distribution.

These tutorials assume that you have a basic knowledge of python and PyGTK. If you have not already done so it is recommended that you take a look at some of my previous PyGTK based tutorials as I will be glossing over much of that which is explained there:

PyLan – part one

Python GTD pyGTK

So the application that we will be creating will be called PyLan, pronounced: plan. In brief it will be used to create a tree of tasks that can be organized into categories and subcategories.

You can download the full source to this tutorial here.

Part one of this tutorial will introduce you to the idea of the application and create the basic shell for it. It will outline the following:

Continue reading PyLan a GTD todo application written in python and PyGTK – part one

Translating your Python/PyGTK application

In this tutorial we will go over the (very) basic steps that you can use in order to translate (localize or internationalize) your PyGTK application. For this tutorial we are going to use the PyWine application that we have been working with in two previous tutorials:

The full source and necessary files for this tutorial can be downloaded here.

Python translation

Creating our Portable Object Files

In order to translate our text we are going to use the gettext module. The gettext module is basically a wrapper for the GNU gettext utility whose documentation can be found here.

The first step is to edit our python file (pywine.py)and “mark” all of the strings that we want to translate in our python code. To do this we will use the _(“xxx”) standard that most people use to mark strings that need to be translated. Otherwise in situations like the following:

#Get the treeView from the widget Tree
self.wineView = self.wTree.get_widget("wineView")

“wineView” might be thought of as a string to be translated when it clearly should not be. So we need to go through the .py file and wrap each of my English strings in _(). Here are all of the strings that need to be marked in their marked form:

self.sWine = _("Wine")
self.sWinery = _("Winery")
self.sGrape = _("Grape")
self.sYear = _("Year")
self.show_error_dlg(_("Error opening file"))
self.show_error_dlg(_("Error opening file"))
file_dialog = gtk.FileChooserDialog(title=_("Select Project")
filter.set_name(_("pyWine database"))
filter.set_name(_("All files"))

The next step is to generate the Portable Object Template file using the command line gettext utility. If you are using Linux or OS X this should be no problem and gettext will probably already be installed. If you are using Windows the tools are available as .exe files from the GNU gettext FTP or this gettext for Win32 sourceforge project.

Continue reading Translating your Python/PyGTK application

Novemeber

Hi everyone just a quick post to let you know that I probably won’t be posting much during this month as I have decided to participate in nanowrimo which leaves me almost no time to come up with tutorials.

I as mentioned in the past Satoshi Tanabe over at satolog has translated a few of my tutorials over into Japanese, which is very cool. It also turns out that someone over at blog.chinaunix.net has also translated one of my tutorials (Building an application with PyGTK and Glade) into Chinese, again very cool! Thanks a lot for the translations guys.

I’ve also been working on some pyGame in my spare time over the last few months, I’ve been working on a level editor and a widget set:

PyGame Window

Of course that doesn’t show very much but it show show my scrollbars! The problem with building the level editor is that y you always have to keep working on the smallest details (like a scrollable area0 before you can get to the real heart of the problem. Oh well it’s till fun!

Talk to you all soon!

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 GUI

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}
self.wTree.signal_autoconnect(dic)
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

Extending our PyGTK Application

In this tutorial we are going to extend our PyWine application to allowing you to edit the items that you have added to the list and save an load the wine lists you create so that you don’t have to keep entering them in all the time.

You can download the complete code for this tutorial here.

If you are not familiar with the PyWine application or with working with Glade and PyGTK I suggest you read my first two tutorial on the subject:

The GUI – Glade

The first thing that we are going to do is open up out PyWine glad project and add an edit button to our toolbar:

  1. Make space for the Edit button by selecting the toolbar and settings its size property to 2.
  2. Add a Toolbar Button in the newly created empty space.
  3. Call the button btnEditWine, set its label to be “Edit Wine”, and its icon to be the stock Edit icon. Next add a handler for the clicked event.
  4. We’re going to change the menu up a little bit, instead of a menu that says Add | Wine, we are going to set the menu up to read Wine | Add and Wine | Edit. Do this just like we did in the previous PyWine tutorial and make the Wine | Edit clicked handler the same function as your btnEditWine button’s clicked event handler.

GLADE Window PyWine

Continue reading Extending our PyGTK Application

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

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