ConfigGroup.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. import inspect
  19. class ConfigGroup(object):
  20. root = None
  21. def __init__(self):
  22. self.root = None
  23. def writeConfiguration(self, configurationView, param):
  24. for name,data in inspect.getmembers(self):
  25. if name.startswith(param):
  26. self.writeField( name, configurationView, param)
  27. def writeField(self, field, configView, prefix):
  28. propertyName = field[len(prefix):]
  29. child = getattr(self, field)
  30. if isinstance(child, ConfigGroup):
  31. child.writeConfiguration(configView.getByName(propertyName),
  32. prefix)
  33. else:
  34. setattr(configView,propertyName,getattr(self,field))
  35. def readConfiguration(self, configurationView, param):
  36. for name,data in inspect.getmembers(self):
  37. if name.startswith(param):
  38. self.readField( name, configurationView, param)
  39. def readField(self, field, configView, prefix):
  40. propertyName = field[len(prefix):]
  41. child = getattr(self, field)
  42. if isinstance(child, ConfigGroup):
  43. child.setRoot(self.root);
  44. child.readConfiguration(configView.getByName(propertyName),
  45. prefix)
  46. else:
  47. value = configView.getByName(propertyName)
  48. if value is not None:
  49. setattr(self,field, value)
  50. def setRoot(self, newRoot):
  51. self.root = newRoot