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