Class pyglet.text.document.AbstractDocument

event.EventDispatcher --+
                        |
                       AbstractDocument
Known Subclasses:
FormattedDocument, UnformattedDocument

Abstract document interface used by all pyglet.text classes.

This class can be overridden to interface pyglet with a third-party document format. It may be easier to implement the document format in terms of one of the supplied concrete classes FormattedDocument or UnformattedDocument.

Events

  on_insert_text(start, text)
Text was inserted into the document.
  on_delete_text(start, end)
Text was deleted from the document.
  on_style_text(start, end, attributes)
Text character style was modified.

Methods

  __init__(self, text='')
int get_paragraph_start(self, pos)
Get the starting position of a paragraph.
int get_paragraph_end(self, pos)
Get the end position of a paragraph.
AbstractRunIterator get_style_runs(self, attribute)
Get a style iterator over the given style attribute.
  get_style(self, attribute, position=0)
Get an attribute style at the given position.
  get_style_range(self, attribute, start, end)
Get an attribute style over the given range.
AbstractRunIterator get_font_runs(self, dpi=None)
Get a style iterator over the pyglet.font.Font instances used in the document.
pyglet.font.Font get_font(self, position, dpi=None)
Get the font instance used at the given position.
  insert_text(self, start, text, attributes=None)
Insert text into the document.
  delete_text(self, start, end)
Delete text from the document.
  insert_element(self, position, element, attributes=None)
Insert a element into the document.
InlineElement get_element(self, position)
Get the element at a specified position.
  set_style(self, start, end, attributes)
Set text style of some or all of the document.
  set_paragraph_style(self, start, end, attributes)
Set the style for a range of paragraphs.
  dispatch_event(self, event_type, *args)
Dispatch a single event to the attached handlers.
(Inherited from pyglet.event.EventDispatcher)
  event(self, *args)
Function decorator for an event handler.
(Inherited from pyglet.event.EventDispatcher)
  pop_handlers(self)
Pop the top level of event handlers off the stack.
(Inherited from pyglet.event.EventDispatcher)
  push_handlers(self, *args, **kwargs)
Push a level onto the top of the handler stack, then attach zero or more event handlers.
(Inherited from pyglet.event.EventDispatcher)
  register_event_type(cls, name)
Register an event type with the dispatcher.
(Inherited from pyglet.event.EventDispatcher)
  remove_handler(self, name, handler)
Remove a single event handler.
(Inherited from pyglet.event.EventDispatcher)
  remove_handlers(self, *args, **kwargs)
Remove event handlers from the event stack.
(Inherited from pyglet.event.EventDispatcher)
  set_handler(self, name, handler)
Attach a single event handler.
(Inherited from pyglet.event.EventDispatcher)
  set_handlers(self, *args, **kwargs)
Attach one or more event handlers to the top level of the handler stack.
(Inherited from pyglet.event.EventDispatcher)

Properties

str text
Document text.

Class Variables

  event_types = ['on_insert_text', 'on_delete_text', 'on_style_t...

Event Details

on_insert_text

on_insert_text(start, text)
Text was inserted into the document.
Parameters:
start : int
Character insertion point within document.
text : str
The text that was inserted.

on_delete_text

on_delete_text(start, end)
Text was deleted from the document.
Parameters:
start : int
Starting character position of deleted text.
end : int
Ending character position of deleted text (exclusive).

on_style_text

on_style_text(start, end, attributes)
Text character style was modified.
Parameters:
start : int
Starting character position of modified text.
end : int
Ending character position of modified text (exclusive).
attributes : dict
Dictionary giving updated named style attributes of the text.

Method Details

get_paragraph_start

get_paragraph_start(self, pos)
Get the starting position of a paragraph.
Parameters:
pos : int
Character position within paragraph.
Returns: int

get_paragraph_end

get_paragraph_end(self, pos)
Get the end position of a paragraph.
Parameters:
pos : int
Character position within paragraph.
Returns: int

get_style_runs

get_style_runs(self, attribute)
Get a style iterator over the given style attribute.
Parameters:
attribute : str
Name of style attribute to query.
Returns: AbstractRunIterator

get_style

get_style(self, attribute, position=0)
Get an attribute style at the given position.
Parameters:
attribute : str
Name of style attribute to query.
position : int
Character position of document to query.
Returns:
The style set for the attribute at the given position.

get_style_range

get_style_range(self, attribute, start, end)

Get an attribute style over the given range.

If the style varies over the range, STYLE_INDETERMINATE is returned.

Parameters:
attribute : str
Name of style attribute to query.
start : int
Starting character position.
end : int
Ending character position (exclusive).
Returns:
The style set for the attribute over the given range, or STYLE_INDETERMINATE if more than one value is set.

get_font_runs

get_font_runs(self, dpi=None)

Get a style iterator over the pyglet.font.Font instances used in the document.

The font instances are created on-demand by inspection of the font_name, font_size, bold and italic style attributes.

Parameters:
dpi : float
Optional resolution to construct fonts at. See pyglet.font.load.
Returns: AbstractRunIterator

get_font

get_font(self, position, dpi=None)
Get the font instance used at the given position.
Parameters:
position : int
Character position of document to query.
dpi : float
Optional resolution to construct fonts at. See pyglet.font.load.
Returns:
pyglet.font.Font: The font at the given position.

See Also: get_font_runs

insert_text

insert_text(self, start, text, attributes=None)
Insert text into the document.
Parameters:
start : int
Character insertion point within document.
text : str
Text to insert.
attributes : dict
Optional dictionary giving named style attributes of the inserted text.

delete_text

delete_text(self, start, end)
Delete text from the document.
Parameters:
start : int
Starting character position to delete from.
end : int
Ending character position to delete to (exclusive).

insert_element

insert_element(self, position, element, attributes=None)

Insert a element into the document.

See the InlineElement class documentation for details of usage.

Parameters:
position : int
Character insertion point within document.
element : InlineElement
Element to insert.
attributes : dict
Optional dictionary giving named style attributes of the inserted text.

get_element

get_element(self, position)
Get the element at a specified position.
Parameters:
position : int
Position in the document of the element.
Returns: InlineElement

set_style

set_style(self, start, end, attributes)
Set text style of some or all of the document.
Parameters:
start : int
Starting character position.
end : int
Ending character position (exclusive).
attributes : dict
Dictionary giving named style attributes of the text.

set_paragraph_style

set_paragraph_style(self, start, end, attributes)

Set the style for a range of paragraphs.

This is a convenience method for set_style that aligns the character range to the enclosing paragraph(s).

Parameters:
start : int
Starting character position.
end : int
Ending character position (exclusive).
attributes : dict
Dictionary giving named style attributes of the paragraphs.

Property Details

text

Document text.

For efficient incremental updates, use the insert_text and delete_text methods instead of replacing this property.

Type:
str

Class Variable Details

event_types

Value:
['on_insert_text', 'on_delete_text', 'on_style_text']