maemo, project, top tip

Displaying a busy indicator on maemo python app.

This is the post I wish existed when I was looking for how to do this simple thing. I spent hours reading around trying to figure out how to show my app is busy, but to no avail. Lets first look at the 'why?'. So you've written yourself a python app for maemo, you've figured out how do do some interesting things and your little project is becoming really quiet useful. Having got it to go do some processing, you ralised that it was locking up the whole user interface whilst it ran, and so you have figured out threads. Everything is going great. The UI no longer freezes when the user presses the 'go' button. But there is a problem.

The time between the user hitting go, and your application having done it's thing is filled with the user staring at the UI wondering...'is it working? Did I hit the button enough? This is rubb...oh theres the response I guess that's ok then'

What you want is to show the user that you've registered their click and are busy working on it for them. Enter, the busy indicator... Everyone is familiar with this concept, little spinning wheels or hour glasses etc. So how do you do this in maemo?

My big mistake was thinking of it as a busy indicator, when I should of thought about it as a progress bar. Personally I think of these as two quiet different things. Lucky for me mwerle on the forums was a few steps ahead of me, and he found the answer in the pymaemo documentation under the section on progress bars. He then posted a comment on my witter thread letting me know. It is hard to explain how happy I am when someone helps me with a problem by giving me specific code examples. It makes my life so much easier, so I'm always really grateful.

It turns out to be as simple as: hildon.hildon_gtk_window_set_progress_indicator(dialog, 1)

Where 1 turns it on, and 0 turns it off. This puts a little spinning indicator into the title bar or your window/dialog whatever you pass in the first argument.

So simple when you know how.

Of course there is a little extra complication if you can have multiple threads, since you need to co-ordinate them setting/unsetting this indicator.

For witter I wrote a simple method every thread calls on entry and exit. On entry they call with a value of +1 on exit they call with a value of -1

def showBusy(self, increment, *args): #increment might be +1 or -1 to take the counter up or down self.busyCounter = self.busyCounter + increment print "running tasks: " + str(self.busyCounter) if (self.busyCounter > 0): #at least one thing running hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) else: #no more tasks busy hildon.hildon_gtk_window_set_progress_indicator(self.window, 0) #in case we missed it somewhere, no longer getting Tweets self.gettingTweets = False


Simply it counts how many active threads there are. And whilst that's not 0 it sets the busy indicator on.

Hopefully this post will help the next developer save some time.