Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm in a deeply nested class (which inherits from Gtk.Box) and I need to get a reference to the GtkWindow I'm in to pass to a call to Gtk.MessageDialog() yet I cant seem to find a reference to it.

I have tried self.props.window as well as self.get_parent_window() with no avail.

Everything I try to do leads to the following error:

TypeError: Expected Gtk.Window, but got GObjectMeta

Code snippet is as follows:

def on_tb_del_clicked(self,widget):
    question = _("Are you sure you want to do this?")
    win = self.get_parent_window() 
    dialog = Gtk.MessageDialog(win,0,Gtk.MessageType.QUESTION,
                                   Gtk.ButtonsType.YES_NO,question) # <<Exception 
    response = dialog.run()

Please help :)

share|improve this question
    
Furthermore i can appreciate the workaround is to simply pass my Top level class reference of my GtkWindow down the chain myself manually but i was hoping there was a nicer API property that i was missing as i would have thought all widgets would benefit from knowing a reference to their top level window?? –  William Culver Jul 5 '12 at 15:31

1 Answer 1

up vote 1 down vote accepted

Try the widget.get_toplevel() method to find the parent window.

share|improve this answer
    
@William Culver so how did you workaround this problem ? –  Majster-pl Jun 17 '13 at 22:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.