Have you ever run into a problem where your favorite Python IDE can't determine the type of a variable, and thus you get no auto-completion? There is a built-in function in Python called isInstance(your_variable, type_of_variable) that is designed to compare a variable to a class type, and return true or false. However, just the presence of this function will give many IDEs all the information they need to determine the type of your variable, and thus give you better auto-completion.

For example, imagine you had a function that returned a gtk.Window.
MyWindow = GetMyWindow()

Most IDEs would not correctly determine the type of MyWindow. To solve this, try the following code:

MyWindow = GetMyWindow()
isInstance(MyWindow, gtk.Window)

There are many articles that point out the dangers of using isInstance, however if you are simply using it like my example, it shouldn't cause any problems.


There comes a time in every man's life where a single goocanvas.Canvas widget just won't cut it. Imagine you need two separate canvases for your interface, but you want them to scroll together with a single scroll bar. How would you solve this problem?

First, to enable a goocanvas.Canvas object to scroll is very easy (or so it would seem). Simply drop it into a gtk.ScrolledWindow widget, and you're done. As long as the boundary of your canvas exceeds the size, the scroll bars will work.

The Problem...

However, don't get too excited. A scrolledWindow widget that has a goocanvas.Canvas object as a child will not bubble up any scroll signals / events. So, if you have another canvas on the window, you will have no luck trying to synchronize up the scrollbars. Or if you want only part of the canvas to scroll, and part to remain fixed, this will not work.

The Solution...
Place two canvas objects next to each other. Place a vertical and horizontal scroll bar where you want them to appear. Create a signal handler for the scroll events, and use the Canvas.scroll_to(x, y) method to manually scroll both canvases.

Example Code:
Here are the signal handler functions for the 2 scroll bars to synchronize the scrolling of 2 goocanvas.Canvas objects:

def on_vscrollbar1_value_changed(self, widget):
isinstance(widget, gtk.VScrollbar)
vertical_value = widget.get_value()

# Get horizontal value
horizontal_scrollbar = self.frmMain.get_widget("hscrollbar1")
horizontal_value = horizontal_scrollbar.get_value()

# scroll the canvases
self.MyCanvas.scroll_to(horizontal_value, vertical_value)
self.MyCanvas_Left.scroll_to(horizontal_value, vertical_value)

def on_hscrollbar1_value_changed(self, widget):
isinstance(widget, gtk.HScrollbar)
horizontal_value = widget.get_value()

# Get vertical value
vertical_scrollbar = self.frmMain.get_widget("vscrollbar1")
vertical_value = vertical_scrollbar.get_value()

# scroll the canvases
self.MyCanvas.scroll_to(horizontal_value, vertical_value)

A picture is worth a thousand words:
Here are 2 similar screens using a goocanvas.Canvas object. Notice the horizontal scroll bar placement on them (at the bottom of the screen). The 2nd screen has an offset scroll bar, which will only scroll that half of the Canvas. Pretty cool!

Screen 1 - Using a single goocanvas.Canvas and a gtk.ScrolledWindow widget:

Screen 2 - Using two goocanvas.Canvas objects and individual scroll bar widgets:


As you know, I am creating a complex timeline for my non-linear video application. I had the choice between the GnomeCanvas (which is obsolete) and a lesser known goocanvas (which is cairo based). I originally choose to use the GnomeCanvas, because it is much more well known, and there is more documentation for it.

After working with the GnomeCanvas in Python for many hours, something became very apparent, the Python bindings for the GnomeCanvas are incomplete and buggy. For example, CanvasGroups are not supported, they throw an exception when used. CanvasPixbuf objects don't expose all of their properties, such as the pixbuf property. So, once you create a CanvasPixbuf, there is no way to change the image. Arghhh!

I have now switched my focus to the goocanvas library, and things are going much better. I hope to have a release of my timeline demo in the next 2 weeks (still lots left to complete).


I have a new favorite Python IDE, and it's the Wingware IDE. That's right folks, the Eclipse IDE (with PyDev) does an admirable job, as well as The Eric Python IDE, but neither are as impressive as Wingware. From this point forward, I dumping the other IDEs and going 100% with Wingware.

