def get_user_taxa(): username = get_app().username # TODO: Show this alert only when clicking on tab instead if not username: alert('Please enter iNaturalist username on Settings page') return {} return ""
def recognize(self, instance, *args, file_list=None): """ Recognize image with tesseract """ if file_list is None: file_list = get_app().image_selection_controller.file_list if not file_list: alert(f'Select images to recognize') self.enable_rec(instance) return if instance._ButtonBehavior__touch_time < self.last_rec_time: self.enable_rec(instance) return logger.info(f'Main: Recognize {len(file_list)} images') # metadata_settings = get_app().metadata # TODO: Handle write errors (like file locked) and show dialog # file_list = get_app().image_selection_controller model = "eng" if self.screen.model.current_item == '' else self.screen.model.current_item.split(": ")[1].strip() psm = "3" if self.screen.psm.current_item == '' else self.screen.psm.current_item.split(": ")[1].strip() oem = "3" if self.screen.oem.current_item == '' else self.screen.oem.current_item.split(": ")[1].strip() outputformats = self.active_outputformats() print_on_screen = self.screen.print_on_screen_chk.active groupfolder = self.screen.groupfolder.text subfolder = self.screen.subfolder_chk.active proc_files, outputnames = recognize(file_list, model=model, psm=psm, oem=oem, tessdatadir=get_app().tessdatadir, output_folder=self.selected_output_folder, outputformats=outputformats, print_on_screen=print_on_screen, subfolder=subfolder, groupfolder=groupfolder) toast(f'{proc_files} images recognized') self.last_rec_time = time.time() + 2 get_app().image_selection_controller.file_chooser._update_files() self.enable_rec(instance)
def diff_dialog(instance, *args): image = instance.selected_image.original_source stdout_cache = read_stdout_cache(image) layout = MDList() if len(stdout_cache.keys()) == 0: alert("No stdout text available.") return item = OneLineListItem(text="Select first text", on_release=partial(select_text, stdout_cache.keys())) layout.add_widget(item) item = OneLineListItem( text="Select second text", on_release=partial(select_text, stdout_cache.keys()), ) layout.add_widget(item) dialog = MDDialog( title="Compare stdouts", type='custom', auto_dismiss=False, content_cls=layout, buttons=[ MDFlatButton(text="COMPARE", on_release=partial(diff, stdout_cache, image)), MDFlatButton(text="DISCARD", on_release=close_dialog), ], ) dialog.open()
def _on_touch_down(self, instance, touch): """ Copy text on right-click """ if not self.collide_point(*touch.pos): return elif touch.button == 'right': Clipboard.copy(self.text) alert('Copied to clipboard') else: super().on_touch_down(touch)
def open_pdf_instance(self, instance, *args): """ Open a pdf via webbrowser or another external software """ from pathlib import Path fname = Path(instance.selected_image.original_source) pdf = [] find_file(fname.parent.joinpath(fname.name.rsplit(".", 1)[0] + ".pdf"), pdf) if not pdf: alert(f"Couldn't find any matching pdf to {fname.name}") return open_pdf(str(Path(pdf[0]).absolute()))
def open_pdf(fname, *args): """ Open a pdf via webbrowser or another external software """ pdfviewer = get_app().settings_controller.pdfviewer if pdfviewer == 'webbrowser': webbrowser.open(str(Path(fname).absolute())) else: try: run([pdfviewer, str(Path(fname).absolute())]) except: alert(f"Couldn't find: {pdfviewer}") pass
def current_screen_paste(self): value = Clipboard.paste() model_id, gt_id = 0, 0 if model_id: self.select_model(id=model_id) alert(f'Model {model_id} selected') if gt_id: # self.select_gt(id=gt_id) alert(f'GT {gt_id} selected') if self.screen_manager.current == HOME_SCREEN: if gt_id: self.image_selection_controller.screen.gt_id_input.text = str(gt_id) self.image_selection_controller.screen.model_id_input.text = '' elif model_id: self.image_selection_controller.screen.gt_id_input.text = '' self.image_selection_controller.screen.model_id_input.text = str(model_id)
def recognize(self, instance, *args, file_list=None, profile=None): """ Recognize image with tesseract """ if profile is None: profile = {} if file_list is None: file_list = get_app().image_selection_online_controller.file_list if not file_list: alert(f'Select images to recognize') self.enable_rec(instance) return logger.info(f'Main: Recognize {len(file_list)} images') model = profile.get( "model", "eng" if self.screen.model.current_item == '' else self.screen.model.current_item.split(": ")[1].strip()) psm = profile.get( "psm", "3" if self.screen.psm.current_item == '' else self.screen.psm.current_item.split(": ")[1].strip().split( ' ', 1)[0]) outputformats = ';'.join( profile.get("outputformats", self.active_outputformats())) if isinstance(file_list, str): print_on_screen = profile.get( "print_on_screen", self.screen.print_on_screen_chk.active) create_online_threadprocess("Start recognize online", ocr_image, file_list, model=model, psm=psm, outputformats=outputformats, print_on_screen=print_on_screen) else: jobname = profile.get( "jobname", "Job_01" if self.screen.jobname.text == '' else self.screen.jobname.text) jobname = re.sub(r"[\s,\.,!,/,\\]", "_", jobname) create_online_threadprocess( f"{jobname}: Upload images", ocr_bulk_of_images, jobname, file_list, model=model, psm=psm, outputformats=outputformats, overwrite=str(self.screen.overwrite_job_chk.active)) self.enable_rec(instance)
def clear_settings(self, *args): reset_defaults() self.update_control_widgets() alert('Settings have been reset to defaults')
def clear_stdout_cache(self, *args): logger.info('Settings: Clearing stdout cache') clear_stdout_cache() self.update_cache_sizes() alert('Cache has been cleared')
def clear_thumbnail_cache(self, *args): logger.info('Settings: Clearing thumbnail cache') delete_thumbnails() self.update_cache_sizes() alert('Cache has been cleared')