WIP: changing how msg() works

pull/1/head
Ozbolt Menegatti 5 years ago
parent 14eb9d1df7
commit 5302d49396

@ -14,8 +14,12 @@ class ClickMessage(Message):
event.stopPropagation()
def msg(message_class, params):
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_instance = message_class(event, params)
update.schedule(message_instance)
message.on_event(event) #message_class(event, params)
update.schedule(message)
return callback

@ -20,9 +20,10 @@ class _ModalResetDelayed(Message):
def update_model(self, model):
model.modal_reset()
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)
window.setTimeout(lambda: msg(_ModalResetDelayed())(None), 100)

@ -56,15 +56,15 @@ def edit_sense_label(sense):
content.append(h("label", {}, [
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel, sense)}}, "+"))
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel(sense))}}, "+"))
return modal_template(content, "Sense", message.EditSenseLabel, sense)
def edit_example_translation(example):
etl_getter = lambda: example.copy().translations
content = generic_list_editor("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation, example))
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
content = generic_list_editor("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation(example)))
return modal_template(content, "Example Translations", message.EditExampleTranslation(example))
def add_sense(sense):

@ -18,7 +18,7 @@ class View:
self.vdom = new_vdom
def _view(self):
return h("div", {"on": { "click": msg(Reset) }}, [
return h("div", {"on": { "click": msg(Reset()) }}, [
View.view_entry(self.model.entry),
# h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"),
View.view_menu(self.model.menu_location, self.model.menu_shown, self.model.translation),
@ -33,9 +33,9 @@ class View:
h("div#entry-header", {}, [
h("span#headword", {}, entry.headword),
h("span#grammar", {}, entry.grammar),
h("button#comment.warning", {"on": {"click": msg(ShowCommentEdit)}}, entry.comment)]),
h("button#comment.warning", {"on": {"click": msg(ShowCommentEdit())}}, entry.comment)]),
h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(ShowSenseAdd)}}, "+")])
h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")])
@staticmethod
def view_sense(sense, senseNum):
@ -44,9 +44,9 @@ class View:
return h("div.elm-div", {}, [
h("div.sense-num", {}, str(senseNum + 1)),
h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit, sense) }}, [
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [
h("span.sense-label", {}, slabel) for slabel in sense.labels ]),
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit, sense) }}, sense.definition),
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit(sense)) }}, sense.definition),
h("div", {}, View.view_translations(sense.translations, sense)),
h("div", {}, examples)])])
@ -55,8 +55,8 @@ class View:
return h("div.example", {}, [
h("div.example-dot", {}, ""),
h("div.example-rest", {}, [
h("span.example-text", {"on": {"click": msg(ShowExampleEdit, example)} }, example.example),
h("div.example-translation-list", { "on": {"click": msg(ShowExampleTranslationEdit, example)} }, [
h("span.example-text", {"on": {"click": msg(ShowExampleEdit(example))} }, example.example),
h("div.example-translation-list", { "on": {"click": msg(ShowExampleTranslationEdit(example))} }, [
h("div.example-translation", {}, [
h("span.example-arrow", {}, ""),
h("span", {}, t)])
@ -68,7 +68,7 @@ class View:
for cluster in translations:
result.append(h("div.translation-div-cluster", {}, [View.view_one_translation(t) for t in cluster]))
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation, sense)}}, "+"))
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation(sense))}}, "+"))
return result
@staticmethod
@ -78,7 +78,7 @@ class View:
if translation.tags:
tags = h("div.translation-tags", {}, [
h("span", {"attr": {"title": key}}, value)
for key, value in translation.tags.items()])
for key, value in translation.tags])
elements.append(tags)
elements.append(h("span.translation-text", {}, translation.translation))
@ -88,7 +88,7 @@ class View:
explanation_class = ".translation-explanation" if translation.translation else ""
elements.append(h("span{}".format(explanation_class), {}, translation.explanation))
return h("div.translation-div", {"on": {"click": msg(ShowMenu, translation) }}, elements)
return h("div.translation-div", {"on": {"click": msg(ShowMenu(translation)) }}, elements)
@staticmethod
@ -102,10 +102,10 @@ class View:
style["visibility"] = "visible"
return h("span.popup-menu", { "style": style }, [
h("button.shyButton", { "on": {"click": msg(ShowEditTranslation, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveRight, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveLeft, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(BinTranslation, translation)}}, "🗑")])
h("button.shyButton", { "on": {"click": msg(ShowEditTranslation(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveRight(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")])
@staticmethod
@ -113,5 +113,5 @@ class View:
return h("div.modal", {}, [
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
h("label.overlay", {}, ""),
h("article", {"on": { "click": msg(NoReset) }}, modal())])
h("article", {"on": { "click": msg(NoReset()) }}, modal())])

Loading…
Cancel
Save