Chapter 8. Text editing

Table of Contents

Text

PyClutter's clutter.Text actor can display text and allow it to be edited. It doesn't have as much functionality as, for instance, PyGTK's gtk.TextView widget, but it is enough for displaying information and for simple text entry. Therefore it serves the same purposes as PyGTK's gtk.Label or gtk.Entry widgets, with the addition of multi line editing.

There are three ways you might use a clutter.Text actor:

  • For a simple label, use clutter.Text() or text.set_markup(). To make it non-editable use text.set_editable().

  • For single line text entry, similar to a gtk.Entry in a normal PyGTK application, create a clutter.Text using clutter.Text() and text.set_single_line_mode(). You may call text.set_activatable() and connect to the activate signal to react when the user presses Enter.

  • For full-featured multi-line text editing, clutter.Text gives you access to the cursor position using the text.{get,set}_cursor_*() functions and to the selection using the text.{get,set}_selection_*() functions. You can also add and remove text at any position.

Text Reference

[Note] Note

When you want the clutter.Text to be editable you must give it key focus using stage.set_key_focus().

Size Management

To discover the size needed by the text inside a clutter.Text actor, you may call will the actor.get_preferred_height() function. This will provide the vertical space necessary to display all of the text at the currently specified width. Alternatively, you could call actor.get_preferred_width() to discover the horizontal space necessary for the text at the currently specified height.