If you are following Sugar development (and of course you are!) you know that we are almost done removing hippo in our path towards Gtk3 and the new (introspected) world. The nice thing is that there are many other less invasive improvements that can be achieved before we get there. One of them, extensively explained and documented by the never at rest Daniel Drake, is the ability to ship a secondary gtk3-enabled Sugar Toolkit for all the cool kids out there that are looking forward to write nice and fresh activities. This also means you get access to all the other introspection goodies out there, most notably access to the latest WebKit bindings.
As a warm up for the Gtk3 hackfest starting tomorrow, I wanted to go over what we last did at the Desktop Summit along with Benjamin Berg to obtain a gtk3-enabled Sugar Toolkit. So here is what was done to port sugar-toolkit to Gtk3:
Converting the Toolkit to Gtk3
- run pygi-convert.sh provided by the pygi community to automatize migration to gtk3 as much as possible
- the script isn’t perfect so you’ll have to add a couple of imports (GObject and Gdk) here and there by hand
- set_geometry_hints is broken, comment it out
- use Gtk.Menu instead of sugarext.Menu
- GtkAlignment doesn’t take named parameters anymore
- use get_window () instead of self.window
- vborder/hborder in Gtk.Notebook note recognized
- pack_start() doesn’t take implicit params anymore
- Gtk.Label#size_request() new type of return value
- Gtk.icon_size_lookup and size-request have new API
- sugarext: avoid using sugarext.GsmClientXSMP
In any case, my ported branch is here: http://cgit.collabora.com/git/user/rgs/sugar-toolkit/log/?h=gtk3
Renaming the ported sugar-toolkit (s/sugar/sugar1/g)
Because we intend to ship two versions of the Toolkit, for gtk2 and gtk3, we need different namespaces. So we go ahead and rename ’sugar’ to ’sugar1′ with an incantation along the lines of:
find -iname "*.py" | xargs sed -si 's/sugar/sugar1/g'
Ship it!
Before installing the new Toolkit you might wanna a save a copy of the original (gtk2) Toolkit so it doesn’t get overwritten. This can be done via:
cd /path/to/sugar-jhbuild/install/lib/python2.7/site-packages/
mv sugar sugar-gtk2
And then to install the new Toolkit:
cd /path/to/sugar-jhbuild/source/sugar-toolkit
make install
and finally do some renaming so each Toolkit can be find in the proper location:
cd /path/to/sugar-jhbuild/install/lib/python2.7/site-packages/
# make the installed Toolkit the alternate (new) one
mv sugar sugar1
# restore the original Toolkit
mv sugar-gtk2 sugar
Finally, a small hack to sugar-activity so it imports the correct toolkit
by replacing /path/to/sugar-jhbuild/source/sugar/bin/sugar-activity:
import sugar
with:
import os
if os.path.exists("GTK3"):
from sugar1.activity import main
else:
from sugar.activity import main
Now you should be able to seamlessly run both gtk2 and gtk3 activities!
Embrace gtk3!
So here is a quick gtk3 activity (CrazyTurtle) i wrote while thinking and exploring how would
porting TurtleArt to gtk3 go. You can find the source code: http://cgit.collabora.com/git/user/rgs/CrazyTurtle.activity/.
Run it!
Lets give our new gtk3 activity a try:

A couple of obvious things to be fixed:
- no theming (go benzea, go!)
- palettes are broken
- testing needed
The Future
Other cool stuff that might come on top of this is a new version of Browse (or Surf?) that is fully gtk3/webkit enabled along with many new and shiny HTML5 apps. There is also a whole world of opportunities around gtk3. One of the things that made me wonder about cool stuff we might explore is Alex Larsson's new broadway backend for Gdk. I can't come up with any immediate use from within Sugar but it is good to know what possibilities are available out there.
vborder/hborder in Gtk.Notebook note recognized