def _on_run_sampler(self, e):
        '''Handles the run sampler button click event 

        '''
        try:
            
            self.confidence_val = Decimal(self.confidence.GetValue()) / Decimal('100')
            self.precision_val = float(self.precision.GetValue()) / 100.0 
            
            if not os.path.exists(self.dir_path) or not os.path.exists(self.output_dir_path):
                dlg = wx.MessageDialog(self, "Please enter a valid input/output directory", "Error", wx.ICON_ERROR)
                dlg.ShowModal()
                return 
            
            file_list = find_files_in_folder(self.dir_path)
            self.SetStatusText('%d files found in %s.' % (len(file_list), self.dir_path) )
            
            sampled_files = random_sampler(file_list, self.confidence_val, self.precision_val, self.SEED)
            self.SetStatusText('%d files are sampled out of %d files.' % (len(sampled_files), len(file_list)))
            
            copy_files_with_dir_tree(self.dir_path, sampled_files, self.output_dir_path)
            self.SetStatusText('%d randomly sampled files (from %d files) are copied to the output folder.' % (len(sampled_files), len(file_list)))

            
            # shows the tree list control 
            self.process_files_tree.on_changed_output_dir(self.output_folder_control.GetValue())
            self.process_files_tree.Show(True)
            self.GetSizer().Layout()
            self.Refresh()

        
        
        except Exception as anyException:
            dlg = wx.MessageDialog(self, str(anyException), "Error", wx.ICON_ERROR)
            dlg.ShowModal()
 def _on_confidence_changed(self, event):
     '''
     Triggers an event and updates the sample list on confidence - aka 
     confidence level change
     Arguments: Event of new confidence
     Returns: Nothing
     '''
     
     
     super(RandomSampler, self)._on_confidence_changed(event)
     
     self._tc_out_confidence_levels.SetValue(self._cbx_confidence_levels.GetValue())
     
     self.confidence_val = Decimal(self._cbx_confidence_levels.GetValue()
                                       )/ Decimal('100')
     self.sampled_files = random_sampler(self.file_list, self.confidence_val,
                                         self.precision_val, self.SEED)
     self.SetStatusText('%d files are sampled out of %d files.'
                            % (len(self.sampled_files), len(self.file_list)))
     self._st_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
     self._st_out_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
     self.GetSizer().Layout()
    def _on_click_io_sel_data_dir( self, event ):
        """
        Select the data folder
        Arguments: Event of item selected
        Returns: Nothing
        """
        super(RandomSampler, self)._on_click_io_sel_data_dir(event) 
        
        dlg = wx.DirDialog(self, "Choose the input folder to sample",
                           self.dir_path, wx.DD_DIR_MUST_EXIST)
        if dlg.ShowModal() == wx.ID_OK:
            self.dir_path = dlg.GetPath()
            message_dialog =  wx.MessageDialog(parent = self, message = "Loading files. This may take a few minutes. Press OK to continue ... ",caption = "Loading",
                                    style = wx.ICON_INFORMATION)
            message_dialog.ShowModal()
            self.do_load(message_dialog)
            #self.file_list = find_files_in_folder(self.dir_path)
        dlg.Destroy()
        self._tc_data_dir.SetValue(self.dir_path)
        self._tc_out_data_dir.SetValue(self.dir_path)
        self.SetStatusText("The selected input folder is %s" % self.dir_path)
        
        # Runs load on a different thread
        
        #self.file_list = find_files_in_folder(self.dir_path)
        self._st_num_data_dir_files.SetLabel('%d files found' % len(self.file_list))
        self._st_out_num_data_dir_files.SetLabel('%d files found' % len(self.file_list))
        
        
        self.sampled_files = random_sampler(self.file_list,
                                            self.confidence_val,
                                            self.precision_val, self.SEED)
        self.SetStatusText('%d files are sampled out of %d files.'
                               % (len(self.sampled_files), len(self.file_list)))

        self._st_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
        self._st_out_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
        self._st_num_samples.Show()
 def _on_precision_changed(self, event):
     '''
     Triggers an event and updates the sample list on precision - aka 
     confidence interval change.
     Arguments: Event of new precision value
     Returns: Nothing
     '''
     super(RandomSampler, self)._on_precision_changed(event)
     
     self._tc_out_confidence_interval.SetValue(self._tc_confidence_interval.GetValue())
     
     # Maybe intermittently null string, escaping 
     try:
         self.get_precision_as_float()
     except ValueError:
         return None 
     self.sampled_files = random_sampler(self.file_list, self.confidence_val,
                                         self.precision_val, self.SEED)
     self.SetStatusText('%d files are sampled out of %d files.'
                            % (len(self.sampled_files), len(self.file_list)))
     self._st_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
     self._st_out_num_samples.SetLabel('%d samples found' % len(self.sampled_files))
     self._st_num_samples.Show()