Index: gc_core/py/oxt/OptionsDialog.xcs ================================================================== --- gc_core/py/oxt/OptionsDialog.xcs +++ gc_core/py/oxt/OptionsDialog.xcs @@ -22,12 +22,14 @@ The data for one leaf. 1 1 0 + 0 1 + Index: gc_lang/fr/oxt/Graphspell.py ================================================================== --- gc_lang/fr/oxt/Graphspell.py +++ gc_lang/fr/oxt/Graphspell.py @@ -53,31 +53,40 @@ self.sImplementationName = "net.grammalecte.graphspell" self.tSupportedServiceNames = (self.sServiceName, ) self.xSvMgr = ctx.ServiceManager self.locales = tuple([ Locale(t[0], t[1], t[2]) for t in lLocale ]) self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False) - xChild = self.xSettingNode.getByName("o_fr") + self.xOptionNode = self.xSettingNode.getByName("o_fr") personal_dic = "" - if (xChild.getPropertyValue("use_personal_dic")): - sPersonalDicJSON = xChild.getPropertyValue("personal_dic") + if (self.xOptionNode.getPropertyValue("use_personal_dic")): + sPersonalDicJSON = self.xOptionNode.getPropertyValue("personal_dic") if sPersonalDicJSON: try: personal_dic = json.loads(sPersonalDicJSON) except: print("Graphspell: wrong personal_dic") traceback.print_exc() self.oGraphspell = SpellChecker("fr", "fr.bdic", "", "", personal_dic) - # self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker") - # self.xHunspellLocale = Locale('fr', 'MC', '') - # self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale') - # self.xHunspellLocale.Language = 'fr' - # self.xHunspellLocale.Country = 'FR' + self.loadHunspell() # print("Graphspell: init done") except: print("Graphspell: init failed") traceback.print_exc() + def loadHunspell (self): + # Hunspell is a fallback spellchecker + try: + self.xHunspell = self.xSvMgr.createInstance("org.openoffice.lingu.MySpellSpellChecker") + except: + print("Hunspell: init failed") + traceback.print_exc() + self.xHunspell = False + self.bHunspell = False + else: + self.xHunspellLocale = Locale('fr', 'MC', '') + self.bHunspell = not bool(self.xOptionNode.getPropertyValue("use_graphspell_sugg")) + # XServiceName def getServiceName (self): return self.sImplementationName #self.sServiceName # XServiceInfo @@ -106,52 +115,47 @@ # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html def isValid (self, aWord, rLocale, aProperties): try: aWord = zElidedWords.sub("", aWord.rstrip("."), count=1) return self.oGraphspell.isValidToken(aWord) + # return self.xHunspell.isValid(aWord, self.xHunspellLocale, aProperties) except: traceback.print_exc() return False - # try: - # if self.xHunspell: - # return self.xHunspell.isValid(aWord, self.xHunspellLocale, aProperties) - # except: - # traceback.print_exc() - # return False def spell (self, aWord, aLocale, aProperties): "returns an object SpellAlternatives" - self.listSpellChecker() - lSugg = [] - for l in self.oGraphspell.suggest(aWord): - lSugg.extend(l) - return SpellAlternatives(aWord, tuple(lSugg)) - # try: - # if self.xHunspell: - # return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties) - # except: - # traceback.print_exc() - # return None + try: + if not self.bHunspell: + lSugg = [] + for l in self.oGraphspell.suggest(aWord): + lSugg.extend(l) + return SpellAlternatives(aWord, tuple(lSugg)) + else: + # fallback dictionary suggestions (Hunspell) + return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties) + except: + traceback.print_exc() + return None # XServiceDisplayName def getServiceDisplayName(self, aLocale): return "Graphspell (fr)" # Other def listSpellChecker (self): xLinguServiceManager = self.xSvMgr.createInstance("com.sun.star.linguistic2.LinguServiceManager") - #print ("STTTSpeller: lingu service manager = %s" % repr(xLinguServiceManager)) lService = xLinguServiceManager.getAvailableServices('com.sun.star.linguistic2.SpellChecker', Locale("fr", "MC", "")) - #print ("STTTSpeller: spell services: %s" % repr(lService)) - for speller in lService: - print(repr(speller)) - #if speller == self.ImplementationName: + for sSpellchecker in lService: + print(repr(sSpellchecker)) + #if sSpellchecker == self.ImplementationName: # continue - #self.fallback_sc = self.xSvMgr.createInstance (speller) - #if self.fallback_sc: - # #print ("STTTSpeller: found other spell checker: %s" % speller) + #self.xFallbackSpellChecker = self.xSvMgr.createInstance(sSpellchecker) + #if self.xFallbackSpellChecker: + # print("Spell checker: %s" % xSpellChecker) # break + class SpellAlternatives (unohelper.Base, XSpellAlternatives): def __init__ (self, sWord, lSugg): try: