You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lexonomy_custom_editor/src/message/message.py

55 lines
1.4 KiB

from update import update
from browser import window
class Message:
def __init__(self, *args):
self._args = args
self.error = None
def update_model(self, model):
raise NotImplementedError("This message does not implement update_model method")
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
def data_change(self):
return True
def add_arg(self, arg):
self._args.append(arg)
def reset(self):
return True
class ClickMessage(Message):
def on_event(self, event):
event.stopPropagation()
def data_change(self):
return False
def msg(message, params):
if not issubclass(type(message), Message):
window.console.log("Not scheduling a Message type, this will not work!")
return lambda: None
def callback(event):
message.on_event(event) #message_class(event, params)
update.schedule(message)
return callback