Holger Reinmann wrote:

Hello,



When I try to get the XID from the gtk.drawingarea with da.window.xid I
get an Errormsg "None Type Object has no attribute XID"

greetings holger

Sorry, the example showed the XID for the window were the button is being painted, and that is its parent's window (the main window on this occasion), as gtk.Buttons don't own an X window for themselves.

With some changes the example at the end should work now as expected.

Anyway, remind that the window for which you want to know the XID must have been realized (if it's exposed you know that happens for sure). If you want to do this in a class that inherits from gtk.DrawingArea that means you should get the XID inside an on_expose_event(...) callback method connected to the configure event for the gtk.DrawingArea. Possibly you can do that too earlier (not sure about this) inside a similar on_realize (for the realize event) chaining up the event before getting the window, just for the case it runs before the parent class' method runs.

Fleshed out, this last idea would be coded as something like this:

<example 1>
"""Print a widget's XID when the widget is a class inherited from another gtk widget."""


import pygtk
pygtk.require('2.0')
import gtk

def show_widget_xid_datum(sender, widget):
  sender.set_label("X window ID: %s" % (widget.the_xid_you_want,))

class GraphArea(gtk.DrawingArea):
   def __init__(self):
      gtk.DrawingArea.__init__(self)
      self.connect('expose-event', self.on_expose_event)

   def on_expose_event(self, widget, event):
      self.the_xid_you_want = widget.window.xid
      return False

window = gtk.Window()
vbox = gtk.VBox()
ga = GraphArea()
ga.set_size_request(200,100)
button = gtk.Button("Press me")
button.connect("clicked", show_widget_xid_datum, ga)
vbox.pack_start(button)
vbox.pack_start(ga)
window.add(vbox)
window.set_title("GraphArea XID example")
window.connect("destroy", gtk.mainquit)

window.show_all()
gtk.main()

<\example 1>

And here is the first example, corrected:
<example 2>
"""Print a widget's XID"""

import pygtk
pygtk.require('2.0')
import gtk

def show_widget_xid(sender, widget):
  sender.set_label("X window ID: %s" % (widget.window.xid,))

window = gtk.Window()
vbox = gtk.VBox()
da = gtk.DrawingArea()
da.set_size_request(200,100)
button = gtk.Button("Press me")
button.connect("clicked", show_widget_xid, da)
vbox.pack_start(button)
vbox.pack_start(da)
window.add(vbox)
window.set_title("DrawingArea example")
window.connect("destroy", gtk.mainquit)

window.show_all()
gtk.main()

Take care,

Pachi


_______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to