psychos.visual.Text#
- class psychos.visual.Text(text: str = '', position: Tuple[float, float] = (0, 0), width: int | None = None, height: int | None = None, color: ColorType | None = None, anchor_x: AnchorHorizontal = 'center', anchor_y: AnchorVertical = 'center', align: AnchorHorizontal = 'center', rotation: float = 0, multiline: bool = False, font_name: str | None = None, font_size: float | None = None, italic: bool = False, stretch: bool = False, window: Window | None = None, coordinates: UnitType | Unit | None = None, **kwargs)[source]#
Bases:
LabelA class to represent text in a Pyglet window using a Label component.
- Parameters:
text (str, default="") – The text to display.
position (Tuple[float, float], default=(0, 0)) – The position of the text in the window.
width (Optional[int], default=None) – The width of the text box.
height (Optional[int], default=None) – The height of the text box.
color (Optional[ColorType], default=None) – The color of the text.
anchor_x (AnchorHorizontal, default="center") – The horizontal anchor alignment of the text.
anchor_y (AnchorVertical, default="center") – The vertical anchor alignment of the text.
window (Optional[Window], default=None) – The window in which the text will be displayed.
rotation (float, default=0) – The rotation angle of the text.
multiline (bool, default=False) – Whether the text can span multiple lines.
font_name (Optional[str], default=None) – The name of the font to use.
font_size (Optional[float], default=None) – The size of the font to use.
italic (bool, default=False) – Whether the text is italicized.
stretch (bool, default=False) – Whether the text is stretched.
align (AnchorHorizontal, default="center") – The alignment of the text.
coordinate_units (Optional[Union[UnitType, Units]], default=None) – The unit system to be used for positioning the text.
kwargs (dict) – Additional keyword arguments to pass to the Pyglet Label.
- __init__(text: str = '', position: Tuple[float, float] = (0, 0), width: int | None = None, height: int | None = None, color: ColorType | None = None, anchor_x: AnchorHorizontal = 'center', anchor_y: AnchorVertical = 'center', align: AnchorHorizontal = 'center', rotation: float = 0, multiline: bool = False, font_name: str | None = None, font_size: float | None = None, italic: bool = False, stretch: bool = False, window: Window | None = None, coordinates: UnitType | Unit | None = None, **kwargs)[source]#
Create a plain text label.
- Parameters:
text – Text to display.
x – X coordinate of the label.
y – Y coordinate of the label.
z – Z coordinate of the label.
width – Width of the label in pixels, or None
height – Height of the label in pixels, or None
anchor_x – Anchor point of the X coordinate: one of
"left","center"or"right".anchor_y – Anchor point of the Y coordinate: one of
"bottom","baseline","center"or"top".rotation – The amount to rotate the label in degrees. A positive amount will be a clockwise rotation, negative values will result in counter-clockwise rotation.
multiline – If True, the label will be word-wrapped and accept newline characters. You must also set the width of the label.
dpi – Resolution of the fonts in this layout. Defaults to 96.
font_name – Font family name(s). If more than one name is given, the first matching name is used.
font_size – Font size, in points.
weight – The ‘weight’ of the font (boldness). See the
Weightenum for valid cross-platform weight names.italic – Italic font style.
stretch – Stretch font style.
color – Font color as RGBA or RGB components, each within
0 <= component <= 255.align – Horizontal alignment of text on a line, only applies if a width is supplied. One of
"left","center"or"right".batch – Optional graphics batch to add the label to.
group – Optional graphics group to use.
program – Optional graphics shader to use. Will affect all glyphs.
Methods
__init__([text, position, width, height, ...])Create a plain text label.
begin_update()Indicate that a number of changes to the layout or document are about to occur.
delete()Deletes all vertices and boxes associated with the layout.
draw()Draw this text layout.
end_update()Perform pending layout changes since begin_update.
get_as_texture([min_filter, mag_filter])Utilizes a
Framebufferto draw the current layout into a texture.get_line_count()Get the number of lines in the text layout.
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_xHorizontal anchor alignment.
anchor_yVertical anchor alignment.
batchThe Batch that this Layout is assigned to.
bottomThe y-coordinate of the bottom side of the layout.
Text color.
content_heightThe calculated height of the text in the layout.
content_valignVertical alignment of content within larger layout box.
content_widthCalculated width of the text in the layout.
Get the coordinate system used for the text.
documentDocument to display.
dpiGet DPI used by this layout.
font_nameFont family name.
font_sizeFont size, in points.
groupGet the Group specified by the user.
The defined maximum height of the layout in pixels, or None.
italicItalic font style.
leftThe x-coordinate of the left side of the layout.
multilineSet if multiline layout is enabled.
opacityBlend opacity.
Get the position of the text in pixels.
programThe ShaderProgram that is assigned to this Layout.
rightThe x-coordinate of the right side of the layout.
rotationRotation of the layout in degrees.
textThe text of the label.
topThe y-coordinate of the top side of the layout.
visibleTrue if the layout will be visible when drawn.
weightThe font weight (boldness or thickness), as a string.
The defined maximum width of the layout in pixels, or None.
xX coordinate of the layout.
yY coordinate of the layout.
zZ coordinate of the layout.
group_cache- property color: tuple[int, int, int, int]#
Text color.
Color is a 4-tuple of RGBA components, each in range [0, 255].
- draw() Text[source]#
Draw this text layout.
Note
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.
Note
If this is not its own batch, InlineElements will not be drawn.
- property height: int | None#
The defined maximum height of the layout in pixels, or None.
When height is not None, it affects the positioning of the text when
anchor_yandcontent_valignare used.