2020-01-14 20:57:36 +00:00
|
|
|
from browser import window, document
|
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)
|
2020-03-19 20:28:43 +00:00
|
|
|
self.add_arg(event)
|
2020-01-05 08:53:16 +00:00
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
key = self.get_arg(0, str)
|
|
|
|
return key == "Escape"
|
|
|
|
|
2020-02-19 22:08:21 +00:00
|
|
|
def data_change(self):
|
|
|
|
return False
|
|
|
|
|
2020-03-19 20:28:43 +00:00
|
|
|
def _handle_textarea(self):
|
|
|
|
event = self.get_arg(1)
|
|
|
|
if event.target["type"] == "textarea":
|
|
|
|
event.preventDefault();
|
|
|
|
|
2020-01-05 08:53:16 +00:00
|
|
|
def update_model(self, model):
|
2020-01-14 20:57:36 +00:00
|
|
|
key = self.get_arg(0, str)
|
|
|
|
|
|
|
|
# Enter when modal shown -> press ok button
|
|
|
|
if model.modal_shown and key == "Enter":
|
2020-03-19 20:28:43 +00:00
|
|
|
# handle textarea as per user wishes
|
|
|
|
self._handle_textarea()
|
|
|
|
|
2020-01-14 20:57:36 +00:00
|
|
|
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)
|
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!
|
2020-02-16 22:17:46 +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
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
|