Event API

class wdom.event.Event(type: str, init: typing.Dict[str, typing.Any] = None) → None[source]

Bases: object

Base class of Event classes.

Create event object.

First argument (type) is a string to represents type of this event. Second optional argument (init) is a dictionally, which has fields for this event’s status.

currentTarget

Return current event target.

Return type:Optional[WebEventTarget]
target

Return original event target, which emitted this event first.

Return type:Optional[WebEventTarget]
stopPrapagation()[source]

Not implemented yet.

Return type:None
class wdom.event.MouseEvent(type: str, init: typing.Dict[str, typing.Any] = None) → None[source]

Bases: wdom.event.UIEvent

Mouse event class.

Event types generate this event class are click, dblclick, mouseup, and mousedown.

This class has the following attributes:

altKey, button, clientX, clientY, ctrlKey, metaKey, movementX, movementY, offsetX, offsetY, pageX, pageY, region, screenX, screenY, shiftKey, x, y

For details of the attributes, see MouseEvent - Web APIs | MDN

class wdom.event.KeyboardEvent(type: str, init: typing.Dict[str, typing.Any] = None) → None[source]

Bases: wdom.event.UIEvent

Keyboard event class.

Event types generate this event class are keydown, keypress, and keyup.

This class has the following attributes:

altKey, code, ctrlKey, key, locale, metaKey, repeat, shiftKey

For details of the attributes, see KeyboardEvent - Web APIs | MDN

class wdom.event.DragEvent(type: str, init: typing.Dict[str, typing.Any] = None) → None[source]

Bases: wdom.event.MouseEvent

Drag event class.

This class inherits MouseEvent class and has own attribute dataTransfer, which is DataTransfer containing data send by this drag event.

Event types generate this event class are drag, dragend, dragenter, dragexit, dragleave, dragover, dragstart, and drop.

class wdom.event.DataTransfer(id: str = '') → None[source]

Bases: object

DataTransfer object is used to transfer drag/drop data.

TODO: Currently always read/write enabled. https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode

Initialize a new empty DataTransfer object with id.

length

Return number of items in this DataTransfer object.

Return type:int
getData(type)[source]

Get data of type format.

If this DataTransfer object does not have type data, return empty string. :arg str type: Data format of the data, like ‘text/plain’.

Return type:str
setData(type, data)[source]

Set data of type format.

Parameters:type (str) – Data format of the data, like ‘text/plain’.
Return type:None
clearData(type='')[source]

Remove data of type foramt.

If type argument is omitted, remove all data.

Return type:None
wdom.event.create_event(msg)[source]

Create Event from JSOM msg and set target nodes.

Parameters:
  • currentTarget (EventTarget) – Current event target node.
  • target (EventTarget) – Node which emitted this event first.
  • init (dict) – Event options.
Return type:

Event

class wdom.event.EventListener(listener: typing.Union[typing.Callable[[wdom.event.Event], NoneType], typing.Callable[[wdom.event.Event], typing.Awaitable[NoneType]]]) → None[source]

Bases: object

Class to wrap an event listener function.

Acceptable listeners are function, coroutine, and coroutine-function. If listener is a coroutine or coroutine-function, it will be executed synchronously as if it is normal function.

Wrap an event listener.

Event listener should be function or coroutine-function.

class wdom.event.EventTarget(*args: typing.Any, **kwargs: typing.Any) → None[source]

Bases: object

Base class for EventTargets.

This class and subclasses can add/remove event listeners and emit events.

ownerDocument

Need to check the target is mounted on document or not.

Return type:Optional[Node]
addEventListener(event, listener)[source]

Add event listener to this node.

event is a string which determines the event type when the new listener called. Acceptable events are same as JavaScript, without on. For example, to add a listener which is called when this node is clicked, event is 'click.

Return type:None
removeEventListener(event, listener)[source]

Remove an event listener of this node.

The listener is removed only when both event type and listener is matched.

Return type:None
on_event_pre(event)[source]

Run before dispatching events.

Used for seting values changed by user input, in some elements like input, textarea, or select. In this method, event.currentTarget is a dict sent from browser.

Return type:None
dispatchEvent(event)[source]

Emit events.

Return type:None