Entry now redrawn only on data change
This commit is contained in:
parent
f822aed45a
commit
c0ca84a901
|
@ -36,6 +36,9 @@ class KeyboardPress(Message):
|
||||||
key = self.get_arg(0, str)
|
key = self.get_arg(0, str)
|
||||||
return key == "Escape"
|
return key == "Escape"
|
||||||
|
|
||||||
|
def data_change(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
key = self.get_arg(0, str)
|
key = self.get_arg(0, str)
|
||||||
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
from model.example.example import Example
|
from model.example.example import Example
|
||||||
|
from model.example.component_lexeme import ComponentLexeme
|
||||||
|
|
|
@ -7,8 +7,10 @@ class Update:
|
||||||
self.view = None
|
self.view = None
|
||||||
|
|
||||||
def update_model(self):
|
def update_model(self):
|
||||||
# check if we need to reset the model
|
data_change = False
|
||||||
reset = False
|
reset = False
|
||||||
|
|
||||||
|
# check if we need to reset the model
|
||||||
for msg in self.message_queue:
|
for msg in self.message_queue:
|
||||||
if msg.reset():
|
if msg.reset():
|
||||||
reset = True
|
reset = True
|
||||||
|
@ -21,6 +23,7 @@ class Update:
|
||||||
for msg in self.message_queue:
|
for msg in self.message_queue:
|
||||||
if msg.data_change():
|
if msg.data_change():
|
||||||
screenful.changed()
|
screenful.changed()
|
||||||
|
data_change = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# do update
|
# do update
|
||||||
|
@ -31,8 +34,8 @@ class Update:
|
||||||
if reset:
|
if reset:
|
||||||
self.model.post_reset()
|
self.model.post_reset()
|
||||||
|
|
||||||
|
self.view.view(self.model, data_change)
|
||||||
self.message_queue = []
|
self.message_queue = []
|
||||||
self.view.view(self.model)
|
|
||||||
|
|
||||||
def schedule(self, msg):
|
def schedule(self, msg):
|
||||||
self.message_queue.append(msg)
|
self.message_queue.append(msg)
|
||||||
|
|
|
@ -64,13 +64,6 @@ def edit_example(example, sense):
|
||||||
h("div.three-fifth", {}, middle),
|
h("div.three-fifth", {}, middle),
|
||||||
h("div.one-fifth", {}, buttons_right(idx))]))
|
h("div.one-fifth", {}, buttons_right(idx))]))
|
||||||
|
|
||||||
cluster = example.get_cluster()
|
|
||||||
if cluster is not None:
|
|
||||||
divs.append(h("hr", {}, []))
|
|
||||||
divs.append(h("div.flex.five.example-component", {}, [
|
|
||||||
h("div.one-fifth", {}, "Cluster"),
|
|
||||||
h("div.four-fifth", {}, show_toggle_cluster_buttons(sense, example))]))
|
|
||||||
|
|
||||||
return modal_template(divs, "Edit Example", (message.EditExampleText, example_original))
|
return modal_template(divs, "Edit Example", (message.EditExampleText, example_original))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,27 +11,30 @@ from export import export_to_xml
|
||||||
class View:
|
class View:
|
||||||
def __init__(self, container):
|
def __init__(self, container):
|
||||||
self.vdom = h('div', {}, "Loading...")
|
self.vdom = h('div', {}, "Loading...")
|
||||||
|
self.entry_vdom = None
|
||||||
self.model = None
|
self.model = None
|
||||||
patch(container, self.vdom)
|
patch(container, self.vdom)
|
||||||
|
|
||||||
# this does not work on parent div, so attaching to document here
|
# this does not work on parent div, so attaching to document here
|
||||||
document.addEventListener("keyup", msg(KeyboardPress))
|
document.addEventListener("keyup", msg(KeyboardPress))
|
||||||
|
|
||||||
def view(self, model):
|
def view(self, model, data_change):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.model.pre_view()
|
|
||||||
|
|
||||||
|
if data_change or self.entry_vdom is None:
|
||||||
|
self.model.pre_view()
|
||||||
|
self.entry_vdom = self.model.entry.view(self.model)
|
||||||
|
|
||||||
new_vdom = self._view()
|
new_vdom = self._view()
|
||||||
patch(self.vdom, new_vdom)
|
patch(self.vdom, new_vdom)
|
||||||
self.vdom = new_vdom
|
self.vdom = new_vdom
|
||||||
|
|
||||||
def _view(self):
|
def _view(self):
|
||||||
return h("div", {"on": { "click": msg(Reset) }}, [
|
return h("div", {"on": { "click": msg(Reset) }}, [
|
||||||
self.model.entry.view(self.model),
|
self.entry_vdom,
|
||||||
h("button.blk", {"on": { "click": lambda _: check_export(self.model) } }, "CHK"),
|
# h("button.blk", {"on": { "click": lambda _: check_export(self.model) } }, "CHK"),
|
||||||
View.view_menu(self.model.menu_location, self.model.menu_target, self.model.entry),
|
View.view_menu(self.model.menu_location, self.model.menu_target, self.model.entry),
|
||||||
View.view_modal(self.model.modal_shown, self.model.modal)])
|
View.view_modal(self.model.modal_shown, self.model.modal)])
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_toggle_buttons(model):
|
def view_toggle_buttons(model):
|
||||||
|
@ -41,38 +44,15 @@ class View:
|
||||||
return [h("span.button.toggle", {"on": {"click": msg(ToggleExamples)}}, txt_examples),
|
return [h("span.button.toggle", {"on": {"click": msg(ToggleExamples)}}, txt_examples),
|
||||||
h("span.button.toggle", {"on": {"click": msg(ToggleClusters)}}, txt_clusters)]
|
h("span.button.toggle", {"on": {"click": msg(ToggleClusters)}}, txt_clusters)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_translations(translations, parent, model):
|
def view_translations(translations, parent, model):
|
||||||
result = []
|
result = []
|
||||||
for cluster in translations:
|
for cluster in translations:
|
||||||
result.append(h("div.translation-div-cluster", {}, [View.view_one_translation(t, model) for t in cluster]))
|
result.append(h("div.translation-div-cluster", {}, [t.view(model) for t in cluster]))
|
||||||
|
|
||||||
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation, parent)}}, "+"))
|
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation, parent)}}, "+"))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def view_one_translation(translation, model):
|
|
||||||
elements = []
|
|
||||||
|
|
||||||
if translation.tags:
|
|
||||||
tags = h("div.translation-tags", {}, [
|
|
||||||
h("span", {"attr": {"title": key}}, clean_label(value))
|
|
||||||
for key, value in translation.tags])
|
|
||||||
elements.append(tags)
|
|
||||||
|
|
||||||
elements.append(h("span.translation-text", {}, translation.translation))
|
|
||||||
if translation.source:
|
|
||||||
elements.append(h("span.translation-source", {}, translation.source))
|
|
||||||
|
|
||||||
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(ShowTranslationMenu, translation) }}, elements)
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_menu(location, menu_target, entry):
|
def view_menu(location, menu_target, entry):
|
||||||
style = {
|
style = {
|
||||||
|
@ -110,7 +90,6 @@ class View:
|
||||||
else:
|
else:
|
||||||
console.log("Should not be heree!!")
|
console.log("Should not be heree!!")
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_modal(modal_shown, modal):
|
def view_modal(modal_shown, modal):
|
||||||
return h("div.modal", {}, [
|
return h("div.modal", {}, [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user