def ok_callback(self):
     if self.sim_input.text == '':
         self._popup = ErrorMsg(
             error_text='Please enter a value for the minimum match score.')
         self._popup.open()
         return
     if self.nmatch_input.text == '':
         self._popup = ErrorMsg(
             error_text=
             'Please enter a value for the maximum number of matches.')
         self._popup.open()
         return
     if self.ngram_input.text == '':
         self._popup = ErrorMsg(
             error_text='Please enter a value for the n-gram size.')
         self._popup.open()
         return
     backend = App.get_running_app().backend
     backend.min_similarity = float(self.sim_input.text)
     backend.max_n_matches = int(self.nmatch_input.text)
     backend.ngram_size = int(self.ngram_input.text)
     backend.excl_chars = self.excl_input.text
     backend.ignore_whitesp = self.check_whitesp.active
     backend.ignore_case = self.check_case.active
     backend.advanced_opts = {
         'amperland': self.check_amperland.active,
         'unidecode': self.check_unidecode.active,
         'shortstr': self.check_shortstr.active
     }
     backend.generate_regex()
     App.get_running_app().nav_to('load_screen', 'left')
Example #2
0
 def do_col_merge(self, *args):
     app = App.get_running_app()
     backend = app.backend
     colm = self.merge_popup.content
     if len(colm.right_buttons) < 2:
         _popup = ErrorMsg(
             error_text='Choose at least 2 columns to merge together.')
         _popup.open()
         return
     col = colm.ids.new_col_text.text
     if col == '':
         _popup = ErrorMsg(
             error_text=
             'Enter a name for the merged column that will be created.')
         _popup.open()
         return
     try:
         if colm.which == 1:
             df = backend.grouper_helper.df1
         else:
             df = backend.grouper_helper.df2
         col_out = backend.merge_cols(df,
                                      [b.text for b in colm.right_buttons])
         new_col_name = col
         ndupe = 1
         while any(df.columns == new_col_name):
             new_col_name = col + '.' + str(ndupe)
             ndupe += 1
             if ndupe > 5000:
                 raise Exception(
                     'Maybe try a different name for the merged column?')
         df.insert(0, new_col_name, col_out)
         if colm.which == 1:
             backend.columns1 = df.columns
             self.populate_dropdown1()
         else:
             backend.columns2 = df.columns
             self.populate_dropdown2()
         app.panels['alsocompare_screen'].reset_panel()
         app.panels['append_screen'].populate()
         self.merge_popup.dismiss()
     except Exception as error:
         self.merge_popup.dismiss()
         error_type = str(type(error)).split('\'')[1]
         error_msg = error
         _popup = ErrorMsg(
             error_text='Error creating new column: {}. {}'.format(
                 error_type, error_msg))
         _popup.open()
Example #3
0
    def save_really(self):
        backend = App.get_running_app().backend
        try:
            if self.out_file.suffix == '.xlsx':
                self.prep_export()
                self.matches_for_export.to_excel(str(self.out_file),
                                                 index=False)
                self._popup.dismiss()

            elif (self.out_file.suffix == '.csv') | (self.out_file.suffix
                                                     == '.txt'):
                self.prep_export()
                self.matches_for_export.to_csv(str(self.out_file),
                                               index=False,
                                               sep=self.sep,
                                               encoding=self.encoding)
                self._popup.dismiss()

            else:
                raise Exception('Filetype must be .xlsx, .csv, or .txt')

        except Exception as error:
            self._popup.dismiss()
            error_type = str(type(error)).split('\'')[1]
            self._popup = ErrorMsg(
                error_text='Error saving {}.\n\n{}: {}'.format(
                    self.out_file.parts[-1], error_type, error))
            self._popup.open()
Example #4
0
 def do_load( self, obj):
     app = App.get_running_app()
     
     app.backend.labels[0] = self.file_section1.dataset_name
     app.backend.labels[1] = self.file_section2.dataset_name
     
     if app.backend.labels[0] == app.backend.labels[1]:
         app.backend.labels[1] += '(2)'
     
     file1 = self.file_section1.get_path()
     file2 = self.file_section2.get_path()
         
     sep1 = self.file_section1.sep
     sep2 = self.file_section2.sep
     encoding1 = self.file_section1.encoding
     encoding2 = self.file_section2.encoding
     
     load_successful = app.backend.init_fast_match( file1, file2, sep1, sep2, encoding1, encoding2)
     
     self._popup.dismiss()
     
     if load_successful:
         app.panels['narrowby_screen'].populate_dropdowns()
         app.panels['alsocompare_screen'].reset_panel()
         app.panels['append_screen'].populate()
         app.nav_to( 'narrowby_screen', 'left')
     else:
         error_type = app.backend.grouper_helper.error_type
         error_msg  = app.backend.grouper_helper.error_msg
         if app.backend.grouper_helper.file1_load_successful:
             problem_file = app.backend.labels[1]
         else:
             problem_file = app.backend.labels[0]
         errtxt = 'Error loading {}.\n\n{}: {}'.format(problem_file, error_type, error_msg)
         if error_type == 'UnicodeDecodeError':
             errtxt += '\n\nThis probably means you selected the wrong encoding. Try re-loading your plaintext file and select a different encoding when prompted.'
         self._popup = ErrorMsg( error_text=errtxt)
         self._popup.open()