rework of update mechanism and noaction message support for faster clicks on modal

This commit is contained in:
2020-03-30 20:27:22 +02:00
parent 02ea272aae
commit 1e84d965ff
5 changed files with 30 additions and 31 deletions
+19 -28
View File
@@ -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