Submodules
Details
Text formatting, layout and display.
This module provides classes for loading styled documents from text files, HTML files and a pyglet-specific markup format. Documents can be styled with multiple fonts, colours, styles, text sizes, margins, paragraph alignments, and so on.
Using the layout classes, documents can be laid out on a single line or word-wrapped to fit a rectangle. A layout can then be efficiently drawn in a window or updated incrementally (for example, to support interactive text editing).
The label classes provide a simple interface for the common case where an application simply needs to display some text in a window.
A plain text label can be created with:
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=10, y=10)
Alternatively, a styled text label using HTML can be created with:
label = pyglet.text.HTMLLabel('<b>Hello</b>, <i>world</i>',
x=10, y=10)
Either label can then be drawn at any time with:
label.draw()
For details on the subset of HTML supported, see pyglet.text.formats.html.
Refer to the Programming Guide for advanced usage of the document and layout classes, including interactive editing, embedding objects within documents and creating scrollable layouts.
New in version 1.1.
DocumentDecodeException
¶An error occurred decoding document text.
DocumentDecoder
¶Abstract document decoder.
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.
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 |
set_style
(name, value)¶Set a document style value by name over the whole document.
Parameters: |
|
---|
bold
¶Bold font style.
Type: | bool |
---|
color
¶Text color.
Color is a 4-tuple of RGBA components, each in range [0, 255].
Type: | (int, int, int, int) |
---|
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 |
---|
font_size
¶Font size, in points.
Type: | float |
---|
italic
¶Italic font style.
Type: | bool |
---|
text
¶The text of the label.
Type: | str |
---|
HTMLLabel
(text=”, location=None, x=0, y=0, width=None, height=None, anchor_x=’left’, anchor_y=’baseline’, multiline=False, dpi=None, batch=None, group=None)¶HTML formatted text label.
A subset of HTML 4.01 is supported. See pyglet.text.formats.html for details.
text
¶HTML formatted text of the label.
Type: | str |
---|
Label
(text=”, font_name=None, font_size=None, bold=False, italic=False, color=(255, 255, 255, 255), x=0, y=0, width=None, height=None, anchor_x=’left’, anchor_y=’baseline’, align=’left’, multiline=False, dpi=None, batch=None, group=None)¶Plain text label.
decode_attributed
(text)¶Create a document directly from some attributed text.
See pyglet.text.formats.attributed for a description of attributed text.
Parameters: | text (str) – Attributed text to decode. |
---|---|
Return type: | FormattedDocument |
decode_html
(text, location=None)¶Create a document directly from some HTML formatted text.
Parameters: |
|
---|---|
Return type: | FormattedDocument |
decode_text
(text)¶Create a document directly from some plain text.
Parameters: | text (str) – Plain text to initialise the document with. |
---|---|
Return type: | UnformattedDocument |
get_decoder
(filename, mimetype=None)¶Get a document decoder for the given filename and MIME type.
If mimetype is omitted it is guessed from the filename extension.
The following MIME types are supported:
text/plain
text/html
text/vnd.pyglet-attributed
DocumentDecodeException is raised if another MIME type is given.
Parameters: |
|
---|---|
Return type: | DocumentDecoder |
load
(filename, file=None, mimetype=None)¶Load a document from a file.
Parameters: |
|
---|---|
Return type: | AbstractDocument |