Beispiel #1
0
    def __init__(self, type: str, init: EventMsgDict = None) -> None:
        """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.
        """
        from wdom.document import getElementByWdomId
        self.type = type
        self.init = dict() if init is None else init
        _id = self.init.get('currentTarget', {'id': None}).get('id')
        ctarget = getElementByWdomId(_id)
        self.__currentTarget = ctarget
        _id = self.init.get('target', {'id': None}).get('id')
        self.__target = getElementByWdomId(_id) or ctarget
Beispiel #2
0
def response_handler(msg: Dict[str, str]) -> None:
    """Handle response sent by browser."""
    from wdom.document import getElementByWdomId
    id = msg['id']
    elm = getElementByWdomId(id)
    if elm:
        elm.on_response(msg)
    else:
        logger.warning('No such element: wdom_id={}'.format(id))
Beispiel #3
0
 def __init__(self, type: str, init: EventMsgDict = None) -> None:
     super().__init__(type, init)
     for attr in self.attrs:
         setattr(self, attr, self.init.get(attr))
     rt = self.init.get('relatedTarget') or {'id': None}
     rid = rt.get('id')
     if rid is not None:
         from wdom.document import getElementByWdomId
         self.relatedTarget = getElementByWdomId(rid)
     else:
         self.relatedTarget = None
Beispiel #4
0
 def test_get_element_by_wdom_id_win(self):
     win = getElementByWdomId('window')
     self.assertIs(get_document().defaultView, win)
Beispiel #5
0
 def test_get_element_by_wdom_id_doc(self):
     doc = getElementByWdomId('document')
     self.assertIs(get_document(), doc)
Beispiel #6
0
def drop(e):
    start_elm = getElementByWdomId(e.dataTransfer.getData('text/plain'))
    current_color = e.currentTarget.style['background-color']
    start_color = start_elm.style['background-color']
    start_elm.style['background-color'] = current_color
    e.currentTarget.style['background-color'] = start_color