def get_recognition_languages(cls) -> t.List[LocaleInfo]: langs = [] for lng in pytesseract.get_languages(): try: langs.append(LocaleInfo.from_three_letter_code(lng)) except ValueError: continue return langs
def populate_list(self, set_focus=True): installed_languages = [(True, info) for info in sorted( TesseractOcrEngine.get_recognition_languages(), key=lambda l: l.english_name, )] if self.is_offline: languages = installed_languages else: languages = [] added_locale_infos = set(l[1] for l in installed_languages) for lang in self.online_languages: loc_info = LocaleInfo.from_three_letter_code(lang) if loc_info in added_locale_infos: continue else: languages.append((False, loc_info)) added_locale_infos.add(loc_info) column_defn = [ ColumnDefn( # Translators: the title of a column in the Tesseract language list _("Language"), "left", 450, lambda lang: lang[1].description, ), ColumnDefn( # Translators: the title of a column in the Tesseract language list _("Installed"), "center", 100, lambda lang: _("Yes") if lang[0] else _("No"), ), ] self.tesseractLanguageList.set_columns(column_defn) if set_focus: self.tesseractLanguageList.set_objects(languages, focus_item=0) else: self.tesseractLanguageList.set_objects(languages, set_focus=False) # Maintain the state of the list if not any(languages): if not self.is_offline: self.addBestButton.Enable(False) self.addFastButton.Enable(False) else: self.removeButton.Enable(False) self.btnPanel.Enable(False)