""" Demonstrate DirBrowse Event Bug in wxPython/wxGTK 2.2.2 . 5.2.2001 Bernhard Reiter """ from wxPython.wx import * from wxPython.lib.filebrowsebutton import DirBrowseButton class wxFrame1(wxFrame): def __init__(self, parent): wxFrame.__init__(self, size = wxSize(300, 30), id=-1, title = 'oh oh oh', parent = parent ) self.dirBrowsePanel= DirBrowseButton( id=-1, parent=self, size=wxSize(280,-1), changeCallback=self.OnDirChanged) self.testinstancevar = "Hula Hula" #****************************************************************************** #* Event Handling #* def OnDirChanged(self,evt): """ Handle changeCallback event from DirBrowseButton. Also handle bug in DirBrowseButton in wxPython-2.2.2, that generates an event when the constructior is not completed. """ # dirty check if the constructor was completed and we have # the instance variables ready if self.__dict__.has_key("testinstancevar"): d=evt.GetString() print "selected database: '%s'" % d print "self.testinstancvar="+self.testinstancevar else: print "Bang, would not have been able to access", print "self.testinstancevar ..." class MyApp(wxApp): def OnInit(self): self.main = wxFrame1(None) self.main.Show(true) self.SetTopWindow(self.main) return true def main(): application = MyApp(0) application.MainLoop() if __name__ == '__main__': main()