Maemo 5: Basic gesture support in python


Once I got witter to the point that it had multiple views, I immediately wanted to have a nice way to switch between those views. In the first instance I just used buttons which have the advantage of being able to go direct to the view you want, but at the cost of screen space to show the button. Or alternatively needing to go via menus to get to the buttons.
Enter ‘gestures’ I wanted to be able to swipe left or right to switch views, much like on the multi-desktop of the N900. So I did some searching and eventually found reference to gPodder which is also written in python and introduced swipe gestures.

So i dug around the source and found that essentially they capture the position of a ‘pressed’ event and the position of the ‘released’ event and calculate the difference. If it’s over a certain threshold left or right then they trigger the appropriate method.

This seemed reasonable enough, but I couldn’t figure out what object was emitting those signals. As I looked into it I found something better.
The hildon pannableArea emits signals for horizontal scrolling and vertical scrolling. And it does so regardless of whether it will actually scroll.

What this means is that for witter, I use a pannableArea to do kinetic scrolling of the treeview which shows the tweets. There is no horizontal movement, but I can use the following:


pannedWindow.connect('horizontal-movement', self.gesture)

Then in the method gesture I get:


def gesture(self, widget, direction, startx, starty):

    if (direction == 3):
        #Go one way
    if (direction == 2):
        #Go rthe other

those numbers do have constants associated, but I haven’t figured out where I am supposed to reference them from, so I’m just using the numbers.

The cool thing about this is that it is quite selective about what constitutes horizontal movement. Going diagonally left and up or down does NOT trigger this signal.

So it’s a pretty nice way to switch between views. Now I need to figure out how to do the cool dragging of views like the desktop, rather than just a straight flip of views.


Leave a Reply

Your email address will not be published. Required fields are marked *