[Sugar-devel] Introducing SimpleActivity / Introduciendo SimpleActivity

Agustin Zubiaga Sanchez aguz at sugarlabs.org
Thu Nov 21 20:19:51 EST 2013


= English (Español debajo) =

Hi everyone,

I am writing to show you what I was developing those last days, in order to
make simpler the developing of Sugar Activities, this module, micro library
or whatever you want to call it, makes much more easier the processes that
every activity does, for example create ToolButtons, add them to a Toolbar
or implement collaboration which is difficult for any starter developer.
The main idea is include SimpleAcivity in our toolkit, but thinking about
all the review processes it takes, you can add it to your activity for now
or you can take a look about how it works in the Demo activity I did [1],
where you can see how easy is to implement sharing or create the toolbar.

* SimpleActivity classes *

simpleactivity.SimpleActivity:
The activities which doesn't want to implement collaboration, can derive
from this class (instead of sugar3.activity.activity.Activity), this class
automatically adds the toolbar to the activity with his
ActivityToolbarButton and it makes easier some processes related to the
design, e.g. add buttons, separators, or whatever to the toolbar in only
one line and also other things related to the operation for example any
number, string, dictionary or list that is saved into the self.data
variable will be auto kept in the journal, and when the instance runs
again, in self.data will be what you leaved when the activity was closed.
Among these there are many other simple features, that after all, they do
everything much easier.

simpleactivity.SharedActivity (derives from SimpleActivity, you can use all
its methods): :
>From this class should derive every activity which needs to be shared, the
process is greatly simplified cause the communication is done automatically
and the "system" works with something like an event manager, so we only
need to worry about register our events in a python dict, where the keys
are the names of the events and the values are the functions to call when
we receive an event, and when we want to "emit" an event with the values we
need or not, all we have to do is to call send_event(event_name, data)...
And that's all, we don't have to worry about telepathy, dbus or anything
like that, SimpleActivity does everything for you :)
Also it includes an option to send files in a very easy way, using the
method send_file(file_path, data) that notifies every peer that a file is
available, and it can be downloaded just calling the download_file method,
and then SharedActivity will start emiting signals with information related
to the download progress, etc.
The process of downloading is done using another independent tube, then
nothing gets blocked while the file is sent/downloaded, we can continue
sending events while, and everything will continue working.

Notes:
- Both classes derives from the "natives" classes of sugar, so we can
continue using every method of sugar.activity.activity.Activity or
whatever, without any problem.
- Whole SimpleActivity (module) is only one .py file, then we can put it
into our activity directory easily as we do with HelpButton or
FontComboBox, even if it isn't in sugar toolkit.
- It only supports GTK3, I think it is not necessary to make it compatible
with GTK2, because nowadays the new activities should be did in GTK3.
- I advice everyone who is interested to take a look of the documentation
that you can found in the docstrings in the file for now (I will create a
cleaner documentation with sphinx), to learn about all you can do with
SimpleActivity.

Also I started a Feature wiki page [2], but is not ready yet. Could anyone
help me with that?
I need some documentation experts ;)

I hope you find it useful, as I always say, I love developing for Sugar,
because it causes a great feeling to know that the lines of code I wrote
will be used directly or indirectly by millions of children around the
world.

[1] https://git.sugarlabs.org/simpleactivity/
[2] http://wiki.sugarlabs.org/go/Features/SimpleActivity

Thank you very much,
aguz

-
= Español =

Hola a todos,

Les escribo para presentarles lo que he estado desarrollando estos últimos
días, con el fin de hacer más simple la creación de actividades para Sugar,
este modulo, micro librería, o como quieran llamarle, hace mucho más fácil
los procesos que todas las actividades hacen, como crear ToolButtons,
agregarlos a una Toolbar o implementar colaboración para cualquier
desarrollador que esté comenzando.
La idea principal es incluir SimpleActivity en la toolkit de sugar, pero
tomando en cuenta todos los procesos de revisados que lleva, pueden ver
como funciona en el repositorio de la actividad de ejemplo
HelloSimpleActivity [1], que implementa un montón de características, y
donde pueden ver lo fácil que es implementar la colaboración o hacer la
barra de herramientas.

