After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 663360 - Cannot retrieve window.xid from Gtk.drawingarea widget
Cannot retrieve window.xid from Gtk.drawingarea widget
Status: RESOLVED NOTABUG
Product: pygobject
Classification: Bindings
Component: general
3.0.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-11-03 22:30 UTC by Jason C. McDonald
Modified: 2012-04-22 14:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jason C. McDonald 2011-11-03 22:30:57 UTC
I had a code that, under Python 2.7 and PyGtk 2.24, worked perfectly. However, now, that same code will work.

I need to retrieve window.xid from the Gtk.drawingarea (named videowidget in my code), in order to run a vital part of my code.

A boiled down version of my code is below:

--

from gi.repository import Gtk, Gdk, GdkPixbuf

class Video:

    def __init__(self):

        win = Gtk.Window()
        win.set_resizable(False)
        win.set_decorated(False)
        win.set_position(Gtk.WindowPosition.CENTER)

        fixed = Gtk.Fixed()
        win.add(fixed)
        fixed.show()

        videowidget = Gtk.DrawingArea()
        fixed.put(videowidget, 0, 0)
        videowidget.set_size_request(640, 480)
        videowidget.show()

        xid = videowidget.window.xid

        win.show()

def main():
    Gtk.main()
    return 0

if __name__ == "__main__":
    Video()
    main()

--

When I run the code, I get the following:

"Traceback (most recent call last): File "video.py", line 32, in on_sync_message win_id = videowidget.window.xid AttributeError: 'DrawingArea' object has no attribute 'window'"

I really need to get the xid. Has the method changed, or is this an overlooked function? I saw nothing about a change in the documentation.
Comment 1 Tomeu Vizoso 2011-11-04 11:39:38 UTC
It's not safe to do that because python cannot know whether it should be referencing that window or not. Use get_window() instead.
Comment 2 Timo Vanwynsberghe 2011-11-04 11:41:54 UTC
There are a couple of things to note:
 - the drawingarea has to be realised before you can get its GdkWindow
 - apparently, you can't get the window property directly
 - you need to import GdkX11 for the xid method

With this in mind, here is a minimal working example:

from gi.repository import GdkX11, Gtk

class App:
    def __init__(self):
        win = Gtk.Window()
        win.resize(400, 400)
        win.connect('delete-event', Gtk.main_quit)

        da = Gtk.DrawingArea()
        win.add(da)
        win.show_all()

        print da.get_property('window').get_xid()

if __name__ == "__main__":
    App()
    Gtk.main()
Comment 3 Martin Pitt 2012-04-22 14:54:01 UTC
get_xid() has worked fine for a long time, closing. Thanks!