Properties.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from com.sun.star.beans import PropertyValue
  19. '''
  20. Simplifies handling Arrays of PropertyValue.
  21. To make a use of this class, instantiate it, and call
  22. the put(propName,propValue) method.
  23. caution: propName should always be a String.
  24. When finished, call the getProperties() method to get an array of the set properties.
  25. '''
  26. class Properties(dict):
  27. @classmethod
  28. def getPropertyValue(self, props, propName):
  29. for i in props:
  30. if propName == i.Name:
  31. return i.Value
  32. raise AttributeError ("Property '" + propName + "' not found.")
  33. @classmethod
  34. def hasPropertyValue(self, props, propName):
  35. for i in props:
  36. if propName == i.Name:
  37. return True
  38. return False
  39. @classmethod
  40. def getProperties(self, _map):
  41. pv = []
  42. for k,v in _map.items():
  43. pv.append(self.createProperty(k, v))
  44. return pv
  45. @classmethod
  46. def createProperty(self, name, value, handle=None):
  47. pv = PropertyValue()
  48. pv.Name = name
  49. pv.Value = value
  50. if handle is not None:
  51. pv.Handle = handle
  52. return pv
  53. def getProperties1(self):
  54. return self.getProperties(self)