/usr/lib/libreoffice/share/extensions/voikko/pythonpath/SettingsEventHandler.py is in libreoffice-voikko 5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | # Libreoffice-voikko: Linguistic extension for LibreOffice
# Copyright (C) 2015 Harri Pitkänen <hatapitk@iki.fi>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 3 or later (the "GPL"), in which
# case the provisions of the GPL are applicable instead of those above.
import unohelper
import logging
import uno
from com.sun.star.lang import XServiceInfo
from com.sun.star.awt import XContainerWindowEventHandler
from com.sun.star.beans import UnknownPropertyException
from PropertyManager import PropertyManager
from VoikkoHandlePool import VoikkoHandlePool
from libvoikko import Voikko
class SettingsEventHandler(unohelper.Base, XServiceInfo, XContainerWindowEventHandler):
def __init__(self, ctx, *args):
print("SettingsEventHandler.__init__")
self.__dictionaryVariantList = ["standard: standard dictionary"]
# From XServiceInfo
def getImplementationName(self):
return SettingsEventHandler.IMPLEMENTATION_NAME
def supportsService(self, serviceName):
return serviceName in self.getSupportedServiceNames()
def getSupportedServiceNames(self):
return SettingsEventHandler.SUPPORTED_SERVICE_NAMES
# From XContainerWindowEventHandler
def callHandlerMethod(self, xWindow, eventObject, methodName):
if methodName != "external_event":
return False
if eventObject == "ok":
self.__saveOptionsFromWindowToRegistry(xWindow)
PropertyManager.getInstance().reloadVoikkoSettings()
return True
if eventObject == "back" or eventObject == "initialize":
self.__initOptionsWindowFromRegistry(xWindow)
return True
return False
def getSupportedMethodNames(self):
return ("external_event",)
def __initOptionsWindowFromRegistry(self, window):
logging.debug("initOptionsWindowFromRegistry()");
hyphWordPartsValue = False
hyphUnknownWordsValue = True
try:
hyphWordPartsValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/hyphenator", "hyphWordParts")
hyphUnknownWordsValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/hyphenator", "hyphUnknownWords")
except UnknownPropertyException as e:
logging.exception("SettingsEventHandler: UnknownPropertyException", e)
return
logging.debug("hyphWordParts = " + str(hyphWordPartsValue))
hyphWordParts = window.getControl("hyphWordParts")
hyphWordPartsProps = hyphWordParts.getModel()
hyphWordPartsProps.setPropertyValue("State", 1 if hyphWordPartsValue else 0)
hyphUnknownWords = window.getControl("hyphUnknownWords")
hyphUnknownWordsProps = hyphUnknownWords.getModel()
hyphUnknownWordsProps.setPropertyValue("State", 1 if hyphUnknownWordsValue else 0)
self.__initVariantDropdown(window)
def __saveOptionsFromWindowToRegistry(self, window):
logging.debug("SettingsEventHandler.__saveOptionsFromWindowToRegistry")
hyphWordParts = window.getControl("hyphWordParts")
hyphWordPartsProps = hyphWordParts.getModel()
hyphWordPartsValue = hyphWordPartsProps.getPropertyValue("State") # 0 = unchecked, 1 = checked
hyphUnknownWords = window.getControl("hyphUnknownWords")
hyphUnknownWordsProps = hyphUnknownWords.getModel()
hyphUnknownWordsValue = hyphUnknownWordsProps.getPropertyValue("State") # 0 = unchecked, 1 = checked
rootView = PropertyManager.getRegistryProperties("/org.puimula.ooovoikko.Config/hyphenator")
rootView.setHierarchicalPropertyValue("hyphWordParts", hyphWordPartsValue == 1)
rootView.setHierarchicalPropertyValue("hyphUnknownWords", hyphUnknownWordsValue == 1)
rootView.commitChanges()
# dictionary variant
variantValue = self.__getSelectedVariant(window)
rootView = PropertyManager.getRegistryProperties("/org.puimula.ooovoikko.Config/dictionary")
rootView.setHierarchicalPropertyValue("variant", variantValue)
rootView.commitChanges()
def __initVariantDropdown(self, windowContainer):
variantDropdown = windowContainer.getControl("variant")
variantProps = variantDropdown.getModel()
# populate dropdown list with available variants
self.__initAvailableVariants()
uno.invoke(variantProps, "setPropertyValue", ("StringItemList", uno.Any("[]string", tuple(self.__dictionaryVariantList))))
# read selected dictionary variant from registry
registryVariantValue = "standard"
try:
registryVariantValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/dictionary", "variant")
except UnknownPropertyException as e:
logging.exception(e)
return
registryVariantValue = registryVariantValue + ": "
selectedValues = [0]
for i, dVariant in enumerate(self.__dictionaryVariantList):
if dVariant.startswith(registryVariantValue):
selectedValues[0] = i;
break;
# set the selected item in the dropdown list
uno.invoke(variantProps, "setPropertyValue", ("SelectedItems", uno.Any("[]short", tuple(selectedValues))))
def __initAvailableVariants(self):
dicts = Voikko.listDicts(VoikkoHandlePool.getInstance().getDictionaryPath())
self.__dictionaryVariantList = []
for vDict in dicts:
dictName = vDict.variant + ": " + vDict.description
self.__dictionaryVariantList.append(dictName)
def __getSelectedVariant(self, windowContainer):
variantDropdown = windowContainer.getControl("variant")
variantProps = variantDropdown.getModel()
# get all values
stringListValue = variantProps.getPropertyValue("StringItemList")
# get the selected item index
selectedValues = variantProps.getPropertyValue("SelectedItems")
# parse the variant id from the string
selectedValue = stringListValue[selectedValues[0]]
if ":" in selectedValue:
return selectedValue[0:selectedValue.find(":")]
logging.error("Failed to get the selected variant, returning default")
return "standard"
SettingsEventHandler.IMPLEMENTATION_NAME = "org.puimula.ooovoikko.SettingsEventHandlerImplementation"
SettingsEventHandler.SUPPORTED_SERVICE_NAMES = ("org.puimula.ooovoikko.SettingsEventHandlerService",)
|