Shared classes¶
Length objects¶
Length values in python-docx
are expressed as a standardized Length
value object.
Length
is a subclass of int
, having all the behavior of an int
. In
addition, it has built-in units conversion properties, e.g.:
>>> inline_shape.height
914400
>>> inline_shape.height.inches
1.0
Length objects are constructed using a selection of convenience constructors, allowing values to be expressed in the units most appropriate to the context.
- class docx.shared.Length(emu)[source]¶
Base class for length constructor classes Inches, Cm, Mm, Px, and Emu. Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to the mm. Provides convenience unit conversion methods in the form of read-only properties. Immutable.
- property cm¶
The equivalent length expressed in centimeters (float).
- property emu¶
The equivalent length expressed in English Metric Units (int).
- property inches¶
The equivalent length expressed in inches (float).
- property mm¶
The equivalent length expressed in millimeters (float).
- property pt¶
Floating point length in points
- property twips¶
The equivalent length expressed in twips (int).
- class docx.shared.Inches(inches)[source]¶
Convenience constructor for length in inches, e.g.
width = Inches(0.5)
.
- class docx.shared.Cm(cm)[source]¶
Convenience constructor for length in centimeters, e.g.
height = Cm(12)
.
- class docx.shared.Mm(mm)[source]¶
Convenience constructor for length in millimeters, e.g.
width = Mm(240.5)
.
RGBColor
objects¶
- class docx.shared.RGBColor(r, g, b)[source]¶
Immutable value object defining a particular RGB color.
r, g, and b are each an integer in the range 0-255 inclusive. Using the hexidecimal integer notation, e.g. 0x42 may enhance readability where hex RGB values are in use:
>>> lavender = RGBColor(0xff, 0x99, 0xcc)