DocumentLabel Class

Inheritance diagram of DocumentLabel

class DocumentLabel(document=None, x=0, y=0, width=None, height=None, anchor_x='left', anchor_y='baseline', multiline=False, dpi=None, batch=None, group=None)

Base label class.

A label is a layout that exposes convenience methods for manipulating the associated document.

Constructor:

__init__(document=None, x=0, y=0, width=None, height=None, anchor_x='left', anchor_y='baseline', multiline=False, dpi=None, batch=None, group=None)

Create a label for a given document.

Parameters:
  • document (AbstractDocument) – Document to attach to the layout.
  • x (int) – X coordinate of the label.
  • y (int) – Y coordinate of the label.
  • width (int) – Width of the label in pixels, or None
  • height (int) – Height of the label in pixels, or None
  • anchor_x (str) – Anchor point of the X coordinate: one of "left", "center" or "right".
  • anchor_y (str) – Anchor point of the Y coordinate: one of "bottom", "baseline", "center" or "top".
  • multiline (bool) – If True, the label will be word-wrapped and accept newline characters. You must also set the width of the label.
  • dpi (float) – Resolution of the fonts in this layout. Defaults to 96.
  • batch (Batch) – Optional graphics batch to add the label to.
  • group (Group) – Optional graphics group to use.

Methods:

begin_update() Indicate that a number of changes to the layout or document are about to occur.
delete() Remove this layout from its batch.
draw() Draw this text layout.
end_update() Perform pending layout changes since begin_update.
get_style(name) Get a document style value by name.
on_delete_text(start, end) Event handler for AbstractDocument.on_delete_text.
on_insert_text(start, text) Event handler for AbstractDocument.on_insert_text.
on_style_text(start, end, attributes) Event handler for AbstractDocument.on_style_text.
set_style(name, value) Set a document style value by name over the whole document.

Attributes:

anchor_x Horizontal anchor alignment.
anchor_y Vertical anchor alignment.
background_group A group with partial order.
bold Bold font style.
color Text color.
content_valign Vertical alignment of content within larger layout box.
document
dpi Get DPI used by this layout.
font_name Font family name.
font_size Font size, in points.
foreground_decoration_group Rendering group for decorative elements (e.g., glyph underlines) in all text layouts.
foreground_group Rendering group for foreground elements (glyphs) in all text layouts.
height Height of the layout.
italic Italic font style.
multiline Set if multiline layout is enabled.
text The text of the label.
top_group Type: TextLayoutGroup
width Width of the layout.
x X coordinate of the layout.
y Y coordinate of the layout.

Methods

DocumentLabel.get_style(name)

Get a document style value by name.

If the document has more than one value of the named style, pyglet.text.document.STYLE_INDETERMINATE is returned.

Parameters:name (str) – Style name to query. See documentation for pyglet.text.layout for known style names.
Return type:object
DocumentLabel.set_style(name, value)

Set a document style value by name over the whole document.

Parameters:
  • name (str) – Name of the style to set. See documentation for pyglet.text.layout for known style names.
  • value (object) – Value of the style.

Attributes

DocumentLabel.bold

Bold font style.

Type:bool
DocumentLabel.color

Text color.

Color is a 4-tuple of RGBA components, each in range [0, 255].

Type:(int, int, int, int)
DocumentLabel.font_name

Font family name.

The font name, as passed to pyglet.font.load. A list of names can optionally be given: the first matching font will be used.

Type:str or list
DocumentLabel.font_size

Font size, in points.

Type:float
DocumentLabel.italic

Italic font style.

Type:bool
DocumentLabel.text

The text of the label.

Type:str

Inherited members

Methods

DocumentLabel.begin_update()

Indicate that a number of changes to the layout or document are about to occur.

Changes to the layout or document between calls to begin_update and end_update do not trigger any costly relayout of text. Relayout of all changes is performed when end_update is called.

Note that between the begin_update and end_update calls, values such as content_width and content_height are undefined (i.e., they may or may not be updated to reflect the latest changes).

DocumentLabel.delete()

Remove this layout from its batch.

DocumentLabel.draw()

Draw this text layout.

Note that this method performs very badly if a batch was supplied to the constructor. If you add this layout to a batch, you should ideally use only the batch’s draw method.

DocumentLabel.end_update()

Perform pending layout changes since begin_update.

See begin_update.

DocumentLabel.on_delete_text(start, end)

Event handler for AbstractDocument.on_delete_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

DocumentLabel.on_insert_text(start, text)

Event handler for AbstractDocument.on_insert_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

DocumentLabel.on_style_text(start, end, attributes)

Event handler for AbstractDocument.on_style_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Attributes

DocumentLabel.anchor_x

Horizontal anchor alignment.

This property determines the meaning of the x coordinate. It is one of the enumerants:

"left" (default)
The X coordinate gives the position of the left edge of the layout.
"center"
The X coordinate gives the position of the center of the layout.
"right"
The X coordinate gives the position of the right edge of the layout.

For the purposes of calculating the position resulting from this alignment, the width of the layout is taken to be width if multiline is True and wrap_lines is True, otherwise content_width.

Type:str
DocumentLabel.anchor_y

Vertical anchor alignment.

This property determines the meaning of the y coordinate. It is one of the enumerants:

"top"
The Y coordinate gives the position of the top edge of the layout.
"center"
The Y coordinate gives the position of the center of the layout.
"baseline"
The Y coordinate gives the position of the baseline of the first line of text in the layout.
"bottom" (default)
The Y coordinate gives the position of the bottom edge of the layout.

For the purposes of calculating the position resulting from this alignment, the height of the layout is taken to be the smaller of height and content_height.

See also content_valign.

Type:str
DocumentLabel.background_group = OrderedGroup(0)
DocumentLabel.content_valign

Vertical alignment of content within larger layout box.

This property determines how content is positioned within the layout box when content_height is less than height. It is one of the enumerants:

top (default)
Content is aligned to the top of the layout box.
center
Content is centered vertically within the layout box.
bottom
Content is aligned to the bottom of the layout box.

This property has no effect when content_height is greater than height (in which case the content is aligned to the top) or when height is None (in which case there is no vertical layout box dimension).

Type:str
DocumentLabel.document
DocumentLabel.dpi

Get DPI used by this layout.

Read-only.

Type:float
DocumentLabel.foreground_decoration_group = TextLayoutForegroundDecorationGroup(2)
DocumentLabel.foreground_group = TextLayoutForegroundGroup(1)
DocumentLabel.height

Height of the layout.

Type:int
DocumentLabel.multiline

Set if multiline layout is enabled.

If multiline is False, newline and paragraph characters are ignored and text is not word-wrapped. If True, the text is word-wrapped only if the wrap_lines is True.

Type:bool
DocumentLabel.top_group = <pyglet.text.layout.TextLayoutGroup object at 0x96bbd2c>
DocumentLabel.width

Width of the layout.

This property has no effect if multiline is False or wrap_lines is False.

Type:int
DocumentLabel.x

X coordinate of the layout.

See also anchor_x.

Type:int
DocumentLabel.y

Y coordinate of the layout.

See also anchor_y.

Type:int

Table Of Contents

Previous topic

DocumentDecoder Class

Next topic

HTMLLabel Class