lightproof_handler_en.py 3.9 KB

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