def getDefaultLocale(self): default_locale = enchant.get_default_language() if default_locale is None: default_locale = QLocale.system().name() if default_locale is None: default_locale = enchant.list_dicts()[0][0] return default_locale
def set_spellcheck_language(self, lang): if lang in [x for x,y in enchant.list_dicts()]: pwlpath = self.get_path('spellcheck-pwl') pwl = os.path.join(pwlpath, lang+'.pwl') self.highlighter.dict = enchant.DictWithPWL(lang, pwl=pwl) self.highlighter.rehighlight() self.print_('Language set to {}'.format(lang)) else: self.error('Language {} does not exist!'.format(lang))
def show_info(self): g.es_print('pyenchant spell checker') g.es_print('user dictionary: %s' % self.find_user_dict()) try: aList = enchant.list_dicts() aList2 = [a for a, b in aList] g.es_print('main dictionaries: %s' % ', '.join(aList2)) except Exception: g.es_exception()
def show_info(self): g.es_print('pyenchant spell checker') g.es_print(f"user dictionary: {self.find_user_dict()}") try: aList = enchant.list_dicts() aList2 = [a for a, b in aList] g.es_print(f"main dictionaries: {', '.join(aList2)}") except Exception: g.es_exception()
def listDictionaries(self): """Wrapper function for pyenchant. """ retList = [] try: import enchant for spTag, spProvider in enchant.list_dicts(): retList.append((spTag, spProvider.name)) except Exception: logger.error("Failed to list languages for enchant spell checking") return retList
def do_create_configure_widget(self): """setup the config dialog""" # setup a check button and associate it with a GSettings key extlbl = Gtk.Label("Extensions:") extensions = Gtk.Entry() extensions.set_tooltip_text("Semi-colon delimited list of extensions.") extensions.set_text(self._prefs.get_extensions()) self._prefs.connect("changed::extensions", self.on_extensions_changed, extensions) extensions.connect('focus-out-event', self.on_extensions_focus_out) dictlbl = Gtk.Label("Dictionary:") dictionary = Gtk.ComboBoxText() dictionary.set_tooltip_text("The dictionary to use") dictionary.set_entry_text_column(0) for dict_name, _ in enchant.list_dicts(): dictionary.append_text(dict_name) dictionary.set_active( self.get_dict_index(self._prefs.get_dictionary())) self._prefs.connect("changed::dictionary", self.on_dictionary_changed, dictionary) dictionary.connect("changed", self.on_dictionary_ctrl_changed) wordlbl = Gtk.Label("Word Regex:") wordregex = Gtk.Entry() wordregex.set_tooltip_text( "The regex used to determine a valid word to be spell checked.") wordregex.set_text(self._prefs.get_wordregex()) self._prefs.connect("changed::wordregex", self.on_wordregex_changed, wordregex) wordregex.connect('focus-out-event', self.on_wordregex_focus_out) extbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) extbox.pack_start(extlbl, False, False, 0) extbox.pack_start(extensions, True, True, 0) dictbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) dictbox.pack_start(dictlbl, False, False, 0) dictbox.pack_start(dictionary, True, True, 0) wordbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) wordbox.pack_start(wordlbl, False, False, 0) wordbox.pack_start(wordregex, True, True, 0) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) vbox.pack_start(extbox, False, False, 0) vbox.pack_start(dictbox, False, False, 0) vbox.pack_start(wordbox, False, False, 0) return vbox
def updateMenuDict(self): if not enchant: return self.menuDict.clear() for i in enchant.list_dicts(): a = QAction(str(i[0]), self) a.setCheckable(True) if settings.dict is None: settings.dict = enchant.get_default_language() if str(i[0]) == settings.dict: a.setChecked(True) a.triggered.connect(self.setDictionary, AUC) self.menuDictGroup.addAction(a) self.menuDict.addAction(a)
def listDictionaries(self): retList = [] for spTag, spProvider in enchant.list_dicts(): if hasPyCountry: spList = [] try: langObj = pycountry.languages.get(alpha_2 = spTag[:2]) spList.append(langObj.name) except: spList.append(spTag[:2]) if len(spTag) > 3: spList.append("(%s)" % spTag[3:]) spList.append("[%s]" % spProvider.name) spName = " ".join(spList) else: spName = "%s [%s]" % (spTag, spProvider.name) retList.append((spTag, spName)) return retList
import enchant print(80 * '-') print('PYTHONPATH: %s' % sys.path) # At least one backend should be available backends = [x.name for x in enchant.Broker().describe()] if len(backends) < 1: raise SystemExit('Error: No dictionary backend available') print(80 * '-') print('Backends: ' + ', '.join(backends)) # Usually en_US dictionary should be bundled. langs = enchant.list_languages() dicts = [x[0] for x in enchant.list_dicts()] if len(dicts) < 1: raise SystemExit('No dictionary available') print(80 * '-') print('Languages: %s' % ', '.join(langs)) print('Dictionaries: %s' % dicts) print(80 * '-') # Try spell checking if English is availale l = 'en_US' if l in langs: d = enchant.Dict(l) print('d.check("hallo") %s' % d.check('hallo')) print('d.check("halllo") %s' % d.check('halllo')) print('d.suggest("halllo") %s' % d.suggest('halllo'))
def availableDictionaries(): if EnchantDictionary.isInstalled(): return list(map(lambda i: str(i[0]), enchant.list_dicts())) return []
def listDictionaries(self): retList = [] for spTag, spProvider in enchant.list_dicts(): spName = "%s [%s]" % (self.expandLanguage(spTag), spProvider.name) retList.append((spTag, spName)) return retList
# NOTE: # Reference : misspell correct python with keyboard proximity # photenic similarity # possiblily using skip-gram import enchant from nltk.metrics import edit_distance enchant.list_dicts() britsh_spell_dict = enchant.Dict('en_GB') american_spell_dict = enchant.Dict('en_US') # NOTE: # step one : check the correct vocs and the uncorrect vocs according to # the enchant dictionary def seperate_by_func(input_list, func): true_list = [] false_list = [] for element in input_list: if func(element) > 0: true_list.append(element) else: false_list.append(element) return true_list, false_list
# enchant hook test import sys import enchant backends = [x.name for x in enchant.Broker().describe()] langs = enchant.list_languages() dicts = [x[0] for x in enchant.list_dicts()] # At least one backend should be available if len(backends) < 1: print('E: No dictionary backend available') exit(1) if len(dicts) < 1: print('W: No dictionary available') print(80 * '-') print('PYTHONPATH: %s' % sys.path) print(80 * '-') print('Backends: ' + ', '.join(backends)) print('Languages: %s' % ', '.join(langs)) print('Dictionaries: %s' % dicts) print(80 * '-') # Try spell checking if English is availale l = 'en_US' if l in langs: d = enchant.Dict(l) print('d.check("hallo") %s' % d.check('hallo')) print('d.check("halllo") %s' % d.check('halllo')) print('d.suggest("halllo") %s' % d.suggest('halllo'))
class PreferencesDialog(wx.Dialog): """Dialog for changing pyspread's configuration preferences""" open_filetypes = ["pys", "pysu", "xls", "xlsx", "all"] save_filetypes = ["pys", "pysu", "xls", "all"] parameters = [ ("grid_rows", { "label": _(u"Grid rows"), "tooltip": _(u"Number of grid rows when starting pyspread"), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 0, "allow_long": True}, "prepocessor": int, }), ("grid_columns", { "label": _(u"Grid columns"), "tooltip": _(u"Number of grid columns when starting pyspread"), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 0, "allow_long": True}, "prepocessor": int, }), ("grid_tables", { "label": _(u"Grid tables"), "tooltip": _(u"Number of grid tables when starting pyspread"), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 0, "allow_long": True}, "prepocessor": int, }), ("max_result_length", { "label": _(u"Max. result length"), "tooltip": _(u"Maximum length of cell result string"), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 0, "allow_long": True}, "prepocessor": int, }), ("timeout", { "label": _(u"Timeout"), "tooltip": _(u"Maximum time that an evaluation process may take."), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 0, "allow_long": True}, "prepocessor": int, }), ("timer_interval", { "label": _(u"Timer interval"), "tooltip": _(u"Interval for periodic updating of timed cells."), "widget": wx.lib.intctrl.IntCtrl, "widget_args": [], "widget_kwargs": {"min": 100, "allow_long": True}, "prepocessor": int, }), ("gpg_key_fingerprint", { "label": _(u"GPG fingerprint"), "tooltip": _(u"Fingerprint of the GPG key for signing files"), "widget": wx.TextCtrl, "widget_args": [], "widget_kwargs": {}, "prepocessor": unicode, }), ("default_open_filetype", { "label": _(u"Open filetype"), "tooltip": _(u"Default filetype when opening via File -> Open"), "widget": wx.Choice, "widget_args": [(100, 50)], "widget_kwargs": {"choices": open_filetypes}, "prepocessor": open_filetypes.index, }), ("default_save_filetype", { "label": _(u"Save filetype"), "tooltip": _(u"Default filetype when saving via File -> Save As"), "widget": wx.Choice, "widget_args": [(100, 50)], "widget_kwargs": {"choices": save_filetypes}, "prepocessor": save_filetypes.index, }), # ("font_save_enabled", { # "label": _(u"Save font in pys"), # "tooltip": _(u"Enable font saving in pys and pysu files."), # "widget": wx.lib.intctrl.IntCtrl, # "widget_args": [], # "widget_kwargs": {"min": 0, "max": 1, "allow_long": False}, # "prepocessor": int, # }), ("ui_language", { "label": _(u"UI language"), "tooltip": _(u"User interface language. Choose 'system' for " + \ u"the system default language. Restart pyspread " + \ u"to activate."), "widget": wx.Choice, "widget_args": [(100, 50)], "widget_kwargs": {"choices": get_mo_languages()}, "prepocessor": get_mo_languages().index, }), ] if enchant is not None: list_dicts = [d[0] for d in enchant.list_dicts()] parameters += [( "spell_lang", { "label": _(u"Spell checker language"), "tooltip": _(u"The language that is used for the spell checker."), "widget": wx.Choice, "widget_args": [(100, 50)], "widget_kwargs": {"choices": list_dicts}, "prepocessor": list_dicts.index, } )] def __init__(self, *args, **kwargs): kwargs["title"] = _(u"Preferences") kwargs["style"] = \ wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME wx.Dialog.__init__(self, *args, **kwargs) self.labels = [] # Controls for entering parameters, NOT only TextCtrls self.textctrls = [] self.grid_sizer = wx.FlexGridSizer(0, 2, 2, 2) for parameter, info in self.parameters: label = info["label"] tooltip = info["tooltip"] value = config[parameter] self.labels.append(wx.StaticText(self, -1, label)) self.labels[-1].SetToolTipString(tooltip) widget = info["widget"] preproc = info["prepocessor"] if widget is wx.Choice: ctrl = widget(self, -1, *info["widget_args"], **info["widget_kwargs"]) ctrl.SetSelection(preproc(value)) else: ctrl = widget(self, -1, preproc(value), *info["widget_args"], **info["widget_kwargs"]) ctrl.SetToolTipString(tooltip) self.textctrls.append(ctrl) self.grid_sizer.Add(self.labels[-1], 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) self.grid_sizer.Add(self.textctrls[-1], 0, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) self.ok_button = wx.Button(self, wx.ID_OK) self.cancel_button = wx.Button(self, wx.ID_CANCEL) self.grid_sizer.Add(self.ok_button, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) self.grid_sizer.Add(self.cancel_button, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) self.SetSizer(self.grid_sizer) self.grid_sizer.Fit(self) self.grid_sizer.AddGrowableCol(1) for row in xrange(len(self.parameters)): self.grid_sizer.AddGrowableRow(row) self.Layout() self.SetSize((300, -1))
def get_dictionaries(): """returns a list with all the available enchant dictionary names""" _dicts = [] for dict_name, _ in enchant.list_dicts(): _dicts.append(dict_name) return _dicts