Class TheGlobalEventBroadcaster

Introduction

This is a simpler way to add listeners to the global event broadcaster that are broadcasted by theGlobalEventBroadcaster.

Example Usage

import contextlib
from typing import TYPE_CHECKING, Any, cast
from ooodev.loader import Lo

if TYPE_CHECKING:
    from com.sun.star.document import DocumentEvent
else:
    DocumentEvent = Any

#  Add a listener to the global event broadcaster
Lo.global_event_broadcaster.add_event_document_event_occurred(on_global_document_event)

def on_global_document_event(src: Any, event: EventArgs, *args, **kwargs) -> None:
    # This is a listener for the global event broadcaster
    with contextlib.suppress(Exception):
        doc_event = cast(DocumentEvent, event.event_data)
        name = doc_event.EventName
        if name == "OnUnfocus":
            # only interested in the OnUnfocus event
            self._clear_cache()

Class Declaration

class ooodev.loader.comp.the_global_event_broadcaster.TheGlobalEventBroadcaster(component)[source]

Bases: TheGlobalEventBroadcasterComp

Class for managing theGlobalEventBroadcaster singleton Class.

__init__(component)[source]

Constructor

Parameters:

component (Any) – UNO Component that implements com.sun.star.frame.theGlobalEventBroadcaster service.

Return type:

None

add_document_event_listener(listener)

Registers a listener which is notified about document events

Return type:

None

Parameters:

listener (com.sun.star.document.XDocumentEventListener) –

add_event_document_event_events_disposing(cb)

Adds a listener for an event.

Event is invoked when the broadcaster is about to be disposed.

The callback EventArgs.event_data will contain a UNO com.sun.star.lang.EventObject struct.

Return type:

None

Parameters:

cb (Any) –

add_event_document_event_occured(cb)

Adds a listener for an event.

Event is invoked when range selection is completed.

The callback EventArgs.event_data will contain a UNO com.sun.star.document.DocumentEvent struct.

Return type:

None

Parameters:

cb (Any) –

add_event_document_event_occurred(cb)

Adds a listener for an event.

Event is invoked when range selection is completed.

The callback EventArgs.event_data will contain a UNO com.sun.star.document.DocumentEvent struct.

Return type:

None

Parameters:

cb (Any) –

create_enumeration()

Creates an enumeration of the container’s elements.

Return type:

XEnumeration

document_event_occured(Event)

Event is invoked when a document event occurred

Return type:

None

Parameters:

Event (com.sun.star.document.DocumentEvent) –

classmethod from_lo(lo_inst=None)

Get the singleton instance from the Lo.

Parameters:

lo_inst (LoInst, optional) – LoInst, Defaults to Lo.current_lo.

Returns:

The instance.

Return type:

TheGlobalEventBroadcasterComp

get_element_type()

Gets the type of the elements contained in the container.

Returns:

The type of the elements. None means that it is a multi-type container and you cannot determine the exact types with this interface.

Return type:

Any

get_events()

Offers a list of event handlers which are be bound to events of this object

Return type:

NameReplaceComp

has(element)

Gets if element is in this container.

Return type:

bool

Parameters:

element (Any) –

has_elements()

Determines whether the container has elements.

Return type:

bool

insert(element)

Inserts the given element into this container.

Raises:
  • com.sun.star.lang.IllegalArgumentExceptionIllegalArgumentException

  • com.sun.star.container.ElementExistExceptionElementExistException

Return type:

None

Parameters:

element (Any) –

notify_document_event(event_name, view_controller, supplement)

Causes the broadcaster to notify all registered listeners of the given event

The method will create a DocumentEvent instance with the given parameters, and fill in the Source member (denoting the broadcaster) as appropriate.

Whether the actual notification happens synchronously or asynchronously is up to the implementor of this method. However, implementations are encouraged to specify this, for the list of supported event types, in their service contract.

Implementations might also decide to limit the list of allowed events (means event names) at their own discretion. Again, in this case they’re encouraged to document this in their service contract.

Raises:
  • com.sun.star.lang.IllegalArgumentExceptionIllegalArgumentException

  • com.sun.star.lang.NoSupportExceptionNoSupportException

Return type:

None

Parameters:
  • event_name (str) –

  • view_controller (com.sun.star.frame.XController2) –

  • supplement (Any) –

remove(element)

removes the given element from this container.

Raises:
  • com.sun.star.lang.IllegalArgumentExceptionIllegalArgumentException

  • com.sun.star.container.NoSuchElementExceptionNoSuchElementException

Return type:

None

Parameters:

element (Any) –

remove_document_event_listener(listener)

revokes a listener which has previously been registered to be notified about document events.

Return type:

None

Parameters:

listener (com.sun.star.document.XDocumentEventListener) –

remove_event_document_event_events_disposing(cb)

Removes a listener for an event

Return type:

None

Parameters:

cb (Any) –

remove_event_document_event_occured(cb)

Removes a listener for an event

Return type:

None

Parameters:

cb (Any) –

remove_event_document_event_occurred(cb)

Removes a listener for an event

Return type:

None

Parameters:

cb (Any) –

property component: com.sun.star.frame.theGlobalEventBroadcaster

theGlobalEventBroadcaster Component

Return type:

theGlobalEventBroadcaster

property events_listener_document_event: DocumentEventListener

Returns listener

Return type:

DocumentEventListener