GNOME Bugzilla – Bug 663360
Cannot retrieve window.xid from Gtk.drawingarea widget
Last modified: 2012-04-22 14:54:01 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.
It's not safe to do that because python cannot know whether it should be referencing that window or not. Use get_window() instead.
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()
get_xid() has worked fine for a long time, closing. Thanks!