[Sugar-devel] Port to Gtk3: Gdk.Image error

James Cameron quozl at laptop.org
Sun Feb 9 18:24:40 EST 2020


Thanks for working on this.

I'm looking forward especially to your porting of the C++ code in this
activity, as that will be critical to success of the porting.

For reference, the issue you are working is
https://github.com/sugarlabs/Bounce/issues/7

My further reply in context below.

On Sun, Feb 09, 2020 at 03:27:10AM +0530, Abhishek Tanwar wrote:
> I am porting BOUNCE ACTIVITY (https://github.com/sugarlabs/Bounce)
> to Gtk +3 and I have ported it to some extent but I am stuck at a
> point where I am not able to find a solution.

https://github.com/sugarlabs/Bounce/pull/13 is a pull request work in
progress that contains a similar change from gtk.gdk.Image to
Gtk.Image, but pygi-convert.sh from the GNOME project (which I've
reviewed just now) does not make such a change as you and @tonadev
have made.

So my first question is why this change was made.  It looks like a
guess.  It looks wrong.

An instance of gtk.gdk.Image is an area for bit-mapped graphics stored
on the X Windows client.  It is not a widget.

https://developer.gnome.org/pygtk/stable/class-gdkimage.html

An instance of Gtk.Image is a widget for showing an image.  It is not
an image storage class.

https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Image.html

So it doesn't seem likely that this change from gtk.gdk.Image to
Gtk.Image is correct.  These are two very different levels of the
software stack.

> Here is the link to my repository for BOUNCE activity :
> https://github.com/abhishektanwar/Bounce

Thanks.  I was unable to understand the pattern of changes you've
made; the commit messages were vague and short.  I don't know which
changes happened because of pygi-convert.sh, sugar-convert.sh, or your
own edits.  I don't know why you made those edits.

https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md#making-commits
has our advice on writing commit messages.

You have also committed the conversion scripts.  Please don't do that,
we don't need the scripts in the activity.

> I know that Gdk.Image is no more supported in Gdk3 and I have to use
> Cairo or Pixbuf but can't figure out how to convert it to Cairo.
> 
> Traceback (most recent call last):
>   File "/usr/share/sugar/activities/Bounce.activity/bounce.py", line 1634, in on_drawarea_expose
>     self.on_drawarea_resize()
>   File "/usr/share/sugar/activities/Bounce.activity/bounce.py", line 1623, in on_drawarea_resize
>     self.drawimage = Gdk.Image(Gdk.IMAGE_FASTEST, Gdk.visual_get_system(), rect.width, rect.height)
>   File "/usr/lib/python2.7/dist-packages/gi/overrides/_init.py", line 39, in __getattr_
>     return getattr(self._introspection_module, name)
>   File "/usr/lib/python2.7/dist-packages/gi/module.py", line 139, in _getattr_
>     self._name_, name))
> AttributeError: 'gi.repository.Gdk' object has no attribute 'Image'

The traceback is not useful.

You must use Cairo for drawing, without using a separate image buffer.

Migrating from GTK+ 2.x to GTK+ 3 explains this;
https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html#id-1.6.3.3.8

Instead of an expose signal and callback, you must connect a draw
signal and write a new callback.

The callback is given a Cairo context.  All drawing operations are
then performed on that context.

If you're not sure how to do this, look for another activity that was
ported from GTK 2 to GTK 3, and examine the changes made.  There are
many to choose from.  You must know how visualise git commit history
and how to read diffs.

Hope that helps!

-- 
James Cameron
http://quozl.netrek.org/


More information about the Sugar-devel mailing list