call a variable created in an event function in wx python -
i created variable (snowdir) via getpath inside wx.dirdialog box , use snowdir outside function. there sample of code:
for file in os.listdir(snowdir): if fnmatch.fnmatch(file, '*.hdf'): if file[9:16] == a: inputhdf = (snowdir + '\\' + file) print 'input hdf is: ', inputhdf tmod = 1 def ondownload(self, e): modispathfile = 'modis_data_directory_path.txt' dlg = wx.dirdialog(self, "choose directory:", style=wx.dd_default_style #| wx.dd_dir_must_exist #| wx.dd_change_dir ) if dlg.showmodal() == wx.id_ok: print "you chose %s" % dlg.getpath() snowdir = dlg.getpath() print 'snowdir : ', snowdir dlg.destroy() more code .... return snowdir
any appreciated since i've search net without lock , i'm getting out of time.
just assign self.snowdir
, can access object , has access it! e.g.:
def ondownload(self, e): modispathfile = 'modis_data_directory_path.txt' dlg = wx.dirdialog(self, "choose directory:", style=wx.dd_default_style #| wx.dd_dir_must_exist #| wx.dd_change_dir ) if dlg.showmodal() == wx.id_ok: print "you chose %s" % dlg.getpath() self.snowdir = dlg.getpath() print 'snowdir : ', self.snowdir dlg.destroy()
in same scope - i.e. part of same object:
def ondoitclick(self, event): """ action uses snowdir """ self.mod01_dir = os.path.join(self.snowdir,'mod01') ....
outside scope: *assuming above code part of class definition of *myframeclass
and app uses theframe = myframeclass(...)
at same level above can use:
if hasattr(theframe, snowdir): print 'snowdir', theframe.snowdir else: print 'user did not set snowdir'
Comments
Post a Comment