Creating your First Sugar Activity
Make A Standalone Python Program First
The best advice I could give a beginning Activity developer is to make a version of your Activity that can run on its own, outside of the Sugar environment. Testing and debugging a Python program that stands alone is faster, easier and less tedious than doing the same thing with a similar Activity. You'll understand why when you start testing your first Activity.
The more bugs you find before you turn your code into an Activity the better. In fact, it's a good idea to keep a standalone version of your program around even after you have the Activity version well underway. I used my standalone version of Read Etexts to develop the text to speech with highlighting feature. This saved me a lot of time, which was especially important because I was figuring things out as I went.
Our first project will be a version of the Read Etexts Activity I wrote.
Inherit From The sugar.activity.Activity Class
Next we're going to take our standalone Python program and make an Activity out of it. To do this we need to understand the concept of inheritance. In everyday speech inheritance means getting something from your parents that you didn't work for. A king will take his son to a castle window and say, "Someday, lad, this will all be yours!" That's inheritance.In the world of computers programs can have parents and inherit things from them. Instead of inheriting property, they inherit code. There is a piece of Python code called sugar.activity.Activity that's the best parent an Activity could hope to have, and we're going to convince it to adopt our program. This doesn't mean that our program will never have to work again, but it won't have to work as much.
Package The Activity
Now we have to package up our code to make it something that can be run under Sugar and distributed as an .xo file. This involves setting up a MANIFEST, activity.info, setup.py, and creating a suitable icon with Inkscape.
Every Activity will have the basic Activity toolbar. For most Activities this will not be enough, so we'll need to create some custom toolbars as well. Then we need to hook them up to the rest of the Activity code so that what happens to the toolbar triggers actions in the Activity and what happens outside the toolbar is reflected in the state of the toolbar.
In addition to toolbars we'll look at some other ways to spiff up your Activity.
Put The Project Code In Version Control
By this time we'll have enough code written that it's worth protecting and sharing with the world. To do that we need to create a Git repository and add our code to it. We'll also go over the basics of using Git.
Going International With Pootle
Now that our code is in Git we can request help from our first collaborator: the Pootle translation system. With a little setup work we can get volunteers to make translated versions of our Activity available.
Distributing The Activity
In this task we'll take our Activity and set it up on http://activities.sugarlabs.org plus we'll package up the source code so it can be included in Linux distributions.
Next we'll add code to share e-books with Friends and the Neighborhood.
Add Text To Speech
Text to Speech with word highlighting is next. Our simple project will become a Kindle-killer!