paleo_view_v1_2.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:PaleoView 作者: GlobalEcologyLab 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号