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.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
|
||||
|
|
|
@ -39,6 +39,9 @@ class Message:
|
|||
|
||||
def clear_args(self):
|
||||
self._args = []
|
||||
|
||||
def no_action(self):
|
||||
return False
|
||||
|
||||
|
||||
def msg(message_class, *params):
|
||||
|
@ -49,5 +52,5 @@ def msg(message_class, *params):
|
|||
return
|
||||
|
||||
message.on_event(event)
|
||||
update.schedule(message)
|
||||
update.update_model(message)
|
||||
return callback
|
||||
|
|
|
@ -28,6 +28,11 @@ class NoReset(Reset):
|
|||
return False
|
||||
|
||||
|
||||
class NoAction(NoReset):
|
||||
def no_action(self):
|
||||
return True
|
||||
|
||||
|
||||
class KeyboardPress(Message):
|
||||
def on_event(self, event):
|
||||
self.add_arg(event.key)
|
||||
|
|
|
@ -2,49 +2,40 @@ import lib.screenful as screenful
|
|||
|
||||
class Update:
|
||||
def __init__(self):
|
||||
self.message_queue = []
|
||||
self.model = 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
|
||||
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
|
||||
for msg in self.message_queue:
|
||||
if msg.reset():
|
||||
reset = True
|
||||
break
|
||||
reset = msg.reset()
|
||||
|
||||
if reset:
|
||||
self.model.pre_reset()
|
||||
|
||||
# check if we need to signal the data change
|
||||
# and for entry redraw
|
||||
for msg in self.message_queue:
|
||||
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()
|
||||
# actually run the update_model
|
||||
msg.update_model(self.model)
|
||||
msg.clear_args()
|
||||
|
||||
# post reset comes now
|
||||
if reset:
|
||||
self.model.post_reset()
|
||||
|
||||
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):
|
||||
self.model = model
|
||||
|
|
|
@ -95,5 +95,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(NoAction) }}, modal())])
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user