Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate gtk3 porting docs from wiki #150

Merged
merged 11 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/gtk3-porting-examples/Finance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Ticket of this port is [here](http://bugs.sugarlabs.org/ticket/3740), with some
useful information that I'm using on the porting and to keep tracking
this port.


Gtk.EventBox
============

EventBox has not `get_colormap` method anymore and this method is used
to set the background color. Now, instead of this one I'm using
`Gdk.Color.parse` to parse the color string:

`ebox = gtk.EventBox()`\
`ebox.modify_bg(gtk.STATE_NORMAL, ebox.get_colormap().alloc_color('#000000'))`

replaced by:

`ebox = Gtk.EventBox()`\
`parse, color = Gdk.Color.parse('#000000')`\
`self.helpbox.modify_bg(Gtk.StateType.NORMAL, color)`

Gtk.TreeViewColumn
==================

The callback function used by `Gtk.TreeViewColumn.set_cell_data_func`
receives a new argument called: *data*

`col = Gtk.TreeViewColumn(_('Description'), renderer)`\
`col.set_cell_data_func(renderer, self.description_render_cb) `

added a new argument to the function definition:

`def description_render_cb(self, column, cell_renderer, model, iter, data):`

Useful links
============

- <http://developer.gnome.org/gtk3/3.5/GtkTreeViewColumn.html#GtkTreeCellDataFunc>
- <http://developer.gnome.org/gdk3/stable/gdk3-Colors.html#GdkColor>
136 changes: 136 additions & 0 deletions src/gtk3-porting-examples/Implode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Ticket of this port is [here](http://bugs.sugarlabs.org/ticket/3715), with some
useful information that I'm using on the porting and to keep tracking
this port.


Porting Gtk.DrawingArea
=======================

There are some things related with `gtk.DrawingArea` that we have to
change when we are porting an activity to GTK+ 3. The names of the signals
change and the way that they work as well.

Get allocation size
-------------------

*self.allocation* property is no longer available and we should use
`self.get_allocation_width` to get the allocation size:

`self.allocation.width`\
`self.allocation.height`

should be replaced by:

`self.get_allocated_width()`\
`self.get_allocated_height()`

Signals
-------

### expose-event

This signal was override by **draw** and it have to be connected with
the method that was connected with the *expose-event* before. The method
itself does not change but the arguments that it receives do. This is
the new definition of the function in my case:

`def _draw_event_cb(self, widget, cr):`

### size-allocate

This signal was used to resize the gtk.DrawingArea every time the window
grows and at the startup of the activity. This is useful to re-draw the
widget for different resolutions (desktops and XOs for example).

I used the same function connected to this signal but I change the
signal connected by **configure-event**. Here is the definition of the
callback:

`def _configure_event_cb(self, widget, event):`

Focus
-----

Implode defines a new widget called *GridWidget* and it should be
focusable because we want to move a cursor with the key arrows on it.
So, this widget was using:

`self.set_flags(Gtk.CAN_FOCUS)`

but that method (*set\_flags*) is no longer available and we have to
replace it by:

`self.set_can_focus(True)`

Another thing related with the focus is to know who has the actual
focus. In gtk2 it was done by

`.focus_child`

and in GTK+ 3 it should be replaced by:

`.get_focus_child()`

Handling .svg with rsvg
=======================

**rsvg** is a library to manage *.svg* files. The only thing that I
found that should be updated is the import and the loading of a rsvg
from data.

Replace the usual import:

`import rsgv`

by the GTK+ 3 one:

`from gi.repository import Rsvg`

This way to load a rsvg from data should be replaced:

`rsvg.Handle(data=data)`

by this new way

`Rsvg.Handle.new_from_data(data)`

Invalidate rectangle
====================

`Gdk.Window.invalidate_rect` takes a *Gdk.Rectangle* instead a tuple in
GTK+ 3.

`rect = Gdk.Rectangle()`\
`rect.x, rect.y, rect.width, rect.height = (0, 0, width, height)`

`self.get_window().invalidate_rect(rect, True)`

Notes
=====

- I had to add a third argument (None) to Gtk.Notebook.append\_page
but I don't know why
- Use **json** instead of *simplejson* or so
- Replace `gtk.VISIBLE` by **Gtk.AccelFlags.VISIBLE**

Missing things (not ported yet)
===============================

- *sugarless.py* is not working. The board is not shown. Do we update
this to keep it working? I mean, do we need to maintain this code?
- \[<span style="color: green;">DONE</span>\] ~~help dialogue is not
working. It shows the example board but it's one pixel size when it
opens~~
- When the help dialogue is shown and you hover the animation with the
mouse something strange happens and it starts to flap.
[Screenshot](http://bugs.sugarlabs.org/attachment/ticket/3715/53.png)

Useful Links
============

- <http://developer.gnome.org/gtk3/3.5/GtkWidget.html#GtkWidget-draw>
- <http://developer.gnome.org/gtk3/3.5/GtkWidget.html#GtkWidget-configure-event>
- <http://developer.gnome.org/rsvg/stable/>
- <http://developer.gnome.org/gdk3/stable/gdk3-Windows.html#gdk-window-invalidate-rect>
- <http://developer.gnome.org/gtk3/3.5/GtkWidget.html#gtk-widget-get-allocated-width>
- <http://developer.gnome.org/gtk3/3.5/GtkNotebook.html#gtk-notebook-append-page>
Loading