Features/GTK3/Porting: Difference between revisions
No edit summary Tag: visualeditor-switched |
|||
| Line 1: | Line 1: | ||
=Porting an existing activity to GTK3= | =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 [ | 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 [https://github.com/sugarlabs/hello-world hello-world] activity as a simple example. | ||
There is another guide | There is another guide that uses this one as reference. It was made while porting GetBooks Activity [[Features/GTK3/Porting/GetBooks]] | ||
If you would like to reference other examples of GTK3 port: | If you would like to reference other examples of GTK3 port: | ||
* [https://github.com/sugarlabs/biorhythm/commit/c16de3b70cce2cc6f8af933e2b062c844a47c144/ Biorhythm] | * [https://github.com/sugarlabs/biorhythm/commit/c16de3b70cce2cc6f8af933e2b062c844a47c144/ Biorhythm] | ||
* [https://github.com/sugarlabs/peru-learns-english-activity/commit/caa2cde526b3823a5a1f7d200a76ad5bc3502b0e Peru Learns English, includes GStreamer and GST update] | * [https://github.com/sugarlabs/peru-learns-english-activity/commit/caa2cde526b3823a5a1f7d200a76ad5bc3502b0e Peru Learns English, includes GStreamer and GST update] | ||
==Cleanup, adopt to API changes in sugar-toolkit-gtk3 == | ==Cleanup, adopt to API changes in sugar-toolkit-gtk3 == | ||
* the keep button has been removed completely | * the keep button has been removed completely | ||
* the old-style toolbar has been removed | * the old-style toolbar has been removed | ||
* | * set_toolbar_box is used instead of set_toolbox (see in [http://git.sugarlabs.org/~walter/abacus/walter-cairo/commit/6871dd340a89ade3b5361457e1bd1d58276a8efc Abacus]) | ||
* remove import of deprecated ActivityToolbox (see [http://git.sugarlabs.org/hello-world/mainline/commit/22060a3063b2d6fd38d6b1cd8d44946170255af3 hello-world]) | * remove import of deprecated ActivityToolbox (see [http://git.sugarlabs.org/hello-world/mainline/commit/22060a3063b2d6fd38d6b1cd8d44946170255af3 hello-world]) | ||
* support for 'service_name' and 'class' has been removed from the activity.info make sure you are using: 'bundle_id' instead of 'service_name' and 'exec' instead of 'class' (see in [http://git.sugarlabs.org/record/mainline/commit/6e8968c71e474e2d8d86886badf5cf7d70217dc5 Record]) | * support for 'service_name' and 'class' has been removed from the activity.info make sure you are using: 'bundle_id' instead of 'service_name' and 'exec' instead of 'class' (see in [http://git.sugarlabs.org/record/mainline/commit/6e8968c71e474e2d8d86886badf5cf7d70217dc5 Record]) | ||
| Line 66: | Line 19: | ||
import gtk | import gtk | ||
to | to | ||
import gi | |||
gi.require_version('Gtk', '3.0') | |||
from gi.repository import Gtk | from gi.repository import Gtk | ||
Note that require_version needs to called only the first time when Gtk is being imported. | |||
Here are some more examples of imports that may be used: | Here are some more examples of imports that may be used: | ||
<pre> | <pre> | ||
from gi.repository import Gdk, Pango, Gobject | from gi.repository import Gdk, Pango, Gobject | ||
| Line 293: | Line 243: | ||
GdkPixbuf.Pixbuf.new_from_file() | GdkPixbuf.Pixbuf.new_from_file() | ||
== | ==Releasing activities (for maintainers)== | ||
Once an activity is ported, a new release can be made. The major version should be greater than the existing one. | |||
Please follow [https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md#checklist---maintainer this] guide for releasing a new version | |||
==Port to Python 3== | |||
We are migrating towards Python 3. Python 3 does not support GTK+ 2. Hence, once the activity is ported to GTK+ 3, please also continue porting the activity from Python 2 to Python 3. | |||
Ref: [https://github.com/sugarlabs/sugar-docs/blob/master/src/python-porting-guide.md Guide to port activities to Python 3] | |||
== Tips to Activity Developers == | == Tips to Activity Developers == | ||
| Line 516: | Line 453: | ||
== Resources == | == Resources == | ||
PyGI Documentation: https://lazka.github.io/pgi-docs/ | |||
gtk2: http://www.pygtk.org/docs/pygtk/ | |||
* Reference Manual | * Reference Manual | ||
:: Gtk3: http://developer.gnome.org/gtk3/3.4/ | :: Gtk3: http://developer.gnome.org/gtk3/3.4/ | ||