[pygtk] Help passing a widget to another class instance
Kim Adil
kadil at proactiveindustrial.net
Mon Jul 20 19:29:40 WST 2009
Solved:
I had to add a self.xxx variable to the init method of the page class
and make it equal to the pparent, so that the "save" method on the page
class had a variable it could access. I would be interested in what
people consider "good practice in this sort of situation.
Kim
Kim wrote:
> Hi,
>
> I have a class for a glade window, that contains a notebook and I have
> another class for notebook pages. I want to pass the (pointer to)
> notebook widget when I create the the page object, so I can change the
> notebook's tab label from a method in the page class (ie save button on
> the page) but I get the error:
>
> print self.pparent.get_current_page()
> AttributeError: load_data_page instance has no attribute 'pparent'
>
> code snips below. Question is how do you pass the widget (or pointer)
> from one object to another?
>
>
> Thanks,
> Kim
>
> class load_data_page:
> """__init__() functions"""
> def __init__(self,pparent):
> self.gladefile = "bp2.glade"
> self.wTree = gtk.glade.XML(self.gladefile, "vbox4")
> self.pageWidget = self.wTree.get_widget("vbox4")
> self.entryDescription = self.wTree.get_widget("entryDescription")
> self.entryUserid = self.wTree.get_widget("entryUserid")
> self.entryUserid.set_text(os.environ['USERNAME'])
> self.entryUserid = self.wTree.get_widget("entryTimestamp")
> self.entryUserid.set_text(time.strftime("%d/%m/%Y %H:%M:%S",
> time.localtime()))
> self.buttonLoad = self.wTree.get_widget("buttonLoad")
> dic = {"on_buttonLoad_clicked" : self.loadFile,
> }
> self.wTree.signal_autoconnect(dic)
>
> def loadFile(self,data):
> self.entryDescription.set_text('hello')
> print 'zzzz'
> print pparent.get_current_page()
>
>
> class win_main:
> """An application to help manage things you intend to do"""
> def __init__(self):
> #Set the Glade file
> self.gladefile = "bp2.glade"
> self.wTree = gtk.glade.XML(self.gladefile, "window1")
> self.wTree3 = gtk.glade.XML(self.gladefile, "toolbar2")
> self.wTree2 = gtk.glade.XML(self.gladefile, "menu4")
> self.wTree4 = gtk.glade.XML(self.gladefile, "label13")
> self.menu41 = self.wTree2.get_widget("tbm3datafile")
> dic = {"on_win_main_destroy" : self.aquit,}
> self.notepad = self.wTree.get_widget("notebook1")
>
> ...
>
>
>
>
>
>
>
> .....
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
More information about the pygtk
mailing list