events¶
Domonic includes a DOM-style event system with EventTarget at the core.
You can use it directly on your own Python objects:
from domonic.events import *
class SomeEventHandler(EventTarget):
def __init__(self):
super().__init__()
self.addEventListener('some_event', self.on_custom_event)
def on_custom_event(self, evt):
print('that just happened')
my_handler = SomeEventHandler()
my_handler.dispatchEvent(Event('some_event'))
And because DOM nodes also inherit from that event model, you can listen for events on virtual documents and elements too:
def on_page_clicked(evt):
print('the page was just clicked', evt)
print('mouseX', evt.x)
print('mouseY', evt.y)
page.addEventListener( MouseEvent.CLICK, on_page_clicked )
domonic.events¶
DOM-style event classes and dispatch machinery for domonic.
This module provides EventTarget plus a broad set of web-platform-flavoured
event classes so DOM nodes, windows, animations, and helper objects can share a
common event model.
- class domonic.events.AbortController[source]
Controller used to abort work associated with an AbortSignal.
- class domonic.events.AbortSignal[source]
Signal object used to communicate cancellation.
- class domonic.events.AnimationEvent[source]
- ANIMATIONEND: str = 'animationend'
- ANIMATIONITERATION: str = 'animationiteration'
- ANIMATIONSTART: str = 'animationstart'
- animationName
Returns the name of the animation
- elapsedTime
Returns the number of seconds an animation has been running
- pseudoElement
Returns the name of the pseudo-element of the animation
- class domonic.events.BeforeUnloadEvent(_type: str, options: dict[str, Any] | None = None, *args, **kwargs)[source]
- class domonic.events.ClipboardEvent[source]
- COPY: str = 'copy'
- CUT: str = 'cut'
- PASTE: str = 'paste'
- clipboardData
Returns an object containing the data affected by the clipboard operation
- class domonic.events.CompositionEvent[source]
- class domonic.events.CustomEvent[source]
- class domonic.events.DOMContentLoadedEvent[source]
- DOMCONTENTLOADED: str = 'DOMContentLoaded'
- document
Returns the document that was loaded
- class domonic.events.DragEvent[source]
- DRAG: str = 'drag'
- DROP: str = 'drop'
- END: str = 'dragend'
- ENTER: str = 'dragenter'
- EXIT: str = 'dragexit'
- LEAVE: str = 'dragleave'
- OVER: str = 'dragover'
- START: str = 'dragstart'
- dataTransfer
Returns the data that is dragged/dropped
- class domonic.events.Event(_type: str = '', options: dict[str, Any] | None = None, *args, **kwargs)[source]
Event class represents events and their properties.
- ABORT: str = 'abort'
- AFTERPRINT: str = 'afterprint'
- BEFOREPRINT: str = 'beforeprint'
- BEFOREUNLOAD: str = 'beforeunload'
- CANPLAY: str = 'canplay'
- CANPLAYTHROUGH: str = 'canplaythrough'
- CHANGE: str = 'change'
- DURATIONCHANGE: str = 'durationchange'
- EMPTIED: str = 'emptied'
- ENDED: str = 'ended'
- ERROR: str = 'error'
- FULLSCREENCHANGE: str = 'fullscreenchange'
- FULLSCREENERROR: str = 'fullscreenerror'
- INPUT: str = 'input'
- INVALID: str = 'invalid'
- LOAD: str = 'load'
- LOADEDDATA: str = 'loadeddata'
- LOADEDMETADATA: str = 'loadedmetadata'
- MESSAGE: str = 'message'
- OFFLINE: str = 'offline'
- ONLINE: str = 'online'
- OPEN: str = 'open'
- PAUSE: str = 'pause'
- PLAY: str = 'play'
- PLAYING: str = 'playing'
- PROGRESS: str = 'progress'
- RATECHANGE: str = 'ratechange'
- READYSTATECHANGE: str = 'readystatechange'
- RESET: str = 'reset'
- RESIZE: str = 'resize'
- SCROLL: str = 'scroll'
- SEARCH: str = 'search'
- SEEKED: str = 'seeked'
- SEEKING: str = 'seeking'
- SELECT: str = 'select'
- SHOW: str = 'show'
- STALLED: str = 'stalled'
- SUBMIT: str = 'submit'
- SUSPEND: str = 'suspend'
- TOGGLE: str = 'toggle'
- UNLOAD: str = 'unload'
- VOLUMECHANGE: str = 'volumechange'
- WAITING: str = 'waiting'
- composedPath()[source]
Returns a list of the event’s path, from the root to the target.
- initEvent(_type: str | None = None, bubbles: bool = True, cancelable: bool = True, *args, **kwargs) Event[source]
Initialize the event.
- msConvertURL(url)[source]
Converts the provided URL to a format recognized by Internet Explorer.
- preventDefault() None[source]
Prevents the default action associated with the event, if cancelable.
This method is used to signal that the event should not trigger its default behavior.
- Returns:
None
- stopImmediatePropagation() None[source]
Prevents further propagation of the current event and immediately stops other event listeners in the same phase from being invoked.
This method is used to stop the event’s propagation immediately and ensure that no other listeners in the same phase are invoked.
- Returns:
None
- stopPropagation()[source]
[prevents further propagation of the current event in the capturing and bubbling phases]
- domonic.events.EventDispatcher
legacy alias
- class domonic.events.EventListener[source]
Interface-style base for listener objects with
handleEvent().
- class domonic.events.EventListenerOptions(capture: bool = False, once: bool = False, passive: bool = False, signal: Any = None)[source]
Dictionary-like helper for DOM listener options.
Supports the common
capture,once,passive, andsignalfields accepted byaddEventListener().
- class domonic.events.EventTarget(*args, **kwargs)[source]
DOM-style event target base class.
Extend
EventTargetto give an object support foraddEventListener(),removeEventListener(), anddispatchEvent()with DOM-like capture, target, and bubble semantics where appropriate.- addEventListener(eventType: str, callback: Callable[[...], Any], options: bool | dict[str, Any] | None = None, *args, **kwargs) None[source]
Add an event listener for the given event type.
- Parameters:
eventType (str) – The type of the event to listen for.
callback (Callable) – The callback function to be executed when the event occurs.
- dispatchEvent(event: Any) bool[source]
Dispatch the specified event to all registered event listeners.
- Parameters:
event (Dict) – The event object to be dispatched.
- Returns:
True if the event was successfully dispatched, otherwise False.
- Return type:
- async dispatchEventAsync(event: Any) bool[source]
Dispatch the specified event asynchronously to all registered event listeners.
- Parameters:
event (Dict) – The event object to be dispatched.
- Returns:
True if the event was successfully dispatched, otherwise False.
- Return type:
Usage:
To dispatch an event asynchronously, use the
awaitkeyword when calling this method.Example:
event_data = {"message": "Hello, world!"} async_event = {"type": "async_event", "data": event_data} await target.dispatchEventAsync(async_event)
- class domonic.events.ExtendableEvent[source]
- extendable
Returns whether the event is extendable or not
- class domonic.events.FetchEvent[source]
- FETCH: str = 'fetch'
- clientId
Returns the client ID of the fetch request
- request
Returns the request object
- respondWith(response)[source]
Returns a promise that resolves to the response object
- waitUntil(promise)[source]
Returns a promise that resolves when the response is available
- class domonic.events.FocusEvent[source]
- BLUR: str = 'blur'
- FOCUS: str = 'focus'
- FOCUSIN: str = 'focusin'
- FOCUSOUT: str = 'focusout'
- class domonic.events.GamePadEvent[source]
- START: str = 'gamepadconnected'
- STOP: str = 'gamepaddisconnected'
- class domonic.events.InputEvent[source]
- CHANGE: str = 'change'
- INPUT: str = 'input'
- SELECT: str = 'select'
- data
Returns the inserted characters
- dataTransfer
Returns an object containing information about the inserted/deleted data
- getTargetRanges()[source]
Returns an array containing target ranges that will be affected by the insertion/deletion
- inputType
Returns the type of the change (i.e “inserting” or “deleting”)
- isComposing
Returns whether the state of the event is composing or not
- class domonic.events.KeyboardEvent(_type: str, options: dict = None, *args, **kwargs)[source]
keyboard events
- DOM_KEY_LOCATION_LEFT: int = 1
- DOM_KEY_LOCATION_NUMPAD: int = 3
- DOM_KEY_LOCATION_RIGHT: int = 2
- DOM_KEY_LOCATION_STANDARD: int = 0
- KEYDOWN: str = 'keydown'
- KEYPRESS: str = 'keypress'
- KEYUP: str = 'keyup'
- class domonic.events.MessageEvent[source]
- CONNECT: str = 'connect'
- DISCONNECT: str = 'disconnect'
- MESSAGE: str = 'message'
- data
Returns the data of the message
- lastEventId
Returns the last event id of the message
- origin
Returns the origin of the message
- ports
Returns the ports of the message
- source
Returns the source of the message
- class domonic.events.MouseEvent(_type: str, options: dict = None, *args, **kwargs)[source]
mouse events
- CLICK: str = 'click'
- CONTEXTMENU: str = 'contextmenu'
- DBLCLICK: str = 'dblclick'
- MOUSEDOWN: str = 'mousedown'
- MOUSEENTER: str = 'mouseenter'
- MOUSELEAVE: str = 'mouseleave'
- MOUSEMOVE: str = 'mousemove'
- MOUSEOUT: str = 'mouseout'
- MOUSEOVER: str = 'mouseover'
- MOUSEUP: str = 'mouseup'
- class domonic.events.PageTransitionEvent[source]
- PAGEHIDE: str = 'pagehide'
- PAGESHOW: str = 'pageshow'
- persisted
Returns whether the webpage was cached by the browser
- class domonic.events.PointerEvent[source]
- POINTER: str = 'pointer'
- POINTERCANCEL: str = 'pointercancel'
- POINTERDOWN: str = 'pointerdown'
- POINTERENTER: str = 'pointerenter'
- POINTERLEAVE: str = 'pointerleave'
- POINTERMOVE: str = 'pointermove'
- POINTEROUT: str = 'pointerout'
- POINTEROVER: str = 'pointerover'
- POINTERUP: str = 'pointerup'
- class domonic.events.PopStateEvent[source]
- POPSTATE: str = 'popstate'
- state
Returns an object containing a copy of the history entries
- class domonic.events.ProgressEvent[source]
- ABORT: str = 'abort'
- ERROR: str = 'error'
- LOAD: str = 'load'
- LOADED: str = 'loaded'
- LOADEND: str = 'loadend'
- LOADSTART: str = 'loadstart'
- PROGRESS: str = 'progress'
- TIMEOUT: str = 'timeout'
- class domonic.events.PromiseRejectionEvent[source]
- HANDLED: str = 'rejectionhandled'
- UNHANDLED: str = 'unhandledrejection'
- isRejected
Returns whether the promise was rejected or not
- promise
Returns the promise that was rejected
- reason
Returns the reason of the rejection
- class domonic.events.SVGEvent[source]
- ABORT: str = 'abort'
- ERROR: str = 'error'
- LOAD: str = 'load'
- LOADEDDATA: str = 'loadeddata'
- LOADEDMETADATA: str = 'loadedmetadata'
- LOADSTART: str = 'loadstart'
- PROGRESS: str = 'progress'
- SCROLL: str = 'scroll'
- UNLOAD: str = 'unload'
- class domonic.events.SecurityPolicyViolationEvent[source]
- SECURITY_POLICY_VIOLATION: str = 'securitypolicyviolation'
- blockedURI
Returns the blocked URI
- frame
Returns the frame that violated the policy
- isFrameAncestor
Returns whether the frame is an ancestor of the frame that violated the policy
- isMainFrame
Returns whether the frame is the main frame
- originalPolicy
Returns the original policy
- violatedDirective
Returns the violated directive
- class domonic.events.StorageEvent[source]
- STORAGE: str = 'storage'
- key
Returns the key of the changed storage item
- newValue
Returns the new value of the changed storage item
- oldValue
Returns the old value of the changed storage item
- storageArea
Returns an object representing the affected storage object
- url
Returns the URL of the changed item’s document
- class domonic.events.SyncEvent[source]
- SYNC: str = 'sync'
- lastChance
Returns whether the sync event is the last chance or not
- tag
Returns the tag of the sync event
- class domonic.events.TimerEvent(_type: str, options: dict = None, *args, **kwargs)[source]
- TIMER: str = 'timer'
- TIMER_COMPLETE: str = 'timercomplete'
TimerEvent
- class domonic.events.TouchEvent[source]
- TOUCHCANCEL: str = 'touchcancel'
- TOUCHEND: str = 'touchend'
- TOUCHMOVE: str = 'touchmove'
- TOUCHSTART: str = 'touchstart'
- class domonic.events.TransitionEvent[source]
- TRANSITIONEND: str = 'transitionend'
- elapsedTime
Returns the number of seconds a transition has been running
- propertyName
Returns the name of the transition
- pseudoElement
Returns the name of the pseudo-element of the transition
- class domonic.events.TweenEvent[source]
- COMPLETE: str = 'onComplete'
- PAUSE: str = 'onPause'
- RESET: str = 'onReset'
- START: str = 'onStart'
- STOP: str = 'onStop'
- TIMER: str = 'onTimer'
- UNPAUSE: str = 'onUnPause'
- UPDATE_END: str = 'onUpdateEnd'
- UPDATE_START: str = 'onUpdateStart'
- class domonic.events.UIEvent(_type: str, options: dict = None, *args, **kwargs)[source]
UIEvent is a specialized event class for user interface events.