Debian Codegraph @

dictionaries/pt_BR/pythonpath/lightproof_handler_pt_BR.py

raw
1 import uno
2 import unohelper
3 import lightproof_opts_pt_BR
4 from com.sun.star.lang import XServiceInfo
5 from com.sun.star.awt import XContainerWindowEventHandler
6
7 pkg = "pt_BR"
8
9 # options
10 options = {}
11
12 def load(context):
13 try:
14 l = LightproofOptionsEventHandler(context)
15 for i in lightproof_opts_pt_BR.lopts:
16 l.load(i)
17 except Exception:
18 pass
19
20 def get_option(page, option):
21 try:
22 return options[page + "," + option]
23 except Exception:
24 try:
25 return options[page[:2] + "," + option]
26 except Exception:
27 return 0
28
29 def set_option(page, option, value):
30 options[page + "," + option] = int(value)
31
32 class LightproofOptionsEventHandler( unohelper.Base, XServiceInfo, XContainerWindowEventHandler ):
33 def __init__( self, ctx ):
34 p = uno.createUnoStruct( "com.sun.star.beans.PropertyValue" )
35 p.Name = "nodepath"
36 p.Value = "/org.openoffice.Lightproof_%s/Leaves"%pkg
37 self.xConfig = ctx.ServiceManager.createInstance( 'com.sun.star.configuration.ConfigurationProvider' )
38 self.node = self.xConfig.createInstanceWithArguments( 'com.sun.star.configuration.ConfigurationUpdateAccess', (p, ) )
39 self.service = "org.libreoffice.comp.pyuno.LightproofOptionsEventHandler." + pkg
40 self.ImplementationName = self.service
41 self.services = (self.service, )
42
43 # XContainerWindowEventHandler
44 def callHandlerMethod(self, aWindow, aEventObject, sMethod):
45 if sMethod == "external_event":
46 return self.handleExternalEvent(aWindow, aEventObject)
47
48 def getSupportedMethodNames(self):
49 return ("external_event", )
50
51 def handleExternalEvent(self, aWindow, aEventObject):
52 sMethod = aEventObject
53 if sMethod == "ok":
54 self.saveData(aWindow)
55 elif sMethod == "back" or sMethod == "initialize":
56 self.loadData(aWindow)
57 return True
58
59 def load(self, sWindowName):
60 child = self.getChild(sWindowName)
61 for i in lightproof_opts_pt_BR.lopts[sWindowName]:
62 sValue = child.getPropertyValue(i)
63 if sValue == '':
64 if i in lightproof_opts_pt_BR.lopts_default[sWindowName]:
65 sValue = 1
66 else:
67 sValue = 0
68 set_option(sWindowName, i, sValue)
69
70 def loadData(self, aWindow):
71 sWindowName = self.getWindowName(aWindow)
72 if (sWindowName is None):
73 return
74 child = self.getChild(sWindowName)
75 for i in lightproof_opts_pt_BR.lopts[sWindowName]:
76 sValue = child.getPropertyValue(i)
77 if sValue == '':
78 if i in lightproof_opts_pt_BR.lopts_default[sWindowName]:
79 sValue = 1
80 else:
81 sValue = 0
82 xControl = aWindow.getControl(i)
83 xControl.State = sValue
84 set_option(sWindowName, i, sValue)
85
86 def saveData(self, aWindow):
87 sWindowName = self.getWindowName(aWindow)
88 if (sWindowName is None):
89 return
90 child = self.getChild(sWindowName)
91 for i in lightproof_opts_pt_BR.lopts[sWindowName]:
92 xControl = aWindow.getControl(i)
93 sValue = xControl.State
94 child.setPropertyValue(i, str(sValue))
95 set_option(sWindowName, i, sValue)
96 self.commitChanges()
97
98 def getWindowName(self, aWindow):
99 sName = aWindow.getModel().Name
100 if sName in lightproof_opts_pt_BR.lopts:
101 return sName
102 return None
103
104 # XServiceInfo method implementations
105 def getImplementationName (self):
106 return self.ImplementationName
107
108 def supportsService(self, ServiceName):
109 return (ServiceName in self.services)
110
111 def getSupportedServiceNames (self):
112 return self.services
113
114 def getChild(self, name):
115 return self.node.getByName(name)
116
117 def commitChanges(self):
118 self.node.commitChanges()
119 return True