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:

# GuitestWindow.py
class GuitestWindow(Window):

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

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

# NewAccountDialog.py
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

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!
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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