def selectClimateDataDirectory(self) :
# Use existing Climate Data Directory if it exists
current_dir = self.climate_data_directory_text.get()
if path.exists(current_dir) :
initial_directory = current_dir
elif MAC_VERSION and environ.has_key('HOME') and path.exists(environ['HOME']) :
initial_directory = environ['HOME']
elif environ.has_key('USERPROFILE') and path.exists(environ['USERPROFILE']) : # PC version
initial_directory = environ['USERPROFILE']
else :
initial_directory = getcwd()
# Open file selection dialog
climate_data_directory_path = askdirectory(title='Select the directory containing the climate data', initialdir=initial_directory)
if climate_data_directory_path : # Directory selected
# Create directory if it doesn't already exist
if not path.exists(climate_data_directory_path) :
try :
climate_data_directory_path = self.data_file_helper.createDirectoryPath(climate_data_directory_path)
except Exception, e :
directory_name = self.data_file_helper.splitPath(climate_data_directory_path)['name']
showerror('Directory Error', 'Error loading or creating directory \"'+directory_name+'\". Check file permissions.')
print >> sys.stderr, 'Error loading or creating directory:', e
# Set the climate data directory appropriately
climate_data_directory_path = path.normpath(str(climate_data_directory_path))
previous_path = self.data_file_helper.getClimateDataDirectoryPath()
self.data_file_helper.setClimateDataDirectory(climate_data_directory_path)
if hasattr(self, 'config_climate_data_location_window') and self.config_climate_data_location_window.children :
# Does it contain the climate data?
if self.data_file_helper.climateDataIsPresent() :
self.climate_data_directory_text.set(climate_data_directory_path)
self.setToolOptions({ 'climate_data_directory' : climate_data_directory_path })
# Reset focus to config window
self.config_climate_data_location_window.focus_set()
else :
showwarning('Climate data not found', 'None of the expected climate data was not found in ' + climate_data_directory_path)
self.data_file_helper.setClimateDataDirectory(previous_path)
elif hasattr(self, 'download_climate_data_window') and self.download_climate_data_window.children :
self.climate_data_directory_text.set(climate_data_directory_path)
self.setToolOptions({ 'climate_data_directory' : climate_data_directory_path })
# Reset focus to download window
self.download_climate_data_window.focus_set()
# Menu Method: Configure Default File Generation Directory
评论列表
文章目录