Skip to content

Commit 454cc68

Browse files
committed
add property value for fill and color; set version to 1.0.3+PPTAgent
1 parent 2d3c4c8 commit 454cc68

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/pptx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if TYPE_CHECKING:
2626
from pptx.opc.package import Part
2727

28-
__version__ = "1.0.2+PPTAgent"
28+
__version__ = "1.0.3+PPTAgent"
2929

3030
sys.modules["pptx.exceptions"] = exceptions
3131
del sys

src/pptx/dml/color.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ def _validate_brightness_value(self, value):
106106
)
107107
raise ValueError(msg)
108108

109+
@property
110+
def value(self):
111+
if self.type == MSO_COLOR_TYPE.RGB:
112+
return str(self.rgb)
113+
elif self.type == MSO_COLOR_TYPE.SCHEME:
114+
return "ThemeColor-" + str(self.theme_color)
115+
elif self.type is None:
116+
return None
117+
return str(self.type).split()[0]
118+
109119

110120
class _Color(object):
111121
"""

src/pptx/dml/fill.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ def type(self) -> MSO_FILL_TYPE:
160160
"""The type of this fill, e.g. `MSO_FILL_TYPE.SOLID`."""
161161
return self._fill.type
162162

163+
@property
164+
def value(self):
165+
"""Return a value appropriate to the fill type.
166+
167+
For solid fills, returns the foreground color.
168+
For pattern fills, returns the pattern type.
169+
For gradient fills, returns the gradient stops.
170+
For picture fills, returns "Picture".
171+
For group fills, returns "Group".
172+
For background (no fill), returns "Background".
173+
Returns None if no fill is applied.
174+
"""
175+
if self.type == MSO_FILL.SOLID:
176+
return self.fore_color.value
177+
elif self.type == MSO_FILL.PATTERNED or self.type == MSO_FILL.TEXTURED:
178+
return "Texture"
179+
elif self.type == MSO_FILL.GRADIENT:
180+
return "GradientColor"
181+
elif self.type == MSO_FILL.PICTURE:
182+
return "Picture"
183+
return None
184+
163185

164186
class _Fill(object):
165187
"""

src/pptx/text/text.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,9 @@ def bold(self, value: bool | None):
353353
self._rPr.b = value
354354

355355
@lazyproperty
356-
def color(self) -> ColorFormat:
356+
def color(self) -> str|None:
357357
"""The |ColorFormat| instance that provides access to the color settings for this font."""
358-
if self.fill.type != MSO_FILL.SOLID:
359-
self.fill.solid()
360-
try:
361-
return str(self.fill.fore_color.rgb)
362-
except:
363-
return None
358+
return self.fill.value
364359

365360
@lazyproperty
366361
def fill(self) -> FillFormat:

0 commit comments

Comments
 (0)