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
|
import uno
import unohelper
import lightproof_opts_hu_HU
from lightproof_impl_hu_HU import pkg
from com.sun.star.lang import XServiceInfo
from com.sun.star.awt import XContainerWindowEventHandler
# options
options = {}
def load(context):
try:
l = LightproofOptionsEventHandler(context)
for i in lightproof_opts_hu_HU.lopts:
l.load(i)
except:
pass
def get_option(page, option):
try:
return options[page + "," + option]
except:
try:
return options[page[:2] + "," + option]
except:
return 0
def set_option(page, option, value):
options[page + "," + option] = int(value)
class LightproofOptionsEventHandler( unohelper.Base, XServiceInfo, XContainerWindowEventHandler ):
def __init__( self, ctx ):
p = uno.createUnoStruct( "com.sun.star.beans.PropertyValue" )
p.Name = "nodepath"
p.Value = "/org.openoffice.Lightproof_%s/Leaves"%pkg
self.xConfig = ctx.ServiceManager.createInstance( 'com.sun.star.configuration.ConfigurationProvider' )
self.node = self.xConfig.createInstanceWithArguments( 'com.sun.star.configuration.ConfigurationUpdateAccess', (p, ) )
self.service = "org.libreoffice.comp.pyuno.LightproofOptionsEventHandler." + pkg
self.ImplementationName = self.service
self.services = (self.service, )
# XContainerWindowEventHandler
def callHandlerMethod(self, aWindow, aEventObject, sMethod):
if sMethod == "external_event":
return self.handleExternalEvent(aWindow, aEventObject)
def getSupportedMethodNames(self):
return ("external_event", )
def handleExternalEvent(self, aWindow, aEventObject):
sMethod = aEventObject
if sMethod == "ok":
self.saveData(aWindow)
elif sMethod == "back" or sMethod == "initialize":
self.loadData(aWindow)
return True
def load(self, sWindowName):
child = self.getChild(sWindowName)
for i in lightproof_opts_hu_HU.lopts[sWindowName]:
sValue = child.getPropertyValue(i)
if sValue == '':
if i in lightproof_opts_hu_HU.lopts_default[sWindowName]:
sValue = 1
else:
sValue = 0
set_option(sWindowName, i, sValue)
def loadData(self, aWindow):
sWindowName = self.getWindowName(aWindow)
if (sWindowName == None):
return
child = self.getChild(sWindowName)
for i in lightproof_opts_hu_HU.lopts[sWindowName]:
sValue = child.getPropertyValue(i)
if sValue == '':
if i in lightproof_opts_hu_HU.lopts_default[sWindowName]:
sValue = 1
else:
sValue = 0
xControl = aWindow.getControl(i)
xControl.State = sValue
set_option(sWindowName, i, sValue)
def saveData(self, aWindow):
sWindowName = self.getWindowName(aWindow)
if (sWindowName == None):
return
child = self.getChild(sWindowName)
for i in lightproof_opts_hu_HU.lopts[sWindowName]:
xControl = aWindow.getControl(i)
sValue = xControl.State
child.setPropertyValue(i, str(sValue))
set_option(sWindowName, i, sValue)
self.commitChanges()
def getWindowName(self, aWindow):
sName = aWindow.getModel().Name
if sName in lightproof_opts_hu_HU.lopts:
return sName
return None
# XServiceInfo method implementations
def getImplementationName (self):
return self.ImplementationName
def supportsService(self, ServiceName):
return (ServiceName in self.services)
def getSupportedServiceNames (self):
return self.services
def getChild(self, name):
return self.node.getByName(name)
def commitChanges(self):
self.node.commitChanges()
return True
|