amirmahdi nezhadshamsi
amirmahdi nezhadshamsi

Reputation: 108

Gtk-Gdk Pixmap in Pygobject python

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 :)

Upvotes: 1

Views: 747

Answers (1)

liberforce
liberforce

Reputation: 11454

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.

Upvotes: 1

Related Questions