Posts

Showing posts from March, 2007

Custom PyGTK Widgets in Glade3: Part 2: Custom widget adaptors

In the last post about custom glade widgets, we briefly discussed how to add your PyGTK custom widgets to glade-3 so that they can be used in a user interface designer. In this post, this shall be extended to include how you can create a custom adaptor for a PyGTK widget to define additional behaviour. We shall be using a custom widget as an example, which I have called a "Service View". We plan that this widget has a content section, which is the main part, and also contains a close button at the bottom. We will use this widget as a general dockable view, kind of like a dialog which is a widget rather than a top-level window. This may seem utterly pointless, but it should be a useful component in an application that generates many different views in notebooks, like an IDE: Debugger, Terminal, Documentation Browser (etc). These can all share the same basic layout, but just replace the single main part of the widget. First let's write a widget: import gtk class ServiceView...

Custom PyGTK Widgets in Glade3

Glade 3, GTK User Interface Designer is really quite nice since release 3.1, since it does away with the gimp-like multi-window view and looks like a normal application. Another nice feature it has is being able to support widgets created in non-C (in our case PyGTK). Components of a plugin: A catalog file A support module Some icon pixmaps (optional) We shall use, for our example, the Kiwi Hyperlink widget, (which I wrote). This widget is an EventBox subclass, so we shall illustrate turning off some of the additional properties that are not required in the user interface designer. The catalog file This is described in http://glade.gnome.org/docs/catalogintro.html and the subsequent pages of the documentation. Essentially there are two sections of the catalog: The Widget definitions The Catalog list The Widget Definitions are like so: <glade-widget-classes> <glade-widget-class title="Hyper Link" name="HyperLink" /> </glade-widget-classes> These ar...

First Blog Post from the gblogger GUI

Image
The gblogger GUI lives! It features listing the blogs for a user, listing the posts for a blog, new blog posting, and blog editing. Wysiwyg is achieved using GTKHTML3, and I have barely formatted this post because formatted posts seem to give 400 posting errors! The client lacks category management, and image uploading, which remain on the TODO list. (Now I am tentatively pressing the save button...after which I will re-edit the blog in Blogger.com, and add some screenshots!)

Posting to Blogger.com from the command line

Well, you can tell I am procrastinating working today (but you can forgive me after the PIDA GSoc Application was rejected as a mentoring organisation), but I have hacked up an early version of a library (for Python) to manage blogger.com posting. I was becoming slightly upset with Blogger.com, since it does some insane things like puts BR tags in the middle of PRE elements, which meant the syntax highlighting script I wanted to use was going nuts. I also gradually realised that none of the blogging clients work with the "new Blogger.com" although for me (who has only been blogging a few months) it has been the "only Blogger.com". So, with a quick search around for documentation from code.google.com, I was able to discover that Blogger.com uses the google GData API with a bit of Atom mixed in. I have no real ideas about these specifications, but http://code.google.com/apis/blogger/gdata.html explains it. Note that another document I found: http://code.blogspot.co...

Using pexpect to control Django manage.py

In the early stages of developing a Django application, I was deleting my sqlite database, and rerunning: python manage.py syncdb Every few minutes as the database models were changing. You might consider this some kind of evil thing to do, because we should all have our database models in concrete before writing any code but I am not that organised. One thing that was really distressing me was the fact that each time I ran a syncdb, I had to enter details for my default admin user. Username Email address Password Repeart Password This was fine for the first 400 times, then I got bored. The solution was to use pexpect. (There are probably command line options that you can give manage.py, but finding them out would have been more effort than this hack) Pexpect, http://pexpect.sourceforge.net/ is a pure python module for running external commands and controlling them as if you were a user. It has good documentation, and is perfect for needs of this nature. A quick browse through the exc...

Unit Testing PyGTK

Unit testing a GUI has always been something that scares me, and scares other people too. Because of this there are about a gazillion tools that behave in different ways, for example in Python, just have a look at: http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy#GUITestingTools (Since the whole world is obsessed with Web Applications, and this is becoming perversely true even in Python circles, some of these GUI Testing tools are actually web testing tools, but never mind that.) How do I do it? Well, we may talk in another blog about one of those tools, the awesome hack that is kiwi.ui.test but it is slightly restrictive on what you want to do, and how you should do it. Specifically, it needs you to have every widget named (which is fine when testing Glade-created interfaces, but a pain when hand-building them). Enter this one function that I found in the kiwi source. Kiwi is LGPL (whatever that means, but you should read the license if you are going to use it). import time i...