Skip to content

Commit be7f11a

Browse files
author
Steve Canny
committed
reorg: mv BaseLength Length
1 parent b303153 commit be7f11a

File tree

8 files changed

+53
-54
lines changed

8 files changed

+53
-54
lines changed

docs/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282
8383
.. |BaseFileSystem| replace:: :class:`BaseFileSystem`
8484
85-
.. |BaseLength| replace:: :class:`.BaseLength`
86-
8785
.. |BaseShape| replace:: :class:`BaseShape`
8886
8987
.. |_Cell| replace:: :class:`_Cell`
@@ -134,18 +132,20 @@
134132
135133
.. |KeyError| replace:: :exc:`KeyError`
136134
137-
.. |list| replace:: :class:`list`
138-
139135
.. |_LayoutPlaceholders| replace:: :class:`_LayoutPlaceholders`
140136
141137
.. |_LayoutShapeTree| replace:: :class:`_LayoutShapeTree`
142138
143139
.. |Legend| replace:: :class:`.Legend`
144140
141+
.. |Length| replace:: :class:`.Length`
142+
145143
.. |LineFormat| replace:: :class:`.LineFormat`
146144
147145
.. |LineSeries| replace:: :class:`.LineSeries`
148146
147+
.. |list| replace:: :class:`list`
148+
149149
.. |_MasterPlaceholders| replace:: :class:`_MasterPlaceholders`
150150
151151
.. |_MasterShapeTree| replace:: :class:`_MasterShapeTree`

features/steps/line.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pptx import Presentation
1212
from pptx.dml.color import RGBColor
1313
from pptx.enum.dml import MSO_COLOR_TYPE, MSO_FILL_TYPE, MSO_THEME_COLOR
14-
from pptx.util import BaseLength, Pt
14+
from pptx.util import Length, Pt
1515

1616
from .helpers import test_pptx
1717

@@ -127,4 +127,4 @@ def then_the_reported_line_width_is_value(context, line_width):
127127
}[line_width]
128128
line_width = context.line.width
129129
assert line_width == expected_value
130-
assert isinstance(line_width, BaseLength)
130+
assert isinstance(line_width, Length)

pptx/dml/line.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def fill(self):
4848
def width(self):
4949
"""
5050
The width of the line expressed as an integer number of :ref:`English
51-
Metric Units <EMU>`. The returned value is an instance of
52-
|BaseLength|, a value class having properties such as `.inches`,
53-
`.cm`, and `.pt` for converting the value into convenient units.
51+
Metric Units <EMU>`. The returned value is an instance of |Length|,
52+
a value class having properties such as `.inches`, `.cm`, and `.pt`
53+
for converting the value into convenient units.
5454
"""
5555
ln = self._ln
5656
if ln is None:

pptx/shapes/table.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ def fill(self):
170170
@property
171171
def margin_left(self):
172172
"""
173-
Read/write integer value of left margin of cell as a |BaseLength|
174-
value object. If assigned |None|, the default value is used, 0.1
175-
inches for left and right margins and 0.05 inches for top and bottom.
173+
Read/write integer value of left margin of cell as a |Length| value
174+
object. If assigned |None|, the default value is used, 0.1 inches for
175+
left and right margins and 0.05 inches for top and bottom.
176176
"""
177177
return self._tc.marL
178178

