graphic.py 5.0 KB

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