Features/GTK3/Porting: Difference between revisions
m edit grammar |
→Porting an existing activity to GTK3: Added more extra information Tags: Mobile edit Mobile web edit |
||
| Line 6: | Line 6: | ||
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] | |||
==Preparation== | ==Preparation== | ||
| Line 72: | Line 73: | ||
gi.require_version('Gtk', '3.0') | gi.require_version('Gtk', '3.0') | ||
from gi.repository import Gtk | from gi.repository import Gtk | ||
</pre> | |||
Here are some more examples of imports that may be used: | |||
<pre> | |||
from gi.repository import Gdk, Pango, Gobject | |||
</pre> | </pre> | ||
| Line 233: | Line 239: | ||
Additionally, PyGTK accepted these construction parameters as positional arguments. As explained above, they must now be converted to keyword arguments. | Additionally, PyGTK accepted these construction parameters as positional arguments. As explained above, they must now be converted to keyword arguments. | ||
=== Gtk Menu Popup === | |||
The Gtk.Menu.popup function now works slightly differently. | |||
The user supplied positioning function now takes different parameters. These are menu, x, y, push_in and user_data. | |||
=== Gdk === | === Gdk === | ||
| Line 266: | Line 277: | ||
Most of the constants have slightly different formats, e.g., | Most of the constants have slightly different formats, e.g., | ||
gtk.STATE_NORMAL became Gtk.StateFlags.NORMAL | |||
gtk.RESPONSE_ACCEPT became Gtk.ResponseType.ACCEPT | |||
gtk.JUSTIFY_CENTER became Gtk.Justification.CENTER | |||
gtk.RELIEF_NONE became Gtk.ReliefStyle.NONE | |||
=== Pixbufs === | === Pixbufs === | ||
| Line 361: | Line 374: | ||
# Handle the expose event | # Handle the expose event | ||
# "expose" became "draw" for the cairo signal | |||
def do_expose_event(self, event): | def do_expose_event(self, event): | ||
# Create the cairo context | # Create the cairo context | ||
| Line 457: | Line 471: | ||
The get_extents() method if different in PangoCairo. It calculates an extent as a Rectangle, but doesn't return anything. There is a method, get_logical_extents() that returns a Rectangle. Alas, it is not necessarily available after v1.16. Note that Rectangle is not a list but a class with methods for get_x(), get_y(), get_width(), and get_height(), so you cannot iter over it. | The get_extents() method if different in PangoCairo. It calculates an extent as a Rectangle, but doesn't return anything. There is a method, get_logical_extents() that returns a Rectangle. Alas, it is not necessarily available after v1.16. Note that Rectangle is not a list but a class with methods for get_x(), get_y(), get_width(), and get_height(), so you cannot iter over it. | ||
Note that the <samp>cairo.Region</samp> will no longer work in Gtk+3 | |||
==== Replacing pixmaps with Cairo ==== | ==== Replacing pixmaps with Cairo ==== | ||