graphic.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.xml.constants import CHART_NS, DRAWING_NS
  3. from openpyxl.descriptors.serialisable import Serialisable
  4. from openpyxl.descriptors import (
  5. Typed,
  6. Bool,
  7. String,
  8. Alias,
  9. )
  10. from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
  11. from .effect import (
  12. EffectList,
  13. EffectContainer,
  14. )
  15. from .fill import (
  16. Blip,
  17. GradientFillProperties,
  18. BlipFillProperties,
  19. )
  20. from .picture import PictureFrame
  21. from .properties import (
  22. NonVisualDrawingProps,
  23. NonVisualGroupShape,
  24. GroupShapeProperties,
  25. )
  26. from .relation import ChartRelation
  27. from .xdr import XDRTransform2D
  28. class GraphicFrameLocking(Serialisable):
  29. noGrp = Bool(allow_none=True)
  30. noDrilldown = Bool(allow_none=True)
  31. noSelect = Bool(allow_none=True)
  32. noChangeAspect = Bool(allow_none=True)
  33. noMove = Bool(allow_none=True)
  34. noResize = Bool(allow_none=True)
  35. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  36. def __init__(self,
  37. noGrp=None,
  38. noDrilldown=None,
  39. noSelect=None,
  40. noChangeAspect=None,
  41. noMove=None,
  42. noResize=None,
  43. extLst=None,
  44. ):
  45. self.noGrp = noGrp
  46. self.noDrilldown = noDrilldown
  47. self.noSelect = noSelect
  48. self.noChangeAspect = noChangeAspect
  49. self.noMove = noMove
  50. self.noResize = noResize
  51. self.extLst = extLst
  52. class NonVisualGraphicFrameProperties(Serialisable):
  53. tagname = "cNvGraphicFramePr"
  54. graphicFrameLocks = Typed(expected_type=GraphicFrameLocking, allow_none=True)
  55. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  56. def __init__(self,
  57. graphicFrameLocks=None,
  58. extLst=None,
  59. ):
  60. self.graphicFrameLocks = graphicFrameLocks
  61. self.extLst = extLst
  62. class NonVisualGraphicFrame(Serialisable):
  63. tagname = "nvGraphicFramePr"
  64. cNvPr = Typed(expected_type=NonVisualDrawingProps)
  65. cNvGraphicFramePr = Typed(expected_type=NonVisualGraphicFrameProperties)
  66. __elements__ = ('cNvPr', 'cNvGraphicFramePr')
  67. def __init__(self,
  68. cNvPr=None,
  69. cNvGraphicFramePr=None,
  70. ):
  71. if cNvPr is None:
  72. cNvPr = NonVisualDrawingProps(id=0, name="Chart 0")
  73. self.cNvPr = cNvPr
  74. if cNvGraphicFramePr is None:
  75. cNvGraphicFramePr = NonVisualGraphicFrameProperties()
  76. self.cNvGraphicFramePr = cNvGraphicFramePr
  77. class GraphicData(Serialisable):
  78. tagname = "graphicData"
  79. namespace = DRAWING_NS
  80. uri = String()
  81. chart = Typed(expected_type=ChartRelation, allow_none=True)
  82. def __init__(self,
  83. uri=CHART_NS,
  84. chart=None,
  85. ):
  86. self.uri = uri
  87. self.chart = chart
  88. class GraphicObject(Serialisable):
  89. tagname = "graphic"
  90. namespace = DRAWING_NS
  91. graphicData = Typed(expected_type=GraphicData)
  92. def __init__(self,
  93. graphicData=None,
  94. ):
  95. if graphicData is None:
  96. graphicData = GraphicData()
  97. self.graphicData = graphicData
  98. class GraphicFrame(Serialisable):
  99. tagname = "graphicFrame"
  100. nvGraphicFramePr = Typed(expected_type=NonVisualGraphicFrame)
  101. xfrm = Typed(expected_type=XDRTransform2D)
  102. graphic = Typed(expected_type=GraphicObject)
  103. macro = String(allow_none=True)
  104. fPublished = Bool(allow_none=True)
  105. __elements__ = ('nvGraphicFramePr', 'xfrm', 'graphic', 'macro', 'fPublished')
  106. def __init__(self,
  107. nvGraphicFramePr=None,
  108. xfrm=None,
  109. graphic=None,
  110. macro=None,
  111. fPublished=None,
  112. ):
  113. if nvGraphicFramePr is None:
  114. nvGraphicFramePr = NonVisualGraphicFrame()
  115. self.nvGraphicFramePr = nvGraphicFramePr
  116. if xfrm is None:
  117. xfrm = XDRTransform2D()
  118. self.xfrm = xfrm
  119. if graphic is None:
  120. graphic = GraphicObject()
  121. self.graphic = graphic
  122. self.macro = macro
  123. self.fPublished = fPublished
  124. class GroupShape(Serialisable):
  125. nvGrpSpPr = Typed(expected_type=NonVisualGroupShape)
  126. nonVisualProperties = Alias("nvGrpSpPr")
  127. grpSpPr = Typed(expected_type=GroupShapeProperties)
  128. visualProperties = Alias("grpSpPr")
  129. pic = Typed(expected_type=PictureFrame, allow_none=True)
  130. __elements__ = ["nvGrpSpPr", "grpSpPr", "pic"]
  131. def __init__(self,
  132. nvGrpSpPr=None,
  133. grpSpPr=None,
  134. pic=None,
  135. ):
  136. self.nvGrpSpPr = nvGrpSpPr
  137. self.grpSpPr = grpSpPr
  138. self.pic = pic