scenario.py 2.4 KB

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