Features/GTK3/Porting: Difference between revisions
→Porting an exisiting activity to GTK3: rewrite and shorten intro, link GTK3, consistently use "GTK3", replace some pre tags with space |
|||
| Line 1: | Line 1: | ||
=Porting an | =Porting an existing activity to GTK3= | ||
This is a guide to porting an existing activity from GTK2 to [http://developer.gnome.org/gtk3/stable/ GTK3]. It also shows the changes to use the new Sugar toolkit that also now uses [[Features/GTK3|GTK3]]. This guide uses the [http://git.sugarlabs.org/hello-world hello-world] activity as a simple example. | |||
==Preparation== | ==Preparation== | ||
| Line 6: | Line 6: | ||
The latest release was version 3. We highly recommend that you use the 'sugar-0.94' as the stable branch name because this will keep the repositories consistent and eases the development work. In git you can create a branch like this: | The latest release was version 3. We highly recommend that you use the 'sugar-0.94' as the stable branch name because this will keep the repositories consistent and eases the development work. In git you can create a branch like this: | ||
git branch sugar-0.94 | |||
This creates a local branch, as you can see by running 'git branch'; you should see the following: | |||
This | |||
<pre> | <pre> | ||
| Line 19: | Line 16: | ||
</pre> | </pre> | ||
The 'sugar-0.94' branch is only locally | The 'sugar-0.94' branch is only available locally, as you can see by running 'git branch -r' which shows the remote branches: | ||
<pre> | <pre> | ||
| Line 53: | Line 50: | ||
* the old-style toolbar has been removed | * the old-style toolbar has been removed | ||
==Port the activity from | ==Port the activity from GTK2 to GTK3== | ||
To start, change the importing instruction for GTK from | |||
import gtk | |||
to | |||
from gi.repository import Gtk | |||
Then you have to change each call that involves Gtk, for example creating a button will look now like this: | Then you have to change each call that involves Gtk, for example creating a button will look now like this: | ||
button = Gtk.Button() | |||
A simple hello world program in | A simple hello world program in GTK3 looks like this: | ||
<pre> | <pre> | ||
from gi.repository import Gtk | from gi.repository import Gtk | ||
| Line 77: | Line 74: | ||
</pre> | </pre> | ||
For porting your activity you do have to change your calls for | For porting your activity you do have to change your calls for accessing widgets and services in the new GTK3 sugar-toolkit as well. The new namespace is called sugar3, trying to reflect that GTK3 is the underlying technology. For example the import of the base activity class has to be changed from | ||
from sugar.activity import activity | |||
to | to | ||
from sugar3.activity import activity | |||
The changes that were needed to port the hello-world activity can be seen in [http://git.sugarlabs.org/hello-world/mainline/commit/508e1c518b56cbde5508e560c8a2ff38a3518583 this commit]. | The changes that were needed to port the hello-world activity can be seen in [http://git.sugarlabs.org/hello-world/mainline/commit/508e1c518b56cbde5508e560c8a2ff38a3518583 this commit]. | ||