Why Wingware?
There are many reasons to like Wingware over other Python IDEs. Here are a few of my favorite features:

  • Source Assistant - This not only describes the current method, module, or variable but also shows you all the expected parameters, shows the __doc__ string, and in many cases links to the official website for the library method (for example, the GTK methods).

  • Great Code Completion - The code completion feels much more complete (and faster loading) than other IDEs. For example, working with the GTK library was a breeze, where as I have struggled using Eclipse... In most other Python IDEs they support limited code completion, but without showing the list of expected parameters. That sucks when you are working with an unknown library. Not a problem anymore!

  • Easy Debugger - The debugger is very similar to Visual Studio (which I have used for years). I found the debugger much easier to step into code, analize the locals and stack data, and they even have a cool tool called a "Debug Probe", which is an immediate window that lets you interact with the current stack data (and includes code completion).

  • Perforce Support - I am a huge Perforce (source control software) fan. Any product that integrates with Perforce sounds like my kind of product. Seriously, I will be using Perforce to manage the source code in my video editor project.

  • Wingware Supports Open-Source - Most supprising, the Wingware company fully supports non-commercial open-source projects, and if you meet their requirements (which I did), they will issue a FREE license. Thanks guys!


Here is a quick update for everyone following this project. I am working on an prototype timeline, using the Gnome canvas, GTK, and Python. So far my "prototype first" methodology seems to be playing out nicely. It is allowing me to quickly test out various libraries, GUI techniques, and design patterns, while allowing me to focus on very specific parts of the application.

The timeline prototype contains the following features:

  • Multiple Tracks
  • Ability to add variable-length video clips (i.e. 30 secs, 1 min, 2 min)
  • Drag 'n Drop video clips
  • Ability to split video clips and move their individual pieces around
  • A Zoom Slider (to adjust the zoom of the timeline)
I will continue to share updates as I develop this prototype, and I hope to have some screenshots available soon.


I never thought licensing free software would be so interesting. Before I start releasing more source code, I figured it was time to understand what the Free Software Foundation and GPL (General Public License) is all about. So here are my thoughts about licensing free software:

Why Even Bother?
To write software and not license it opens the door for corporations or businesses with money (more money than you) to take your source code, redistribute it with their name on it, removing credit from you (the developer), and profiting off of your work. Most people would agree that even free software needs to be licensed and copyrighted.

What License Should I Use?
Once you've decided to license your source code, their are a ton of licensing choices. Many types of licenses make sense for various types of software. For a free, open-source software project, the GNU GPL (version 3) makes a lot of sense. However, their are 2 main variations of the GPL that you should consider:

The main difference between these two licenses is the LGPL license can be freely modified by anyone, and doesn't require the modifications (i.e. modified source code) to be re-distributed. It's perfectly legal to only distribute the binaries from your changes, and never share your source code. Why is this dangerous? Because it allows proprietary versions of your software to be released, and thus you no longer have a "free" software product.

The main selling point of GPL (over other licenses) is your code can be freely modified by anyone, and even redistributed by anyone, but any public release of any version of your software (by anyone) must make the source code available. It's also perfectly fine for someone to sell a version of a GPL software product, however they must make the source code available, and they must not charge extra for the source code.

What about GStreamer?
The GStreamer library is unique, in that it uses many non-free, proprietary codecs. If your software wants to use this library, it will be in violation with the GPL (version 3). What does the GStreamer team recommend? They recommend adding an exception clause to your GPL similar to this example:
"The EXAMPLE project hereby grants permission for non-GPL compatible GStreamer plugins to be used and distributed together with GStreamer and EXAMPLE. This permission is above and beyond the permissions granted by the GPL license by which EXAMPLE is covered. If you modify this code, you may extend this exception to your version of the code, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version."
Are There Any Other Licenses?
Of course, there are many open-source licenses to consider, not just the GNU GPL. The Open Source Initiative (OSI) has a comprehensive list of OSI approved licenses for you to consider.


Just to be clear, I am no lawyer, and I strongly recommend you speak to a lawyer if you are interested in licensing an open-source project, especially if it uses libraries that contain non-free software. Also, there are many great resources on the Internet related to this topic, so head to Google and start learning.

Subscribe to: Posts (Atom)