OpenOffice.org: utilisation des boîtes de dialogue du système par défaut.
[macros-openoffice.git] / auf-poste-client-reflets / openoffice / DialogHandler.py
CommitLineData
a80ac883
P
1#!
2# -*- coding: utf_8 -*-
4928a69a
P
3"""
4Extension pour faciliter l'intégration du logiciel Coda.
5Gestion de la fenêtre des options.
6
7Copyright : Agence universitaire de la Francophonie
8Licence : GNU General Public Licence, version 2
9Auteur : Jean Christophe André
10Date de création : juillet 2009
11"""
a80ac883
P
12import uno
13import unohelper
14
15# interfaces
16from com.sun.star.lang import XServiceInfo
17from com.sun.star.awt import XContainerWindowEventHandler
18
19# main class
20class DialogHandler(unohelper.Base, XServiceInfo, XContainerWindowEventHandler):
21 def __init__(self, ctx):
22 self.ctx = ctx;
23 self.cp = self.ctx.ServiceManager.createInstanceWithContext(
24 "com.sun.star.configuration.ConfigurationProvider",
25 self.ctx)
26 node = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
27 node.Name = "nodepath"
28 node.Value = "/org.openoffice.VCL/Settings/Transfer"
29 self.node = node
30 self.cfg_names = ("SelectionTimeout",)
31 return
32
33 # XContainerWindowEventHandler
34 def callHandlerMethod(self, window, eventObject, method):
35 if method == "external_event":
36 try:
37 self.handleExternalEvent(window, eventObject)
38 except:
39 pass
40 return True
41
42 # XContainerWindowEventHandler
43 def getSupportedMethodNames(self):
44 return ("external_event",)
45
46 def supportsService(self, name):
47 return False
48
49 def getImplementationName(self):
50 return "org.auf.openoffice.reflets.DialogHandler"
51
52 def getSupportedServiceNames(self):
53 return ()
54
55 def handleExternalEvent(self, window, eventName):
56 if eventName == "ok":
57 self.saveData(window)
58 elif eventName == "back":
59 self.loadData(window, "back")
60 elif eventName == "initialize":
61 self.loadData(window, "initialize")
62 return True
63
64 # load and set the data
65 def loadData(self, window, ev):
66 name = window.getModel().Name
67 if name != "RefletsDialog":
68 return
69 settings = self.configreader()
70 if not settings:
71 return
72 for name in self.cfg_names:
73 window.getControl(name).setValue(settings.get(name, ''))
74 return
75
76 # making the save data
77 def saveData(self,window):
78 name = window.getModel().Name
79 if name != "RefletsDialog":
80 return
81 settings = []
82 for name in self.cfg_names:
83 settings.append(str(int(window.getControl(name).Value)))
84 self.configwriter(tuple(settings))
85 return
86
87 # read configuration
88 def configreader(self):
89 settings = {}
90 try:
91 ConfigReader = self.cp.createInstanceWithArguments(
92 "com.sun.star.configuration.ConfigurationAccess",
93 (self.node,))
94 #cfg_values = ConfigReader.getPropertyValues(self.cfg_names)
95 for i in range(len(self.cfg_names)):
96 cfg_value = ConfigReader.getByName(self.cfg_names[i])
97 settings[self.cfg_names[i]] = cfg_value
98 except:
99 pass
100 return settings
101
102 # write configuration, cfg_values: tuple
103 # keep the order of the values
104 def configwriter(self, cfg_values):
105 try:
106 ConfigWriter = self.cp.createInstanceWithArguments(
107 "com.sun.star.configuration.ConfigurationUpdateAccess",
108 (self.node,))
109 #ConfigWriter.setPropertyValues(self.cfg_names, cfg_values)
110 for i in range(len(self.cfg_names)):
111 ConfigWriter.replaceByName(self.cfg_names[i], cfg_values[i])
112 ConfigWriter.commitChanges()
113 except:
114 pass
115
116# uno implementation
117g_ImplementationHelper = unohelper.ImplementationHelper()
118g_ImplementationHelper.addImplementation( \
119 DialogHandler, "org.auf.openoffice.reflets.DialogHandler", \
120 ("org.auf.openoffice.reflets.DialogHandler",),)