1

I'm porting a code from PyGtk to PyGI(PyGObject). There is my code:

import gi
gi.require_version('Gtk','2.0')
from gi.repository import Gtk, Gdk, GObject
w, h = 100,100
# pixmap = gtk.gdk.Pixmap(None, w, h, 1)
pixmap = Gdk.Pixmap(None, w, h, 1) # I Change to it and get error
ctx = pixmap.cairo_create()

My error is:

GObject.init() takes exactly 0 arguments (4 given)

... And Then I Change "Gdk.Pixmap(None, w, h, 1)" To "Gdk.Pixmap.new(None, w, h, 1)"I get this error:

TypeError: Argument 0 does not allow None as a value

ThankYou :)

  • 2
    Number one problem is that you are using Gtk2 with introspection. Use `gi.require_version('Gtk','3.0')` instead. – theGtknerd Feb 09 '18 at 02:57

1 Answers1

1

gi stands for GObject-introspection. This feature only appeared with GTK+ 3, and allowed dynamic bindings, as opposed to static bindings like pyGTK. It seems however that there's a compatibility layer with GTK+ 2 (pygtkcompat), but I know no project using that.

Please read this article that gives hints about how to port from pyGTK to pyGObject: https://wiki.gnome.org/Projects/PyGObject/IntrospectionPorting

One of the migration steps is to use the pygi-convert.sh script to update your code and do a part of the migration for you.

liberforce
  • 11,189
  • 37
  • 48
  • There isn't any "Pixmap" word in pygi-convert.sh(with pygi-convert.sh I get error too). and I added ".new" after "Gdk.Pixmap" but I get error too. I Think in C Programming work gdk_pixmap_new(NULL,w,h,1) – amirmahdi nezhadshamsi Feb 10 '18 at 16:41
  • 1
    It would probably be in `GdkPixbuf` and not `Gdk` itself but in Gtk 3 you have to change the `Pixmap` code anyway. Have a look at " Replace GdkPixmap by cairo surfaces" in the [migration guide](https://developer.gnome.org/gtk3/stable/ch26s02.html). – elya5 Feb 11 '18 at 09:22