from browser import window from message.message import Message, msg # click messages stuff class DataChgClickMessage(Message): def on_event(self, event): event.stopPropagation() class ClickMessage(DataChgClickMessage): def data_change(self): return True # reset messages stuff class Reset(ClickMessage): def update_model(self, model): pass class NoReset(Reset): def reset(self): return False # 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): # msg just creates a callback, need to actually run it! window.setTimeout(lambda: msg(_ModalResetDelayed())(None), 100) def data_change(self): return False # Special message to handle ctrl+click and click # overwrite update_model_noctrl and/or update_model_ctrl class CtrlClickMessage(ClickMessage): def on_event(self, event): super().on_event(event) self.ctrl = event.ctrlKey def update_model(self, model): if self.ctrl: self.update_model_ctrl(model) else: self.update_model_noctrl(model) def update_model_ctrl(self, model): pass def update_model_noctrl(self, model): pass