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
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))
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
def test_get_element_by_wdom_id_win(self): win = getElementByWdomId('window') self.assertIs(get_document().defaultView, win)
def test_get_element_by_wdom_id_doc(self): doc = getElementByWdomId('document') self.assertIs(get_document(), doc)
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