from browser import window, document from message.message import Message, msg, delayed_msg # click messages stuff class DataChgClickMessage(Message): def on_event(self, event): event.stopPropagation() class ClickMessage(DataChgClickMessage): def data_change(self): return False # reset messages stuff class Reset(ClickMessage): def update_model(self, model): pass class NoReset(Reset): def reset(self): return False class NoAction(NoReset): def no_action(self): return True class KeyboardPress(Message): def on_event(self, event): self.add_arg(event.key) self.add_arg(event) def reset(self): key = self.get_arg(0, str) return key == "Escape" def data_change(self): return False def _handle_textarea(self): event = self.get_arg(1) if event.target["type"] == "textarea": event.preventDefault(); def update_model(self, model): key = self.get_arg(0, str) # Enter when modal shown -> press ok button if model.modal_shown and key == "Enter": # handle textarea as per user wishes self._handle_textarea() ok_button = document.getElementById("modal-ok") if ok_button is not None: # has to be called in separate thread window.setTimeout(lambda: ok_button.click(), 10) # a "hack" message for reseting modals # # everytime a modal closes, run 100ms later model.modal = [] # this is done to achieve nice close animation # after setting model.modal, do view update to actually update the DOM class _ModalResetDelayed(Message): def update_model(self, model): model.modal_reset() def data_change(self): return False class ModalNotOkClose(Reset): def update_model(self, model): # modal reset should be called a bit later for shoother transition delayed_msg(_ModalResetDelayed, None, 100) def data_change(self): return False