Pages

Showing posts with label Event-handling. Show all posts
Showing posts with label Event-handling. Show all posts

Saturday, May 28, 2011

Basic Application

Alright, there's one thing you need to know about me: I'm quite stupid :) So I will start from the start and  play around with Kivy using basics and build up on that. NB: this post may be a bit redundant, Kivy offers a Quickstart already, from which I draw most of the content of this post.

First you'll have to install the Kivy library, there is an installation guide for Ubuntu as well (that's what I use). I've had some problems with the graphic library, preventing some examples included in the library to function. This is due to a bug, but luckily there is a patch to solve the issue for now. The patch's installation is quite long, but it's worth it :)

Then we're ready to start coding. Kivy's Quickstart offers a simple example to run:


Now you should not have problem running this on your system. You could do that from your terminal by running $ python ./main.py in the folder where you saved your Python file. Personally, I use Geany for coding, so I can run it from there. and you should see something like this on your screen:
The window is a black canvas with a large grey button (with rounded corners). The window decoration is not part of the coding and is taken care of by your Window Manager. There may be a way to prevent this decoration by changing a property of the Kivy application, I am not sure of that just yet, but it could also be done by addressing the WM directly (by setting window decoration rules in Compiz for instance).
You can hover and click the button like this:
Now don't forget Kivy is made to function on touch-screen technology, there are three touch events: Down, Move, Up. From what I understand, touch events are passed in a top-down fashion, i.e. from the top-level parent widget, to the children. When the touch-event matches a listener of any of the widgets standing in the way of that event, they will launch their respective callbacks. Events are better explained in the documentation. Down and Up touch-events each match two default event listeners of the Button widget, namely on_press() and on_release(). The default callbacks of the Button widget affect its appearance: the background changes from grey to blue.

If your application does not shut down, you may be affected by the bug mentioned above. Next post will pick up from here and try to tweak this basic application and see what more can be done with App() and Button().