Activity tutorial: Difference between revisions

From OLPC
Jump to navigation Jump to search
(Traduccion 1)
Line 3: Line 3:
<< [[Tutorials]]
<< [[Tutorials]]


This tutorial explains step by step how to create the Hello World Activity bundle. You can [http://divieira.googlepages.com/HelloWorld-1.xo download a completed .xo package], though the package will not exactly match the below contents.
Este tutorial explica paso a paso como crear la '''Actividad Hola Mundo''' en un conjunto. Puedes [http://divieira.googlepages.com/HelloWorld-1.xo descargar un paquete completo .xo], aunque el paquete no sera exactamente identico al que esta a continuación.


This tutorial assumes you have read the [[Developers|Developer's Manual]], have [[Developers/Setup|installed a Sugar development environment]] and wish to use the [[Developers/Setup#Python/PyGTK|PyGTK]] development approach (the standard approach to developing activities for the OLPC).
Este tutorial asume que has leido el [[Developers|Manual del Desarrollador]], has [[Developers/Setup|instalado un ambiente de desarrollo de Sugar]] y deseas desarrollar en [[Developers/Setup#Python/PyGTK|PyGTK]] (el estandar de desarrollo para actividades en OLPC).


== Getting started ==
== Comenzando ==
*Crea una estructura de directorios:
*Create the bundle directory structure:


mkdir -p HelloWorldActivity.activity/activity
mkdir -p HelloWorldActivity.activity/activity


*Write the <tt>activity.info</tt> file, to describe your bundle in the activity sub-directory (e.g. <tt>HelloWorldActivity.activity/activity/activity.info</tt>). The [[Activity Bundles]] specification explain in detail the meaning of each field.
*Escribe el archivo <tt>activity.info</tt>, para describir el conjunto dentro del sub-directorio de una actividad (e.g. <tt>HelloWorldActivity.activity/activity/activity.info</tt>). La especificación del [[Activity Bundles]] explica en detalle el significado de cada campo.
**Note: in a joyride-1525 build, sugar could not locate the icon when I tried this unless I removed the '.svg' extension from the 'icon = activity-helloworld.svg' line.
**Nota: en la compilación joyride-1525, sugar no pudo localizar el icono cuando intente esto asi que elimine la extension '.svg' de la linea 'icon = activity-helloworld.svg'.


{{ Box File | activity.info | 2=<pre>
{{ Box File | activity.info | 2=<pre>
Line 27: Line 27:
}}
}}


*Design an icon for your activity by following the instructions on [[Making_Sugar_Icons | making icons for Sugar]] and place it in the activity sub-directory. The file name should match the icon file name specified in the info file (e.g. <tt>activity-helloworld.svg</tt>). The contents of the SVG file will look something like:
*Diseña un icono para la actividad siguiendo las instrucciones en [[Making_Sugar_Icons | creando iconos para Sugar]] y ponlo en el subdirectorio de la actividad. El nombre del archivo debe ser igual al nombre del archivo de icono especificado en el archivo de información (e.g. <tt>activity-helloworld.svg</tt>). El contenido del archivo SVG se vera así:


{{ Box File | activity-helloworld.svg | 2=<pre>
{{ Box File | activity-helloworld.svg | 2=<pre>
Line 43: Line 43:
}}
}}


*Write the <tt>setup.py</tt> script in the top level directory (e.g. <tt>HelloWorldActivity.activity/setup.py</tt>), which in most cases will look like this:
*Escribe el script <tt>setup.py</tt> en el directorio raíz (e.g. <tt>HelloWorldActivity.activity/setup.py</tt>), el cual en muchas ocaciones se vera de esta forma:


{{ Box File | setup.py | 2=<pre>
{{ Box File | setup.py | 2=<pre>
Line 52: Line 52:
}}
}}


Una versión avanzada, la cual soporta la creacion de actividades sin Sugar previamente instalado, se vera de esta forma:
A more advanced version, which supports building activity bundles without Sugar installed, looks like this:


{{ Box File | setup.py | 2=<pre>
{{ Box File | setup.py | 2=<pre>

Revision as of 04:31, 18 May 2011

  english | 日本語 | 한국어 | português | español HowTo [ID# 256189]  +/-  


<< Tutorials

Este tutorial explica paso a paso como crear la Actividad Hola Mundo en un conjunto. Puedes descargar un paquete completo .xo, aunque el paquete no sera exactamente identico al que esta a continuación.

Este tutorial asume que has leido el Manual del Desarrollador, has instalado un ambiente de desarrollo de Sugar y deseas desarrollar en PyGTK (el estandar de desarrollo para actividades en OLPC).

Comenzando

  • Crea una estructura de directorios:
mkdir -p HelloWorldActivity.activity/activity
  • Escribe el archivo activity.info, para describir el conjunto dentro del sub-directorio de una actividad (e.g. HelloWorldActivity.activity/activity/activity.info). La especificación del Activity Bundles explica en detalle el significado de cada campo.
    • Nota: en la compilación joyride-1525, sugar no pudo localizar el icono cuando intente esto asi que elimine la extension '.svg' de la linea 'icon = activity-helloworld.svg'.
 File: activity.info
 [Activity]
 name = HelloWorld
 bundle_id = org.laptop.HelloWorldActivity
 class = HelloWorldActivity.HelloWorldActivity
 icon = activity-helloworld
 activity_version = 1
 host_version = 1
 show_launcher = yes
  • Diseña un icono para la actividad siguiendo las instrucciones en creando iconos para Sugar y ponlo en el subdirectorio de la actividad. El nombre del archivo debe ser igual al nombre del archivo de icono especificado en el archivo de información (e.g. activity-helloworld.svg). El contenido del archivo SVG se vera así:
 File: activity-helloworld.svg
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
   <!ENTITY stroke_color "#666666">
   <!ENTITY fill_color "#FFFFFF">
 ]>
 <svg xmlns="http://www.w3.org/2000/svg" width="55" height="55">
   <rect x="5" y="5" width="45" height="45"
   style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5"/>
 </svg>
  • Escribe el script setup.py en el directorio raíz (e.g. HelloWorldActivity.activity/setup.py), el cual en muchas ocaciones se vera de esta forma:
 File: setup.py
 #!/usr/bin/env python
 from sugar.activity import bundlebuilder
 bundlebuilder.start()

Una versión avanzada, la cual soporta la creacion de actividades sin Sugar previamente instalado, se vera de esta forma:

 File: setup.py
 #!/usr/bin/env python
 try:
 	from sugar.activity import bundlebuilder
 	bundlebuilder.start()
 except ImportError:
 	import os
 	os.system("find ./ | sed 's,^./,HelloWorldActivity.activity/,g' > MANIFEST")
 	os.system('rm HelloWorldActivity.xo')
 	os.chdir('..')
 	os.system('zip -r HelloWorldActivity.xo HelloWorldActivity.activity')
 	os.system('mv HelloWorldActivity.xo ./HelloWorldActivity.activity')
 	os.chdir('HelloWorldActivity.activity')
  • Code your activity in Python. The name you specified in the .info file as "class" is the name of the class which runs your code. For the activity.info file above, we specify a top-level module named HelloWorldActivity.HelloWorldActivity (please note that the use of uppercase names in module names is considered poor Python style, feel free to use an activity name with more standard style names).
 File: HelloWorldActivity.py
 from sugar.activity import activity
 import logging
 
 import sys, os
 import gtk
 
 class HelloWorldActivity(activity.Activity):
     def hello(self, widget, data=None):
         logging.info('Hello World')
 
     def __init__(self, handle):
         print "running activity init", handle
         activity.Activity.__init__(self, handle)
         print "activity running"
 
         # Creates the Toolbox. It contains the Activity Toolbar, which is the
         # bar that appears on every Sugar window and contains essential
         # functionalities, such as the 'Collaborate' and 'Close' buttons.
         toolbox = activity.ActivityToolbox(self)
         self.set_toolbox(toolbox)
         toolbox.show()
 
         # Creates a new button with the label "Hello World".
         self.button = gtk.Button("Hello World")
     
         # When the button receives the "clicked" signal, it will call the
         # function hello() passing it None as its argument.  The hello()
         # function is defined above.
         self.button.connect("clicked", self.hello, None)
     
         # Set the button to be our canvas. The canvas is the main section of
         # every Sugar Window. It fills all the area below the toolbox.
         self.set_canvas(self.button)
     
         # The final step is to display this newly created widget.
         self.button.show()
     
         print "AT END OF THE CLASS"

The above file is called HelloWorldActivity.py

  • Create a MANIFEST (e.g. HelloWorldActivity.activity/MANIFEST), containing the list of the files (relative to the directory that the MANIFEST is in) to include in the package. (Note: Be sure not to leave blank lines at the end of the file.) This script does that in linux (run it from within the HellowWorldActivity.activity directory):
cd HelloWorldActivity.activity
find . -type f | sed 's,^./,,g' > MANIFEST
  • Your directory structure should now look like this:
HelloWorldActivity.activity/
HelloWorldActivity.activity/setup.py
HelloWorldActivity.activity/activity
HelloWorldActivity.activity/activity/activity.info
HelloWorldActivity.activity/activity/activity-helloworld.svg
HelloWorldActivity.activity/HelloWorldActivity.py
HelloWorldActivity.activity/MANIFEST
  • Make sure that all your python files have the required permissions to be used.
chmod a+x setup.py
chmod a+x HelloWorldActivity.py
  • Setup your bundle for development (must be user olpc when you do this) to become user olpc, type: su - olpc

If you are prompted for a password, trying using: su

python setup.py dev

This just creates a symlink to your activity folder in ~/Activities, so that Sugar can find your activity.

  • Restart Sugar using Ctrl-Alt-Erase and your activity will appear in the interface! (NOTE: By default, the Home view shows only the favorite activities. You should press Ctrl+2 or go the right-upper corner and change to the List View)
  • Run your activity, and if there are errors use the Log viewer activity to see what went wrong.

Running

If you now run sugar the activity icon should be visible on the frame. (You have to restart sugar to get it to pick up the change if you just installed it. Hit ctrl-alt-erase.)

You can also edit the code in your bundle directory directly. Note that the first time your Activity is launched, it leaves a process around even if you close the window, so you must kill the sugar-activity-factory to get it to reload when you click again.

Distribution

Create a .xo package to distribute your bundle. (An .xo file is essentially a zip file built from the MANIFEST with some extra metadata, like a JAR file. It also has some localization ability, and in the future we expect to be able to sign these too.) The bundle name is automatically generated from the 'name' and 'activity_version' values found in the activity.info file, separated by a dash, with a .xo extension.

 ./setup.py dist_xo

To install the xo on a laptop you can use the installer script.

 sugar-install-bundle HelloWorld-1.xo

Trouble Shooting

You can find application logs in /home/olpc/.sugar/default/logs. If the sample fails to compile, sugar will show you the icon in the circle but remain forever at the "Starting..." tag when you hover your mouse over it. You'll have to restart sugar with <ctrl-alt-erase> in order to remove the icon. You can find the cause of your trouble in the the log named for the "service-name" in your activity.info file, in this case "org.laptop.HelloWorldActivity".

See also