scenario.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. String,
  5. Integer,
  6. Bool,
  7. Sequence,
  8. Convertible,
  9. )
  10. from .cell_range import MultiCellRange
  11. class InputCells(Serialisable):
  12. tagname = "inputCells"
  13. r = String()
  14. deleted = Bool(allow_none=True)
  15. undone = Bool(allow_none=True)
  16. val = String()
  17. numFmtId = Integer(allow_none=True)
  18. def __init__(self,
  19. r=None,
  20. deleted=False,
  21. undone=False,
  22. val=None,
  23. numFmtId=None,
  24. ):
  25. self.r = r
  26. self.deleted = deleted
  27. self.undone = undone
  28. self.val = val
  29. self.numFmtId = numFmtId
  30. class Scenario(Serialisable):
  31. tagname = "scenario"
  32. inputCells = Sequence(expected_type=InputCells)
  33. name = String()
  34. locked = Bool(allow_none=True)
  35. hidden = Bool(allow_none=True)
  36. user = String(allow_none=True)
  37. comment = String(allow_none=True)
  38. __elements__ = ('inputCells',)
  39. __attrs__ = ('name', 'locked', 'hidden', 'user', 'comment', 'count')
  40. def __init__(self,
  41. inputCells=(),
  42. name=None,
  43. locked=False,
  44. hidden=False,
  45. count=None,
  46. user=None,
  47. comment=None,
  48. ):
  49. self.inputCells = inputCells
  50. self.name = name
  51. self.locked = locked
  52. self.hidden = hidden
  53. self.user = user
  54. self.comment = comment
  55. @property
  56. def count(self):
  57. return len(self.inputCells)
  58. class ScenarioList(Serialisable):
  59. tagname = "scenarios"
  60. scenario = Sequence(expected_type=Scenario)
  61. current = Integer(allow_none=True)
  62. show = Integer(allow_none=True)
  63. sqref = Convertible(expected_type=MultiCellRange, allow_none=True)
  64. __elements__ = ('scenario',)
  65. def __init__(self,
  66. scenario=(),
  67. current=None,
  68. show=None,
  69. sqref=None,
  70. ):
  71. self.scenario = scenario
  72. self.current = current
  73. self.show = show
  74. self.sqref = sqref
  75. def append(self, scenario):
  76. s = self.scenario
  77. s.append(scenario)
  78. self.scenario = s
  79. def __bool__(self):
  80. return bool(self.scenario)