UnformattedDocument Class

Inheritance diagram of UnformattedDocument

class UnformattedDocument(text='')

A document having uniform style over all text.

Changes to the style of text within the document affects the entire document. For convenience, the position parameters of the style methods may therefore be omitted.

Constructor:

__init__(text='')

Methods:

delete_text(start, end) Delete text from the document.
dispatch_event(event_type, *args) Dispatch a single event to the attached handlers.
event(*args) Function decorator for an event handler.
get_element(position) Get the element at a specified position.
get_element_runs()
get_font([position, dpi])
get_font_runs([dpi])
get_paragraph_end(pos) Get the end position of a paragraph.
get_paragraph_start(pos) Get the starting position of a paragraph.
get_style(attribute[, position])
get_style_range(attribute, start, end) Get an attribute style over the given range.
get_style_runs(attribute)
insert_element(position, element[, attributes]) Insert a element into the document.
insert_text(start, text[, attributes]) Insert text into the document.
pop_handlers() Pop the top level of event handlers off the stack.
push_handlers(*args, **kwargs) Push a level onto the top of the handler stack, then attach zero or more event handlers.
register_event_type(name) Register an event type with the dispatcher.
remove_handler(name, handler) Remove a single event handler.
remove_handlers(*args, **kwargs) Remove event handlers from the event stack.
set_handler(name, handler) Attach a single event handler.
set_handlers(*args, **kwargs) Attach one or more event handlers to the top level of the handler stack.
set_paragraph_style(start, end, attributes)
set_style(start, end, attributes)

Events:

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

Attributes:

event_types Type: list
text Document text.

Methods

UnformattedDocument.get_element_runs()
UnformattedDocument.get_font(position=None, dpi=None)
UnformattedDocument.get_font_runs(dpi=None)
UnformattedDocument.get_style(attribute, position=None)
UnformattedDocument.get_style_runs(attribute)
UnformattedDocument.set_paragraph_style(start, end, attributes)
UnformattedDocument.set_style(start, end, attributes)

Inherited members

Methods

UnformattedDocument.delete_text(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).
UnformattedDocument.dispatch_event(event_type, *args)

Dispatch a single event to the attached handlers.

The event is propagated to all handlers from from the top of the stack until one returns EVENT_HANDLED. This method should be used only by EventDispatcher implementors; applications should call the dispatch_events method.

Since pyglet 1.2, the method returns EVENT_HANDLED if an event handler returned EVENT_HANDLED or EVENT_UNHANDLED if all events returned EVENT_UNHANDLED. If no matching event handlers are in the stack, False is returned.

Parameters:
  • event_type (str) – Name of the event.
  • args (sequence) – Arguments to pass to the event handler.
Return type:

bool or None

Returns:

(Since pyglet 1.2) EVENT_HANDLED if an event handler returned EVENT_HANDLED; EVENT_UNHANDLED if one or more event handlers were invoked but returned only EVENT_UNHANDLED; otherwise False. In pyglet 1.1 and earler, the return value is always None.

UnformattedDocument.event(*args)

Function decorator for an event handler.

Usage:

win = window.Window()

@win.event
def on_resize(self, width, height):
    # ...

or:

@win.event('on_resize')
def foo(self, width, height):
    # ...
UnformattedDocument.get_element(position)

Get the element at a specified position.

Parameters:position (int) – Position in the document of the element.
Return type:InlineElement
UnformattedDocument.get_paragraph_end(pos)

Get the end position of a paragraph.

Parameters:pos (int) – Character position within paragraph.
Return type:int
UnformattedDocument.get_paragraph_start(pos)

Get the starting position of a paragraph.

Parameters:pos (int) – Character position within paragraph.
Return type:int
UnformattedDocument.get_style_range(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.

UnformattedDocument.insert_element(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.
UnformattedDocument.insert_text(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.
UnformattedDocument.pop_handlers()

Pop the top level of event handlers off the stack.

UnformattedDocument.push_handlers(*args, **kwargs)

Push a level onto the top of the handler stack, then attach zero or more event handlers.

If keyword arguments are given, they name the event type to attach. Otherwise, a callable’s __name__ attribute will be used. Any other object may also be specified, in which case it will be searched for callables with event names.

classmethod UnformattedDocument.register_event_type(name)

Register an event type with the dispatcher.

Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers.

Parameters:name (str) – Name of the event to register.
UnformattedDocument.remove_handler(name, handler)

Remove a single event handler.

The given event handler is removed from the first handler stack frame it appears in. The handler must be the exact same callable as passed to set_handler, set_handlers or push_handlers; and the name must match the event type it is bound to.

No error is raised if the event handler is not set.

Parameters:
  • name (str) – Name of the event type to remove.
  • handler (callable) – Event handler to remove.
UnformattedDocument.remove_handlers(*args, **kwargs)

Remove event handlers from the event stack.

See push_handlers for the accepted argument types. All handlers are removed from the first stack frame that contains any of the given handlers. No error is raised if any handler does not appear in that frame, or if no stack frame contains any of the given handlers.

If the stack frame is empty after removing the handlers, it is removed from the stack. Note that this interferes with the expected symmetry of push_handlers and pop_handlers.

UnformattedDocument.set_handler(name, handler)

Attach a single event handler.

Parameters:
  • name (str) – Name of the event type to attach to.
  • handler (callable) – Event handler to attach.
UnformattedDocument.set_handlers(*args, **kwargs)

Attach one or more event handlers to the top level of the handler stack.

See push_handlers for the accepted argument types.

Events

UnformattedDocument.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).
UnformattedDocument.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.
UnformattedDocument.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.

Attributes

UnformattedDocument.event_types = ['on_insert_text', 'on_delete_text', 'on_style_text']
UnformattedDocument.text

Document text.

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

Type:str

Table Of Contents

Previous topic

InlineElement Class

Next topic

pyglet.text.formats