Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Quickly and created the main window and a dialog. In the main window I am setting access to database (u1db) in the finish_initializing method (self.db=...). After an action I open a dialog where I need access to the database.

I thought that I can use self.get_parent() in the dialog to get instance of the main window and access the database, but return value of the get_parent() is None.

My question is, how can I access the instance of the parent window in the dialog or perhaps where should I place the instance of the database wrapper?

Shortened code:

class GuitestWindow(Window):

    def finish_initializing(self, builder):
        self.db =

    def on_addaccountbutton_clicked(self, widget):
        dialog = NewAccountDialog.NewAccountDialog(db=self.db)
        result =

class NewAccountDialog(Gtk.Dialog):
    __gtype_name__ = "NewAccountDialog"

    def __new__(cls, *args, **kwargs):
        print "__new__: %s : %s" % (args, kwargs)
        builder = get_builder('NewAccountDialog')
        new_object = builder.get_object('new_account_dialog')
        print "__new__ end"
        return new_object

    def __init__(self, *args, **kwargs):
        print "__init__: %s : %s" % (args, kwargs)
        self.db = kwargs.get('db')
        super(NewAccountDialog, self).__init__(*args, **kwargs)
        print "__init__ end"


__new__: () : {'db': <u1db.backends.sqlite_backend.SQLitePartialExpandDatabase object at 0x1884f50>}
__init__: () : {}
__init__ end
__new__ end
__init__: () : {'db': <u1db.backends.sqlite_backend.SQLitePartialExpandDatabase object at 0x1884f50>}
__init__ end
share|improve this question

That's pretty simple, just pass your main window instance to your dialog :-).

    # ...
    dialog = NewAccountDialog.NewAccountDialog(self)
    # ...

class NewAccountDialog(Gtk.Dialog):
    def __init__(self, main):
        self.main = main
        # I can manage main now!
share|improve this answer
I updated the code. When I pass a parameter, new is called once, init two times but one time without the parametr I supplied. – Bruce Sep 5 '12 at 21:23

Your Answer


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.