def callHandlerMethod(self, xWindow, eventObject, methodName): if methodName != "external_event": return False if eventObject == "ok": self.__saveOptionsFromWindowToRegistry(xWindow) PropertyManager.getInstance().reloadDivvunSettings() return True if eventObject == "back" or eventObject == "initialize": self.__initOptionsWindowFromRegistry(xWindow) return True return False
def isValid(self, word, locale, properties): DivvunHandlePool.mutex.acquire() try: divvun = DivvunHandlePool.getInstance().getHandle(locale) if divvun is None: return False PropertyManager.getInstance().setValues(properties) result = divvun.spell(word) PropertyManager.getInstance().resetValues(properties) return result finally: DivvunHandlePool.mutex.release()
def saveIgnoredRules(ignoredRules): # type: (Set[str]) -> None """Save ignored rule identifiers to registry""" gcsettingTids = " ".join(ignoredRules) rootView = PropertyManager.getRegistryProperties("/no.divvun.gramcheck.Config/dictionary") rootView.setHierarchicalPropertyValue("gcignored", gcsettingTids) logging.debug("KBU: gcignored registry set to {}".format(gcsettingTids)) rootView.commitChanges()
def removeLinguServiceEventListener(self, xLstnr): logging.debug("SpellChecker.removeLinguServiceEventListener") DivvunHandlePool.mutex.acquire() try: return PropertyManager.getInstance( ).removeLinguServiceEventListener(xLstnr) finally: DivvunHandlePool.mutex.release()
def addLinguServiceEventListener(self, xLstnr): logging.debug("Hyphenator.addLinguServiceEventListener") DivvunHandlePool.mutex.acquire() try: return PropertyManager.getInstance().addLinguServiceEventListener( xLstnr) finally: DivvunHandlePool.mutex.release()
def readIgnoredRules(): # type: () -> Set[str] """Read ignored rule identifiers from registry""" try: registryRaw = PropertyManager.getInstance().readFromRegistry("/no.divvun.gramcheck.Config/dictionary", "gcignored") logging.debug("KBU: Read gcignored registryRaw {}".format(registryRaw)) return set(registryRaw.split()) except UnknownPropertyException as e: logging.exception(e) return set()
def spell(self, word, locale, properties): # Check if diagnostic message should be returned if word == "DivvunGetStatusInformation": suggestions = [ DivvunHandlePool.getInstance().getInitializationStatus() ] return SpellAlternatives(word, suggestions, locale) DivvunHandlePool.mutex.acquire() try: divvun = DivvunHandlePool.getInstance().getHandle(locale) if divvun is None: return None PropertyManager.getInstance().setValues(properties) if divvun.spell(word): PropertyManager.getInstance().resetValues(properties) return None suggestions = divvun.suggest(word) PropertyManager.getInstance().resetValues(properties) return SpellAlternatives(word, suggestions, locale) finally: DivvunHandlePool.mutex.release()
"Please report this to http://divvun.no/contact.html :\n", "sys.version = " + str(sys.version), "sys.path = " + str(sys.path), "sys.prefix = " + str(sys.prefix), "sys.exec_prefix = " + str(sys.exec_prefix), "\nTraceback:", "".join(traceback.format_exception(*sys.exc_info())) ]) logging.warn(msg) if not loadingFailed: messageBox(msg) loadingFailed = True # Presumably this can fail too, catch the same kinds of errors here: if not (loadingFailed or PropertyManager.loadingFailed): try: # Force initialization of property manager so that it is done before anything else. PropertyManager.getInstance() # name of g_ImplementationHelper is significant, Python component loader expects to find it g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(SettingsEventHandler, \ SettingsEventHandler.IMPLEMENTATION_NAME, SettingsEventHandler.SUPPORTED_SERVICE_NAMES,) g_ImplementationHelper.addImplementation(SpellChecker, \ SpellChecker.IMPLEMENTATION_NAME, SpellChecker.SUPPORTED_SERVICE_NAMES,) g_ImplementationHelper.addImplementation(Hyphenator, \ Hyphenator.IMPLEMENTATION_NAME, Hyphenator.SUPPORTED_SERVICE_NAMES,) g_ImplementationHelper.addImplementation(GrammarChecker, \ GrammarChecker.IMPLEMENTATION_NAME, GrammarChecker.SUPPORTED_SERVICE_NAMES,) except OSError as e:
def hyphenate(self, word, locale, nMaxLeading, properties): logging.debug("Hyphenator.hyphenate") if len(word) > 10000: return None DivvunHandlePool.mutex.acquire() try: divvun = DivvunHandlePool.getInstance().getHandle(locale) if divvun is None: return None PropertyManager.getInstance().setValues(properties) minLeading = PropertyManager.getInstance().getHyphMinLeading() minTrailing = PropertyManager.getInstance().getHyphMinTrailing() wlen = len(word) # If the word is too short to be hyphenated, return no hyphenation points if wlen < PropertyManager.getInstance().getHyphMinWordLength( ) or wlen < minLeading + minTrailing: PropertyManager.getInstance().resetValues(properties) return None hyphenationPoints = divvun.getHyphenationPattern(word) if hyphenationPoints is None: PropertyManager.getInstance().resetValues(properties) return None # find the hyphenation point hyphenPos = -1 i = wlen - minTrailing # The last generally allowed hyphenation point if i > nMaxLeading: i = nMaxLeading # The last allowed point on this line while i >= minLeading and hyphenPos == -1: if word[i] == '\'': i = i - 1 continue if hyphenationPoints[i] == '-' or hyphenationPoints[i] == '=': hyphenPos = i break i = i - 1 # return the result PropertyManager.getInstance().resetValues(properties) if hyphenPos != -1: return HyphenatedWord(word, hyphenPos - 1, locale) else: return None finally: DivvunHandlePool.mutex.release()
def createPossibleHyphens(self, word, locale, properties): logging.debug("Hyphenator.createPossibleHyphens") wlen = len(word) if wlen > 10000: return None DivvunHandlePool.mutex.acquire() try: divvun = DivvunHandlePool.getInstance().getHandle(locale) if divvun is None: return None PropertyManager.getInstance().setValues(properties) # If the word is too short to be hyphenated, return no hyphenation points minLeading = PropertyManager.getInstance().getHyphMinLeading() minTrailing = PropertyManager.getInstance().getHyphMinTrailing() if wlen < PropertyManager.getInstance().getHyphMinWordLength( ) or wlen < minLeading + minTrailing: PropertyManager.getInstance().resetValues(properties) return None hyphenationPoints = divvun.getHyphenationPattern(word) if hyphenationPoints is None: PropertyManager.getInstance().resetValues(properties) return None hyphenSeq = [] hyphenatedWord = "" for i in range(0, wlen): hyphenatedWord = hyphenatedWord + word[i] if i >= minLeading - 1 and i < wlen - minTrailing and hyphenationPoints[ i + 1] == '-': hyphenSeq.append(i) hyphenatedWord = hyphenatedWord + "=" res = PossibleHyphens(word, hyphenatedWord, hyphenSeq, locale) PropertyManager.getInstance().resetValues(properties) return res finally: DivvunHandlePool.mutex.release()