2

Context:

There was once a post on preventing window overlap with Gtk+2.x Recent changes in Gtk+3 have however affected the gdk_property_change() function, which has the PyGobject Introspection (hereafter referred to as PyGI) equivalent of Gdk.property_change(). In the previous SO answer the property_change arguments were of type (str, str, Gdk.PROP_MOD_*, int, data), the Gtk+3 equivalent asks instead for (GdkWindow, GdkAtom, GdkAtom, int, GdkPropMode, data, int). Passing a GdkAtom as argument rather than a string seems to be the new requirement.

Problem:

New Gdk.Atom can be created with PyGtk with the gtk.gdk.atom_intern(str) method. The corresponding C function in the documentation is gdk_atom_intern(). There is however no such method in PyGI: a mere dir(Gtk) will return Gdk.Atom or Gdk.atom_name but no Gdk.atom_intern. The Gdk.Atom has no apparent method either. PS: it seems reading this code at line 139 that Gdk.atom_intern() would be available though.

Question:

Do you know how I could create (or find out how to create) a Gdk.Atom using PyGI with Gtk+3?

Thanks.

Community
  • 1
  • 1
neydroydrec
  • 6,973
  • 9
  • 57
  • 89
  • The language bindings are not always perfect yet. You should probably file a bug on bugzilla.gnome.org. – ptomato May 22 '11 at 17:15
  • @Ptomato: that's what i fear as well. I mailed the Gtk mailinglist, hoping to get a confirmation from them. – neydroydrec May 22 '11 at 17:44
  • Update: [bug submitted](https://bugzilla.gnome.org/show_bug.cgi?id=650811). Awaiting confirmation before updating answer. – neydroydrec May 22 '11 at 18:07
  • I actually meant I thought the bug was in the binding of `Gdk.property_change()`; in Python it ought to take strings, just like the PyGTK function. Strings in Python have some similarities to atoms anyway, and the language bindings should take care of that for you. – ptomato May 23 '11 at 00:06

1 Answers1

0

It might be that Gobject-Introspection picks up Gdk from Gtk+-2.0 version, so you have to force the version:

In [1]: import gi  
In [2]: gi.require_version("Gdk", "3.0")   
In [3]: from gi.repository import Gdk    
In [4]: Gdk.__path__
Out[4]: '/usr/lib64/girepository-1.0/Gdk-3.0.typelib'    
In [5]: Gdk.atom_intern
Out[5]: <function atom_intern at 0x152f140>    
In [6]: Gdk.atom_intern_static_string
Out[6]: <function atom_intern_static_string at 0x152f398>

For this to work, the gir1.2-gtk-3.0 package is needed. On Ubuntu it can be installed from repositories with sudo apt-get install gir1.2-gtk-3.0.

neydroydrec
  • 6,973
  • 9
  • 57
  • 89
plaes
  • 31,788
  • 11
  • 91
  • 89
  • Amazing: mine returns `AttributeError: 'gi.repository.Gdk' object has no attribute 'atom_intern'. Can you tell which version you have? `Gdk.__path__` returns `/usr/lib/girepository-1.0/Gdk-2.0.typelib`. – neydroydrec May 23 '11 at 07:18
  • I believe i don't have the latest version installed. But i am stuck with the installation: it's asking for gobject-introspection 1.0 while the latest version is 0.10. – neydroydrec May 23 '11 at 08:10
  • @Benjamin: You seem to be importing Gdk from Gtk+-2.0, as for me: 'Gdk.__path__' returns '/usr/lib64/girepository-1.0/Gdk-3.0.typelib'. Also, this is with Gtk+-3.0.9 – plaes May 23 '11 at 08:57
  • 1
    @Benjamin: I have updated the code to show how to force specific version. – plaes May 23 '11 at 09:19
  • @plaes: thanks. I have accepted your answer although that doesn't work for me as of yet since I don't have the latest Gtk+3 or PyGI libraries. I am running into trouble installing those however: did it go well for you? If you're willing to help i'd be grateful, although it may not fit in this Q&A. You can contact me at gmail my username is jesuisbenjamin. Thanks. – neydroydrec May 23 '11 at 10:38
  • Well, it depends on the distribution you are using, I'm using Gentoo and all the introspection stuff comes with the package manager, basically I just have to do (USE=introspection emerge gtk+). – plaes May 23 '11 at 11:07
  • @plaes: where did you find your Gdk 3? in your distro's repositories? I just finished installin Gtk+3 and latest version of PyGobject but no Gdk-3.0.typelib. – neydroydrec May 23 '11 at 13:39
  • @plaes: i found the package "gir1.2-gtk-3.0" which i was missing and updated your answer accordingly :) once installed though, specifying the version is not necessary: it picks up the latests by default. Thanks :) – neydroydrec May 23 '11 at 14:35