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 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(
            db_path,
            create=True
        )


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



# 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')
        new_object.finish_initializing(builder)
        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"

Result:

__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
add comment

1 Answer

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
add comment

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.