pptx/text/text.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ def fit_text(self, font_family='Calibri', max_size=18, bold=False,
8181
@property
8282
def margin_bottom(self):
8383
"""
84-
|BaseLength| value representing the inset of text from the bottom
85-
text frame border. :meth:`pptx.util.Inches` provides a convenient way
86-
of setting the value, e.g. ``text_frame.margin_bottom
87-
= Inches(0.05)``.
84+
|Length| value representing the inset of text from the bottom text
85+
frame border. :meth:`pptx.util.Inches` provides a convenient way of
86+
setting the value, e.g. ``text_frame.margin_bottom = Inches(0.05)``.
8887
"""
8988
return self._bodyPr.bIns
9089

@@ -95,7 +94,7 @@ def margin_bottom(self, emu):
9594
@property
9695
def margin_left(self):
9796
"""
98-
Inset of text from left text frame border as |BaseLength| value.
97+
Inset of text from left text frame border as |Length| value.
9998
"""
10099
return self._bodyPr.lIns
101100

@@ -106,7 +105,7 @@ def margin_left(self, emu):
106105
@property
107106
def margin_right(self):
108107
"""
109-
Inset of text from right text frame border as |BaseLength| value.
108+
Inset of text from right text frame border as |Length| value.
110109
"""
111110
return self._bodyPr.rIns
112111

@@ -117,7 +116,7 @@ def margin_right(self, emu):
117116
@property
118117
def margin_top(self):
119118
"""
120-
Inset of text from top text frame border as |BaseLength| value.
119+
Inset of text from top text frame border as |Length| value.
121120
"""
122121
return self._bodyPr.tIns
123122

@@ -340,13 +339,13 @@ def name(self, value):
340339
@property
341340
def size(self):
342341
"""
343-
Read/write |BaseLength| value or |None|, indicating the font height
344-
in English Metric Units (EMU). |None| indicates the font size should
345-
be inherited from its style hierarchy, such as a placeholder or
346-
document defaults (usually 18pt). |BaseLength| is a subclass of |int|
347-
having properties for convenient conversion into points or other
348-
length units. Likewise, the :class:`pptx.util.Pt` class allows
349-
convenient specification of point values::
342+
Read/write |Length| value or |None|, indicating the font height in
343+
English Metric Units (EMU). |None| indicates the font size should be
344+
inherited from its style hierarchy, such as a placeholder or document
345+
defaults (usually 18pt). |Length| is a subclass of |int| having
346+
properties for convenient conversion into points or other length
347+
units. Likewise, the :class:`pptx.util.Pt` class allows convenient
348+
specification of point values::
350349
351350
>> font.size = Pt(24)
352351
>> font.size

pptx/util.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import platform
99

1010

11-
class BaseLength(int):
11+
class Length(int):
1212
"""
1313
Base class for length classes Inches, Emu, Cm, Mm, Pt, and Px. Provides
1414
properties for converting length values to convenient units.
@@ -79,66 +79,66 @@ def px(self):
7979
return int(round(self / float(self._EMUS_PER_PX)) + 0.1)
8080

8181

82-
class Inches(BaseLength):
82+
class Inches(Length):
8383
"""
8484
Convenience constructor for length in inches
8585
"""
8686
def __new__(cls, inches):
87-
emu = int(inches * BaseLength._EMUS_PER_INCH)
88-
return BaseLength.__new__(cls, emu)
87+
emu = int(inches * Length._EMUS_PER_INCH)
88+
return Length.__new__(cls, emu)
8989

9090

91-
class Centipoints(BaseLength):
91+
class Centipoints(Length):
9292
"""
9393
Convenience constructor for length in hundredths of a point
9494
"""
9595
def __new__(cls, centipoints):
96-
emu = int(centipoints * BaseLength._EMUS_PER_CENTIPOINT)
97-
return BaseLength.__new__(cls, emu)
96+
emu = int(centipoints * Length._EMUS_PER_CENTIPOINT)
97+
return Length.__new__(cls, emu)
9898

9999

100-
class Cm(BaseLength):
100+
class Cm(Length):
101101
"""
102102
Convenience constructor for length in centimeters
103103
"""
104104
def __new__(cls, cm):
105-
emu = int(cm * BaseLength._EMUS_PER_CM)
106-
return BaseLength.__new__(cls, emu)
105+
emu = int(cm * Length._EMUS_PER_CM)
106+
return Length.__new__(cls, emu)
107107

108108

109-
class Emu(BaseLength):
109+
class Emu(Length):
110110
"""
111111
Convenience constructor for length in english metric units
112112
"""
113113
def __new__(cls, emu):
114-
return BaseLength.__new__(cls, int(emu))
114+
return Length.__new__(cls, int(emu))
115115

116116

117-
class Mm(BaseLength):
117+
class Mm(Length):
118118
"""
119119
Convenience constructor for length in millimeters
120120
"""
121121
def __new__(cls, mm):
122-
emu = int(mm * BaseLength._EMUS_PER_MM)
123-
return BaseLength.__new__(cls, emu)
122+
emu = int(mm * Length._EMUS_PER_MM)
123+
return Length.__new__(cls, emu)
124124

125125

126-
class Pt(BaseLength):
126+
class Pt(Length):
127127
"""
128128
Convenience value class for specifying a length in points
129129
"""
130130
def __new__(cls, points):
131-
emu = int(points * BaseLength._EMUS_PER_PT)
132-
return BaseLength.__new__(cls, emu)
131+
emu = int(points * Length._EMUS_PER_PT)
132+
return Length.__new__(cls, emu)
133133

134134

135-
class Px(BaseLength):
135+
class Px(Length):
136136
"""
137137
Convenience constructor for length in pixels
138138
"""
139139
def __new__(cls, px):
140-
emu = int(px * BaseLength._EMUS_PER_PX)
141-
return BaseLength.__new__(cls, emu)
140+
emu = int(px * Length._EMUS_PER_PX)
141+
return Length.__new__(cls, emu)
142142

143143

144144
def lazyproperty(f):

tests/shapes/test_table.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_Cell, _CellCollection, _Column, _ColumnCollection, _Row, _RowCollection,
1717
Table
1818
)
19-
from pptx.util import Inches, BaseLength, Pt
19+
from pptx.util import Inches, Length, Pt
2020