* Clases de simpleactivity *

simpleactivity.SimpleActivity:
Las actividades que NO deseen implementar colaboración, pueden simplemente
heredar de esta clase (en lugar de sugar3.activity.activity.Activity), esta
clase agrega automáticamente la toolbar a la actividad con su
ActivityToolButton, y simplifica varios procesos relacionados con el diseño
por ejemplo agregar botones, separadores (o lo que sea) a la toolbar en una
sola linea y también otros de funcionamiento como por ejemplo cualquier
numero, string, diccionario o lista que se guarde, en la variable
self.data, al cerrar la actividad esta lo guardará automáticamente en el
journal y al abrir otra vez esta instancia de nuestra actividad, en
self.data estará lo que allí dejamos.
Entre estas hay muchas otras características simples, que al fin y al cabo,
hacen todo mucho más fácil.

simpleactivity.SharedActivity (hereda de SimpleActivity, puedes usar
támbien todos sus metodos):
De esta clase deben heredar todas las actividades que deseen implementar
colaboración, el proceso se simplifica enormemente, ya que la comunicación
la hace toda automática, el "sistema" funciona con una especie de manejador
de eventos, por lo que solo debemos de preocuparnos por registrar nuestros
eventos en un diccionario de python, donde las claves son los nombres de
los eventos y los valores son las funciones a llamar cuando alguien nos
envie ese evento, y cuando deseamos emitirlos con los valores que
necesitemos o no (simpleactivity se encargara de notificar a cada maquina y
enviar a todos los datos) simplemente llamamos a una función
send_event(nombre_evento, datos)... Y listo! No debemos preocuparnos por
telepathy, dbus ni nada por el estilo, SimpleActivity hace todo por ti :)
Además incluye la opción de enviar archivos de una manera muy fácil,
utilizando un metodo send_file que avisa a todas las demás maquinas, que
hay un archivo disponible y podemos acceder a descargarlo simplemente
llamando la función download_file y SharedActivity comenzará a emitir
señales con información acerca del progreso de descarga, etc.
El proceso de descarga de archivos se hace por un tubo aparte por lo cual,
nada se bloquea mientras el archivo se envia/descarga, podemos seguir
enviando eventos sin problemas mientras lo hacemos, y todo seguirá
funcionando.

Notas:
- Ambas clases heredan de las clases nativas de sugar, por lo cual podemos
utilizar todos los métodos de  sugar3.activity.activity.Activity o lo que
sea que deseemos, sin ningún problema.
- SimpleActivity (módulo) es en su totalidad un solo archivo .py por lo que
podemos incorporarlo en nuestra actividad muy fácilmente, así como lo
hacemos con HelpButton o FontComboBox, aunque aún no esten en sugar toolkit.
- Soporta solo GTK3, creo que no es necesario dedicarnos a hacer una
versión compatible con GTK2, porque hoy en día las actividades nuevas se
deben hacer desde el inicio con GTK3.
- Recomiendo a todos los interesados revisar la documentación que está en
docstrings en el archivo por ahora, (proximamente armaré una documentación
más prolija con sphinx), para enterarse de todo lo que se puede hacer con
simpleactivity.

Además comencé con una pagina en la wiki [2], pero todavía no está lista.
¿Alguien quiere ayudarme con eso?
Necesito ayuda de los expertos en documentación ;)

Espero que les sea útil, como siempre digo, me encanta desarrollar para
Sugar, porque me provoca un sentimiento inexplicable saber que las lineas
de código que escribo van a ser utilizadas directa o indirectamente por
millones de chicos al rededor del mundo.

[1] https://git.sugarlabs.org/simpleactivity/
[2] http://wiki.sugarlabs.org/go/Features/SimpleActivity

Muchas gracias,
aguz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20131121/590e5db2/attachment-0001.html>


More information about the Sugar-devel mailing list