1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
"""DrawingML objects related to line formatting."""
from __future__ import annotations
from pptx.dml.fill import FillFormat
from pptx.enum.dml import MSO_FILL
from pptx.util import Emu, lazyproperty
class LineFormat(object):
"""Provides access to line properties such as color, style, and width.
A LineFormat object is typically accessed via the ``.line`` property of
a shape such as |Shape| or |Picture|.
"""
def __init__(self, parent):
super(LineFormat, self).__init__()
self._parent = parent
@lazyproperty
def color(self):
"""
The |ColorFormat| instance that provides access to the color settings
for this line. Essentially a shortcut for ``line.fill.fore_color``.
As a side-effect, accessing this property causes the line fill type
to be set to ``MSO_FILL.SOLID``. If this sounds risky for your use
case, use ``line.fill.type`` to non-destructively discover the
existing fill type.
"""
if self.fill.type != MSO_FILL.SOLID:
self.fill.solid()
return self.fill.fore_color
@property
def dash_style(self):
"""Return value indicating line style.
Returns a member of :ref:`MsoLineDashStyle` indicating line style, or
|None| if no explicit value has been set. When no explicit value has
been set, the line dash style is inherited from the style hierarchy.
Assigning |None| removes any existing explicitly-defined dash style.
"""
ln = self._ln
if ln is None:
return None
return ln.prstDash_val
@dash_style.setter
def dash_style(self, dash_style):
if dash_style is None:
ln = self._ln
if ln is None:
return
ln._remove_prstDash()
ln._remove_custDash()
return
ln = self._get_or_add_ln()
ln.prstDash_val = dash_style
@lazyproperty
def fill(self):
"""
|FillFormat| instance for this line, providing access to fill
properties such as foreground color.
"""
ln = self._get_or_add_ln()
return FillFormat.from_fill_parent(ln)
@property
def width(self):
"""
The width of the line expressed as an integer number of :ref:`English
Metric Units <EMU>`. The returned value is an instance of |Length|,
a value class having properties such as `.inches`, `.cm`, and `.pt`
for converting the value into convenient units.
"""
ln = self._ln
if ln is None:
return Emu(0)
return ln.w
@width.setter
def width(self, emu):
if emu is None:
emu = 0
ln = self._get_or_add_ln()
ln.w = emu
def _get_or_add_ln(self):
"""
Return the ``<a:ln>`` element containing the line format properties
in the XML.
"""
return self._parent.get_or_add_ln()
@property
def _ln(self):
return self._parent.ln
|