1- from typing import Self , cast
1+ from typing import TypeVar , cast
22
33from pptx .dml .fill import FillFormat as PptxFillFormat
4+ from pptx .dml .fill import _Fill as PptxFill
45from pptx .dml .fill import _GradFill as PptxGradFill
56from pptx .dml .fill import _GradientStop as PptxGradientStop
67from pptx .dml .fill import _GradientStops as PptxGradientStops
1112
1213from tppt .pptx .converter import PptxConvertible , to_pptx_angle , to_tppt_angle
1314from tppt .pptx .dml .color import ColorFormat
15+ from tppt .pptx .enum .dml import LiteralPatternType , to_pptx_pattern_type
1416from tppt .types ._angle import Angle
1517
1618
1719class FillFormat (PptxConvertible [PptxFillFormat ]):
1820 """Fill format."""
1921
20- def __init__ (self , pptx_obj : PptxFillFormat ) -> None :
21- self . _pptx = pptx_obj
22+ def __init__ (self , pptx_obj : PptxFillFormat , / ) -> None :
23+ super (). __init__ ( pptx_obj )
2224
2325 @property
2426 def fore_color (self ) -> ColorFormat :
@@ -59,70 +61,17 @@ def gradient(self) -> "GradFill":
5961 self ._pptx .gradient ()
6062 return GradFill (cast (PptxGradFill , self ._pptx ._fill ))
6163
62- def to_pptx (self ) -> PptxFillFormat :
63- """Convert to pptx fill format."""
64- return self ._pptx
6564
66- @classmethod
67- def from_pptx (cls , pptx_obj : PptxFillFormat ) -> Self :
68- """Create from pptx fill format."""
69- return cls (pptx_obj )
65+ _GenericPptxFill = TypeVar ("_GenericPptxFill" , bound = PptxFill )
7066
7167
72- class NoFill (PptxConvertible [PptxNoFill ]):
73- """No fill."""
74-
75- def __init__ (self , pptx_obj : PptxNoFill ) -> None :
76- self ._pptx = pptx_obj
77-
78- def to_pptx (self ) -> PptxNoFill :
79- """Convert to pptx no fill."""
80- return self ._pptx
81-
82- @classmethod
83- def from_pptx (cls , pptx_obj : PptxNoFill ) -> Self :
84- """Create from pptx no fill."""
85- return cls (pptx_obj )
86-
87-
88- class PattFill (PptxConvertible [PptxPattFill ]):
89- """Pattern fill."""
90-
91- def __init__ (self , pptx_obj : PptxPattFill ) -> None :
92- self ._pptx = pptx_obj
93-
94- def to_pptx (self ) -> PptxPattFill :
95- """Convert to pptx pattern fill."""
96- return self ._pptx
97-
98- @classmethod
99- def from_pptx (cls , pptx_obj : PptxPattFill ) -> Self :
100- """Create from pptx pattern fill."""
101- return cls (pptx_obj )
102-
103-
104- class SolidFill (PptxConvertible [PptxSolidFill ]):
105- """Solid fill."""
68+ class Fill (PptxConvertible [_GenericPptxFill ]):
69+ pass
10670
107- def __init__ (self , pptx_obj : PptxSolidFill ) -> None :
108- self ._pptx = pptx_obj
10971
110- def to_pptx (self ) -> PptxSolidFill :
111- """Convert to pptx solid fill."""
112- return self ._pptx
113-
114- @classmethod
115- def from_pptx (cls , pptx_obj : PptxSolidFill ) -> Self :
116- """Create from pptx solid fill."""
117- return cls (pptx_obj )
118-
119-
120- class GradFill (PptxConvertible [PptxGradFill ]):
72+ class GradFill (Fill [PptxGradFill ]):
12173 """Gradient fill."""
12274
123- def __init__ (self , pptx_obj : PptxGradFill ) -> None :
124- self ._pptx = pptx_obj
125-
12675 @property
12776 def gradient_angle (self ) -> Angle | None :
12877 """Angle in float degrees of line of a linear gradient."""
@@ -137,44 +86,59 @@ def gradient_stops(self) -> "GradientStops":
13786 """Gradient stops."""
13887 return GradientStops (self ._pptx .gradient_stops )
13988
140- def to_pptx (self ) -> PptxGradFill :
141- """Convert to pptx gradient fill."""
142- return self ._pptx
14389
144- @classmethod
145- def from_pptx (cls , pptx_obj : PptxGradFill ) -> Self :
146- """Create from pptx gradient fill."""
147- return cls (pptx_obj )
90+ class NoFill (Fill [PptxNoFill ]):
91+ """No fill."""
92+
93+ def __init__ (self , pptx_obj : PptxNoFill ) -> None :
94+ super ().__init__ (pptx_obj )
95+
96+
97+ class PattFill (Fill [PptxPattFill ]):
98+ """Pattern fill."""
99+
100+ @property
101+ def back_color (self ) -> ColorFormat :
102+ """Back color."""
103+ return ColorFormat (self ._pptx .back_color )
104+
105+ @property
106+ def fore_color (self ) -> ColorFormat :
107+ """Fore color."""
108+ return ColorFormat (self ._pptx .fore_color )
109+
110+ @property
111+ def pattern (self ) -> MSO_PATTERN_TYPE :
112+ """Pattern."""
113+ return self ._pptx .pattern
114+
115+ @pattern .setter
116+ def pattern (self , value : LiteralPatternType | MSO_PATTERN_TYPE ) -> None :
117+ self ._pptx .pattern = to_pptx_pattern_type (value )
118+
119+
120+ class SolidFill (Fill [PptxSolidFill ]):
121+ """Solid fill."""
122+
123+ @property
124+ def fore_color (self ) -> ColorFormat :
125+ """Fore color."""
126+ return ColorFormat (self ._pptx .fore_color )
148127
149128
150129class GradientStops (PptxConvertible [PptxGradientStops ]):
151130 """Gradient stops."""
152131
153- def __init__ (self , pptx_obj : PptxGradientStops ) -> None :
154- self ._pptx = pptx_obj
155-
156132 def __getitem__ (self , idx : int ) -> "GradientStop" :
157133 return GradientStop (self ._pptx [idx ])
158134
159135 def __len__ (self ) -> int :
160136 return len (self ._pptx )
161137
162- def to_pptx (self ) -> PptxGradientStops :
163- """Convert to pptx gradient stops."""
164- return self ._pptx
165-
166- @classmethod
167- def from_pptx (cls , pptx_obj : PptxGradientStops ) -> Self :
168- """Create from pptx gradient stops."""
169- return cls (pptx_obj )
170-
171138
172139class GradientStop (PptxConvertible [PptxGradientStop ]):
173140 """Gradient stop."""
174141
175- def __init__ (self , pptx_obj : PptxGradientStop ) -> None :
176- self ._pptx = pptx_obj
177-
178142 @property
179143 def color (self ) -> ColorFormat :
180144 """Color."""
@@ -194,12 +158,3 @@ def position(self) -> float:
194158 @position .setter
195159 def position (self , value : float ) -> None :
196160 self ._pptx .position = value
197-
198- def to_pptx (self ) -> PptxGradientStop :
199- """Convert to pptx gradient stop."""
200- return self ._pptx
201-
202- @classmethod
203- def from_pptx (cls , pptx_obj : PptxGradientStop ) -> Self :
204- """Create from pptx gradient stop."""
205- return cls (pptx_obj )
0 commit comments