rework of update mechanism and noaction message support for faster clicks on modal
This commit is contained in:
parent
02ea272aae
commit
1e84d965ff
|
@ -1,4 +1,4 @@
|
||||||
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress
|
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction
|
||||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||||
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
|
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
|
||||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
||||||
|
|
|
@ -40,6 +40,9 @@ class Message:
|
||||||
def clear_args(self):
|
def clear_args(self):
|
||||||
self._args = []
|
self._args = []
|
||||||
|
|
||||||
|
def no_action(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def msg(message_class, *params):
|
def msg(message_class, *params):
|
||||||
def callback(event):
|
def callback(event):
|
||||||
|
@ -49,5 +52,5 @@ def msg(message_class, *params):
|
||||||
return
|
return
|
||||||
|
|
||||||
message.on_event(event)
|
message.on_event(event)
|
||||||
update.schedule(message)
|
update.update_model(message)
|
||||||
return callback
|
return callback
|
||||||
|
|
|
@ -28,6 +28,11 @@ class NoReset(Reset):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class NoAction(NoReset):
|
||||||
|
def no_action(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class KeyboardPress(Message):
|
class KeyboardPress(Message):
|
||||||
def on_event(self, event):
|
def on_event(self, event):
|
||||||
self.add_arg(event.key)
|
self.add_arg(event.key)
|
||||||
|
|
|
@ -2,49 +2,40 @@ import lib.screenful as screenful
|
||||||
|
|
||||||
class Update:
|
class Update:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.message_queue = []
|
|
||||||
self.model = None
|
self.model = None
|
||||||
self.view = None
|
self.view = None
|
||||||
|
|
||||||
def update_model(self):
|
def update_model(self, msg):
|
||||||
|
# check if completely no action needed
|
||||||
|
if msg.no_action():
|
||||||
|
return
|
||||||
|
|
||||||
|
# by default, no need to redraw entry
|
||||||
entry_redraw = False
|
entry_redraw = False
|
||||||
reset = False
|
|
||||||
|
# check if we need to signal the data change
|
||||||
|
if msg.data_change():
|
||||||
|
screenful.changed()
|
||||||
|
entry_redraw = True
|
||||||
|
|
||||||
|
# redraw of view can happen even if no data changed
|
||||||
|
entry_redraw |= msg.entry_redraw()
|
||||||
|
|
||||||
# check if we need to reset the model
|
# check if we need to reset the model
|
||||||
for msg in self.message_queue:
|
reset = msg.reset()
|
||||||
if msg.reset():
|
|
||||||
reset = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
self.model.pre_reset()
|
self.model.pre_reset()
|
||||||
|
|
||||||
# check if we need to signal the data change
|
# actually run the update_model
|
||||||
# and for entry redraw
|
msg.update_model(self.model)
|
||||||
for msg in self.message_queue:
|
msg.clear_args()
|
||||||
if msg.data_change():
|
|
||||||
screenful.changed()
|
|
||||||
entry_redraw = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if msg.entry_redraw():
|
|
||||||
entry_redraw = True
|
|
||||||
|
|
||||||
# do update
|
|
||||||
for msg in self.message_queue:
|
|
||||||
msg.update_model(self.model)
|
|
||||||
msg.clear_args()
|
|
||||||
|
|
||||||
|
# post reset comes now
|
||||||
if reset:
|
if reset:
|
||||||
self.model.post_reset()
|
self.model.post_reset()
|
||||||
|
|
||||||
self.view.view(self.model, entry_redraw)
|
self.view.view(self.model, entry_redraw)
|
||||||
self.message_queue = []
|
|
||||||
|
|
||||||
def schedule(self, msg):
|
|
||||||
self.message_queue.append(msg)
|
|
||||||
# for now, directly clearing message queue
|
|
||||||
self.update_model()
|
|
||||||
|
|
||||||
def set_model(self, model):
|
def set_model(self, model):
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|
|
@ -95,5 +95,5 @@ class View:
|
||||||
return h("div.modal", {}, [
|
return h("div.modal", {}, [
|
||||||
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
|
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
|
||||||
h("label.overlay", {}, ""),
|
h("label.overlay", {}, ""),
|
||||||
h("article", {"on": { "click": msg(NoReset) }}, modal())])
|
h("article", {"on": { "click": msg(NoAction) }}, modal())])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user