[sugar] adapting a gnome app to sugar
Owen Williams
ywwg
Wed Sep 13 16:54:25 EDT 2006
I develop a GNOME application called PenguinTV
(http://penguintv.sourceforge.net) and I've been working with Marco to
help get it running on Sugar. I used the wiki tutorial
(http://wiki.laptop.org/go/Sugar_Activity_Tutorial) to get myself
started, but I thought I would post some of the other things I learned
along the way. I hope this is useful for other developers who may be
new to Sugar or autotools.
The biggest difference between a regular application and a Sugar
application is that with a Sugar app, you don't have a window. You only
have a container widget into which you put your application widgets.
Because of this, if a program uses the GnomeApp widget, you don't get
the menus, toolbar, or status bar.
I had to adapt my application in a few ways. First, instead of one
glade window that holds the whole app, I created two glade windows:
* one for the gnomeapp window, with a container widget for the
application contents
* one for all the application contents.
When I load my application the normal way, I load the main window and
then plug the application contents into it (this is simplified code):
app_widget_tree = gtk.glade.XML(gladefile,'app','penguintv')
app_window = app_widget_tree.get_widget('app')
dock_widget = app_widget_tree.get_widget('dock_widget')
components = gtk.glade.XML(gladefile,'layout_container','penguintv')
layout_container = components.get_widget('layout_container')
dock_widget.add(layout_container)
Note that "layout container" isn't the window in the glade file. I just
use the window to hold the widgets. If I'm running under sugar, I can
skip the app_window initialization and just plug the layout_container
into the activity widget.
Second, I had to go through my code and find places where I had assumed
a window exists. For me this just meant places where I get or set the
window size.
I don't know anything about autoconf or any of those tools, so the
little tutorial on autogen.sh and all that was very helpful. Here are a
few things I learned:
A Makefile only works in the current directory. Any directory that has
files that will be installed must have its own Makefile.am (which will
become a Makefile). All of the Makefiles must be listed in
configure.ac:
AC_OUTPUT([
Makefile
share/Makefile
penguintv/Makefile
penguintv/ptvbittorrent/Makefile
])
For every directory that has subdirectories that have installable files,
you need to list the subdirectories in the Makefile.am. I know this is
really basic stuff, but as I said I didn't know anything -- I'm used to
python's distutils.
SUBDIRS = share penguintv
the rest was pretty easy -- activity_PYTHON lists the files to be
copied, and activitydir is where they will go. I don't have to bother
with distutils or compiling the code myself.
The activity file was a little tricky. Unlike the example, my
application requires a lot of initialization and shutdown code, so I
can't just pop in a widget and do "show". I create an instance of my
application and run it as usual. But I also connect the activity's
destroy signal to a little function that takes my app as an argument:
self.connect('destroy',self.do_quit, app)
When the widget is destroyed, I call my shutdown code (which cleans up
threads, etc). HOWEVER, I found I _also_ have to specifically delete the
app object
del app
or else it doesn't start up again properly -- even though I instantiate
a new version of my app every time. I don't know if this is my fault or
a bug in Sugar or Python, but that's my workaround.
That was all I needed to do to get my application to work correctly. I
will still need to create new widgets to replace my missing menus,
toolbar, and status bar, but that's just adventures in glade and basic
signal connection. The application as a whole works correctly.
hope this was interesting,
Owen
More information about the Sugar-devel
mailing list