fsleyes.gl.text

This module provides the Text class, which uses the fsleyes_widgets.utils.textbitmap module, and a Texture2D object to render text to a GL canvas.

class fsleyes.gl.text.Text(text=None, pos=None, off=None, coordinates='proportions', fontSize=10, halign=None, valign=None, colour=None, bgColour=None, alpha=None, scale=None, angle=None)[source]

Bases: object

A Text object manages a RGBA Texture2D object, allowing text to be drawn to a GL canvas.

The fsleyes_widgets.utils.textbitmap module is used to render the text, using matplotlib.

Usage:

# create and maintain a reference to a Text object
import fsleyes.gl.text as gltext
text = gltext.Text('hello')

# modify various properties by direct attribute
# assignment - see __init__ for definitions
text.pos    = (0.5, 0.5)
text.colour = '#FFFFFF'

# activate your GL context, and call draw()
text.draw()

# call destroy() when you're finished
text.destroy()
__init__(text=None, pos=None, off=None, coordinates='proportions', fontSize=10, halign=None, valign=None, colour=None, bgColour=None, alpha=None, scale=None, angle=None)[source]

Create a Text object.

Parameters
  • text – The text to draw.

  • pos – (x, y) position along the horizontal/vertical axes as either a proportion between 0 (left/bottom) and 1 (right/top), or as absolute pixels.

  • off – Fixed (x, y) horizontal/vertical offsets in pixels

  • coordinates – Whether to interpret pos as 'proportions' (the default), or as absolute 'pixels'.

  • fontSize – Font size in points.

  • halign – Horizontal alignemnt - 'left', 'centre', or right.

  • valign – Vertical alignemnt - 'bottom', 'centre', or top.

  • colour – Colour to draw the text in (any matplotlib-compatible colour specification)

  • bgColour – Background colour (default: transparent).

  • alpha – Opacity between 0 and 1.

  • scale – Scale the text by this factor.

  • angle – Angle, in degrees, by which to rotate the text. NOT IMPLEMENTED YET AND PROBABLY NEVER WILL BE

destroy()[source]

Must be called when this Text is no longer needed. Frees texture resources.

__clearBitmap(old, new)

Used by property setters to clear cached bitmap, if a value which requires the bitmap to be re-generated is changed.

property colour

Return the current foreground colour.

property bgColour

Return the current background colour.

property alpha

Return the current opacity.

property text

Returns the current text value.

__dict__ = mappingproxy({'__module__': 'fsleyes.gl.text', '__doc__': "A ``Text`` object manages a RGBA :class:`.Texture2D` object, allowing\n text to be drawn to a GL canvas.\n\n The :mod:`fsleyes_widgets.utils.textbitmap` module is used to render the\n text, using ``matplotlib``.\n\n Usage::\n\n # create and maintain a reference to a Text object\n import fsleyes.gl.text as gltext\n text = gltext.Text('hello')\n\n # modify various properties by direct attribute\n # assignment - see __init__ for definitions\n text.pos = (0.5, 0.5)\n text.colour = '#FFFFFF'\n\n # activate your GL context, and call draw()\n text.draw()\n\n # call destroy() when you're finished\n text.destroy()\n ", '__init__': <function Text.__init__>, 'destroy': <function Text.destroy>, '_Text__clearBitmap': <function Text.__clearBitmap>, 'colour': <property object>, 'bgColour': <property object>, 'alpha': <property object>, 'text': <property object>, 'fontSize': <property object>, 'size': <property object>, '_Text__refreshBitmap': <function Text.__refreshBitmap>, 'draw': <function Text.draw>, '__dict__': <attribute '__dict__' of 'Text' objects>, '__weakref__': <attribute '__weakref__' of 'Text' objects>, '__annotations__': {}})
__module__ = 'fsleyes.gl.text'
__weakref__

list of weak references to the object (if defined)

property fontSize

Returns the current font size.

property size

Return the size of the text texture in pixels, scaled by the scale factor if it is set. Returns None if the text has not yet been drawn and the bitmap not created.

__refreshBitmap()

Called when the text bitmap and texture data needs a refresh.

draw(width, height)[source]

Draws the texture onto the current GL canvas.

Parameters
  • width – Width of canvas in pixels

  • height – Height of canvas in pixels