ConfigSet.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 traceback
  19. from .ConfigGroup import ConfigGroup
  20. class ConfigSet(ConfigGroup):
  21. '''
  22. After reading the configuration set items,
  23. the ConfigSet checks this field.
  24. If it is true, it will remove any nulls from
  25. the vector.
  26. subclasses can change this field in the constructor
  27. to avoid this "deletion" of nulls.
  28. '''
  29. def __init__(self, childType):
  30. self.childType = childType
  31. self.childrenList = []
  32. self.childrenListLen = 0
  33. def writeConfiguration(self, configurationView, param):
  34. for i in range(self.childrenListLen):
  35. #remove previous configuration
  36. configurationView.removeByName(i)
  37. for index,item in enumerate(self.childrenList):
  38. try:
  39. childView = configurationView.createInstance()
  40. configurationView.insertByName(index, childView)
  41. if callable( self.childType ):
  42. topic = self.childType()
  43. topic.cp_Index = item[0].Value
  44. topic.cp_Topic = item[1].Value
  45. topic.cp_Responsible = item[2].Value
  46. topic.cp_Time = item[3].Value
  47. topic.writeConfiguration(childView, param)
  48. except Exception:
  49. traceback.print_exc()
  50. def readConfiguration(self, configurationView, param):
  51. #each iteration represents a Topic row
  52. names = configurationView.ElementNames
  53. if names:
  54. for i in names:
  55. try:
  56. if callable( self.childType ):
  57. topic = self.childType()
  58. topic.readConfiguration(
  59. configurationView.getByName(i), param)
  60. self.childrenList.append(topic)
  61. except Exception:
  62. traceback.print_exc()
  63. self.childrenListLen = len(self.childrenList)