2019-11-11 22:04:45 +00:00
|
|
|
from browser import window
|
2019-11-20 23:28:49 +00:00
|
|
|
from message.message import Message, msg
|
2019-11-05 21:18:20 +00:00
|
|
|
|
|
|
|
|
2019-11-20 23:28:49 +00:00
|
|
|
# click messages stuff
|
|
|
|
|
|
|
|
|
|
|
|
class DataChgClickMessage(Message):
|
|
|
|
def on_event(self, event):
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
|
|
|
|
class ClickMessage(DataChgClickMessage):
|
|
|
|
def data_change(self):
|
2020-01-04 13:36:09 +00:00
|
|
|
return False
|
2019-11-20 23:28:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
# reset messages stuff
|
|
|
|
|
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
class Reset(ClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class NoReset(Reset):
|
|
|
|
def reset(self):
|
|
|
|
return False
|
2020-01-05 08:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KeyboardPress(Message):
|
|
|
|
def on_event(self, event):
|
|
|
|
self.add_arg(event.key)
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
key = self.get_arg(0, str)
|
|
|
|
return key == "Escape"
|
|
|
|
|
|
|
|
def update_model(self, model):
|
|
|
|
pass
|
2019-11-11 22:04:45 +00:00
|
|
|
|
2019-11-20 23:28:49 +00:00
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
# 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):
|
2019-11-05 21:18:20 +00:00
|
|
|
def update_model(self, model):
|
2019-11-11 23:34:52 +00:00
|
|
|
model.modal_reset()
|
2019-11-20 21:25:31 +00:00
|
|
|
|
|
|
|
def data_change(self):
|
|
|
|
return False
|
2019-11-11 22:04:45 +00:00
|
|
|
|
2019-11-17 20:15:35 +00:00
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
class ModalNotOkClose(Reset):
|
|
|
|
def update_model(self, model):
|
|
|
|
# msg just creates a callback, need to actually run it!
|
2019-11-17 20:15:35 +00:00
|
|
|
window.setTimeout(lambda: msg(_ModalResetDelayed())(None), 100)
|
2019-11-20 21:25:31 +00:00
|
|
|
|
|
|
|
def data_change(self):
|
|
|
|
return False
|
2019-11-11 22:04:45 +00:00
|
|
|
|
2020-01-02 09:38:06 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
|