cometdog
March 10th, 2010, 02:50 AM
So far I'm having fun working with the quickly ubuntu-project (template). I have done some programming before, but essentially nothing with a GUI, and this was exactly what I needed to get started.
What is the correct way to access the main window object from the preferences dialog that is autogenerated by the ubuntu-project template?
I feel like there must be an obvious answer to this question, but I am not seeing it since I have never worked before with glade and pyGTK.
I am trying to flesh out the preferences dialog, and I actually require access to some of the objects in the main window. But I can't see any explicit way that the preferences dialog is aware of the main window. I can't figure out how to access the main application window "object" so that I could do something like main_window_object.builder('label1'), or retrieve some property of the main window, etc.
So far I can work around this as follows. Here is the code that runs when you click the menu button to open the preferences dialog:
def preferences(self, widget, data=None):
"""preferences - display the preferences window for TestProject """
prefs = PreferencesTestProjectDialog.NewPreferencesTestPro jectDialog(self)
response = prefs.run()
if response == gtk.RESPONSE_OK:
#make any updates based on changed preferences here
pass
prefs.destroy()
As you can see, I added "self" explicitly as an argument to the constructor function, and made the corresponding changes in the preferences dialog code. Now I have access to the main window object from the dialog.
But is there a different way to accomplish this? I can't escape the feeling that there is already some built-in way to do this and that my workaround is unnecessary and nonstandard.
What is the correct way to access the main window object from the preferences dialog that is autogenerated by the ubuntu-project template?
I feel like there must be an obvious answer to this question, but I am not seeing it since I have never worked before with glade and pyGTK.
I am trying to flesh out the preferences dialog, and I actually require access to some of the objects in the main window. But I can't see any explicit way that the preferences dialog is aware of the main window. I can't figure out how to access the main application window "object" so that I could do something like main_window_object.builder('label1'), or retrieve some property of the main window, etc.
So far I can work around this as follows. Here is the code that runs when you click the menu button to open the preferences dialog:
def preferences(self, widget, data=None):
"""preferences - display the preferences window for TestProject """
prefs = PreferencesTestProjectDialog.NewPreferencesTestPro jectDialog(self)
response = prefs.run()
if response == gtk.RESPONSE_OK:
#make any updates based on changed preferences here
pass
prefs.destroy()
As you can see, I added "self" explicitly as an argument to the constructor function, and made the corresponding changes in the preferences dialog code. Now I have access to the main window object from the dialog.
But is there a different way to accomplish this? I can't escape the feeling that there is already some built-in way to do this and that my workaround is unnecessary and nonstandard.