2121
from ..unitutil.cxml import element, xml
2222
from ..unitutil.mock import class_mock, instance_mock
@@ -358,7 +358,7 @@ def it_knows_its_width(self, width_get_fixture):
358358
column, expected_value = width_get_fixture
359359
width = column.width
360360
assert width == expected_value
361-
assert isinstance(width, BaseLength)
361+
assert isinstance(width, Length)
362362

363363
def it_can_change_its_width(self, width_set_fixture):
364364
column, new_width, expected_xml, parent_ = width_set_fixture
@@ -469,7 +469,7 @@ def it_knows_its_height(self, height_get_fixture):
469469
row, expected_value = height_get_fixture
470470
height = row.height
471471
assert height == expected_value
472-
assert isinstance(height, BaseLength)
472+
assert isinstance(height, Length)
473473

474474
def it_can_change_its_height(self, height_set_fixture):
475475
row, new_height, expected_xml, parent_ = height_set_fixture

tests/test_util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
from pptx.util import (
13-
BaseLength, Centipoints, Cm, Emu, Inches, Mm, Pt, Px, to_unicode
13+
Length, Centipoints, Cm, Emu, Inches, Mm, Pt, Px, to_unicode
1414
)
1515

1616

@@ -25,19 +25,19 @@ class DescribeLength(object):
2525
def it_can_construct_from_convenient_units(self, construct_fixture):
2626
UnitCls, units_val, emu = construct_fixture
2727
length = UnitCls(units_val)
28-
assert isinstance(length, BaseLength)
28+
assert isinstance(length, Length)
2929
assert length == emu
3030

3131
def it_can_self_convert_to_convenient_units(self, units_fixture):
3232
emu, units_prop_name, expected_length_in_units = units_fixture
33-
length = BaseLength(emu)
33+
length = Length(emu)
3434
length_in_units = getattr(length, units_prop_name)
3535
assert length_in_units == expected_length_in_units
3636

3737
# fixtures -------------------------------------------------------
3838

3939
@pytest.fixture(params=[
40-
(BaseLength, 914400, 914400),
40+
(Length, 914400, 914400),
4141
(Inches, 1.1, 1005840),
4242
(Centipoints, 12.5, 1587),
4343
(Cm, 2.53, 910799),

0 commit comments

Comments
 (0)