59
59
60
60
class BaseSize (namedtuple ("__BaseSize" , "width, height" )):
61
61
"""
62
- Base class namedtuple representing a page size, in point
63
-
64
- :param width: The page width
65
- :type width: |AnyNumber|
66
- :param height: The page height
67
- :type height: |AnyNumber|
62
+ Base class namedtuple representing a page size, in point.
68
63
"""
69
64
70
65
__slots__ : List [str ] = []
71
66
_unit : Unit = pt
67
+
68
+ #: The page width.
72
69
width : Unit
70
+
71
+ #: The page height.
73
72
height : Unit
74
73
75
74
def __new__ (cls , width : AnyNumber , height : AnyNumber ):
75
+ """
76
+ Create a new :class:`~.BaseSize` object.
77
+
78
+ :param width: The page width.
79
+ :param height: The page height.
80
+ """
81
+
76
82
return super ().__new__ (
77
83
cls ,
78
84
cls ._unit (width ),
@@ -88,10 +94,10 @@ def from_pt(cls, size: Tuple[float, float]):
88
94
Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a
89
95
page size in point.
90
96
91
- :param size: The size, in point, to convert from
97
+ :param size: The size, in point, to convert from.
92
98
93
99
:rtype: A subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
94
- """
100
+ """ # noqa D400
95
101
96
102
assert isinstance (size , PageSize )
97
103
@@ -100,35 +106,35 @@ def from_pt(cls, size: Tuple[float, float]):
100
106
@classmethod
101
107
def from_size (cls , size : Tuple [AnyNumber , AnyNumber ]) -> "BaseSize" :
102
108
"""
103
- Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a tuple
109
+ Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a tuple.
104
110
"""
105
111
106
112
return cls (* size )
107
113
108
114
def is_landscape (self ) -> bool :
109
115
"""
110
- Returns whether the page is in the landscape orientation
116
+ Returns whether the page is in the landscape orientation.
111
117
"""
112
118
113
119
return self .width >= self .height
114
120
115
121
def is_portrait (self ) -> bool :
116
122
"""
117
- Returns whether the page is in the portrait orientation
123
+ Returns whether the page is in the portrait orientation.
118
124
"""
119
125
120
126
return self .width < self .height
121
127
122
128
def is_square (self ) -> bool :
123
129
"""
124
- Returns whether the given pagesize is square
130
+ Returns whether the given pagesize is square.
125
131
"""
126
132
127
133
return self .width == self .height
128
134
129
135
def landscape (self ) -> "BaseSize" :
130
136
"""
131
- Returns the pagesize in landscape orientation
137
+ Returns the pagesize in landscape orientation.
132
138
"""
133
139
134
140
if self .is_portrait ():
@@ -138,7 +144,7 @@ def landscape(self) -> "BaseSize":
138
144
139
145
def portrait (self ) -> "BaseSize" :
140
146
"""
141
- Returns the pagesize in portrait orientation
147
+ Returns the pagesize in portrait orientation.
142
148
"""
143
149
144
150
if self .is_landscape ():
@@ -148,7 +154,7 @@ def portrait(self) -> "BaseSize":
148
154
149
155
def to_pt (self ) -> "PageSize" :
150
156
"""
151
- Returns the page size in point
157
+ Returns the page size in point.
152
158
"""
153
159
154
160
return PageSize (self .width .as_pt (), self .height .as_pt ())
@@ -159,83 +165,50 @@ def to_pt(self) -> "PageSize":
159
165
160
166
class Size_mm (BaseSize ):
161
167
"""
162
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
163
- representing a pagesize in millimeters.
164
-
165
- :param width: The page width
166
- :type width: |AnyNumber|
167
- :param height: The page height
168
- :type height: |AnyNumber|
168
+ Represents a pagesize in millimeters.
169
169
"""
170
170
171
171
_unit = mm
172
172
173
173
174
174
class Size_inch (BaseSize ):
175
175
"""
176
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
177
- representing a pagesize in inches.
178
-
179
- :param width: The page width
180
- :type width: |AnyNumber|
181
- :param height: The page height
182
- :type height: |AnyNumber|
176
+ Represents a pagesize in inches.
183
177
"""
184
178
185
179
_unit = inch
186
180
187
181
188
182
class Size_cm (BaseSize ):
189
183
"""
190
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
191
- representing a pagesize in centimeters.
192
-
193
- :param width: The page width
194
- :type width: |AnyNumber|
195
- :param height: The page height
196
- :type height: |AnyNumber|
184
+ Represents a pagesize in centimeters.
197
185
"""
198
186
199
187
_unit = cm
200
188
201
189
202
190
class Size_um (BaseSize ):
203
191
"""
204
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
205
- representing a pagesize in micrometers.
206
-
207
- :param width: The page width
208
- :type width: |AnyNumber|
209
- :param height: The page height
210
- :type height: |AnyNumber|
192
+ Represents a pagesize in micrometers.
211
193
"""
212
194
213
195
_unit = um
214
196
215
197
216
198
class Size_pica (BaseSize ):
217
199
"""
218
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
219
- representing a pagesize in pica.
220
-
221
- :param width: The page width
222
- :type width: |AnyNumber|
223
- :param height: The page height
224
- :type height: |AnyNumber|
200
+ Represents a pagesize in pica.
225
201
"""
226
202
227
203
_unit = pica
228
204
229
205
230
206
class PageSize (BaseSize ):
231
207
"""
232
- Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
233
- representing a pagesize in point.
208
+ Represents a pagesize in point.
234
209
235
210
:param width: The page width
236
- :type width: |AnyNumber|
237
211
:param height: The page height
238
- :type height: |AnyNumber|
239
212
240
213
The pagesize can be converted to other units using the properties below.
241
214
"""
@@ -246,8 +219,8 @@ def __new__(cls, width: AnyNumber, height: AnyNumber, unit: AnyNumber = pt):
246
219
"""
247
220
Create a new :class:`~domdf_python_tools.pagesizes.classes.PageSize` object.
248
221
249
- :param width:
250
- :param height:
222
+ :param width: The page width.
223
+ :param height: The page height.
251
224
:param unit:
252
225
"""
253
226
0 commit comments