Changes

Jump to navigation Jump to search
147 bytes removed ,  02:14, 18 November 2011
→‎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 exisiting activity to GTK3=
+
=Porting an existing activity to GTK3=
In this guide we will handle the porting of the an existing activity from using GTK2 to use GTK3. Furthermore we will show you what changes you need to do to make usage of the new sugar toolkit that uses now GTK3 as well. In this guide we will use the [http://git.sugarlabs.org/hello-world hello-world] activity as a simple example.
+
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
   −
<pre>
+
This creates a local branch, as you can see by running 'git branch'; you should see the following:
git branch sugar-0.94
  −
</pre>
  −
 
  −
This has created a local branch. You can show the result by running 'git branch', you should see the following:
      
<pre>
 
<pre>
Line 19: Line 16:  
</pre>
 
</pre>
   −
The 'sugar-0.94' branch is only locally available so far which can be seen by running 'git branch -r' which shows the remote branches:
+
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 GTK-2 to GTK-3==
+
==Port the activity from GTK2 to GTK3==
The first thing that changes is the importing instruction for GTK,
+
To start, change the importing instruction for GTK from
<pre>import gtk</pre>
+
import gtk
has to be replaced by
+
to
<pre>from gi.repository import Gtk</pre>
+
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:
<pre>button = Gtk.Button()</pre>
+
button = Gtk.Button()
   −
A simple hello world program in GTK-3 does look like this:
+
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 accesing 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
+
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
<pre>from sugar.activity import activity</pre>
+
from sugar.activity import activity
 
to
 
to
<pre>from sugar3.activity import activity</pre>
+
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].

Navigation menu