2019-11-11 22:04:45 +00:00
|
|
|
from update import update
|
2019-11-17 20:30:30 +00:00
|
|
|
from browser import window
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2019-11-05 21:18:20 +00:00
|
|
|
class Message:
|
2019-11-17 20:30:30 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self._args = args
|
|
|
|
self.error = None
|
|
|
|
|
2019-11-05 21:18:20 +00:00
|
|
|
def update_model(self, model):
|
2019-11-11 22:04:45 +00:00
|
|
|
raise NotImplementedError("This message does not implement update_model method")
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
def on_event(self, event):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_arg(self, n, argtype=None):
|
|
|
|
if n > len(self._args):
|
|
|
|
window.console.log("not enough arguments: {} <= {}".format(n, len(self._args)))
|
|
|
|
|
|
|
|
result = self._args[n]
|
|
|
|
if argtype is not None:
|
|
|
|
if not type(result) is argtype:
|
|
|
|
window.console.trace("Error type check!")
|
|
|
|
return None
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2019-11-20 21:25:31 +00:00
|
|
|
def data_change(self):
|
|
|
|
return True
|
|
|
|
|
2020-02-19 22:15:42 +00:00
|
|
|
def entry_redraw(self):
|
|
|
|
return self.data_change()
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
def add_arg(self, arg):
|
|
|
|
self._args.append(arg)
|
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
def reset(self):
|
|
|
|
return True
|
2020-01-05 08:53:16 +00:00
|
|
|
|
|
|
|
def clear_args(self):
|
|
|
|
self._args = []
|
2020-03-30 18:25:17 +00:00
|
|
|
|
|
|
|
def no_action(self):
|
|
|
|
return False
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2020-02-16 23:00:03 +00:00
|
|
|
def msg(message_class, *params):
|
2019-11-11 22:04:45 +00:00
|
|
|
def callback(event):
|
2020-02-16 23:00:03 +00:00
|
|
|
message = message_class(*params)
|
2020-02-16 22:17:46 +00:00
|
|
|
if not issubclass(type(message), Message):
|
|
|
|
window.console.log("Not scheduling a Message type, this will not work!")
|
|
|
|
return
|
|
|
|
|
|
|
|
message.on_event(event)
|
2020-03-30 18:25:17 +00:00
|
|
|
update.update_model(message)
|
2019-11-11 22:04:45 +00:00
|
|
|
return callback
|
2020-06-11 20:34:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def delayed_msg(message_class, event, timeout_ms, *params):
|
|
|
|
window.setTimeout(lambda: msg(message_class, *params)(event), timeout_ms)
|