Splitting reset into pre and post reset.

This commit is contained in:
Ozbolt Menegatti 2020-01-02 13:15:04 +01:00
parent 4bac269257
commit 00827e7b0b
2 changed files with 26 additions and 3 deletions

View File

@ -21,13 +21,26 @@ class Model:
self.translation = None
self.sense = None
# choosing examples
self.chosen_examples = []
self.reset()
self.modal_reset()
def reset(self):
# do both resets at once
self.pre_reset()
self.post_reset()
def pre_reset(self):
# the reset before updating models
self.menu_target = None
self.modal_shown = False
def post_reset(self):
# the reset after updating the models
self.chosen_examples = []
def modal_reset(self):
self.modal = lambda: []

View File

@ -7,19 +7,29 @@ class Update:
self.view = None
def update_model(self):
# any update resets menu_location, except if it explicitly defines it
# check if we need to reset the model
reset = False
for msg in self.message_queue:
if msg.reset():
self.model.reset()
reset = True
break
if reset:
self.model.pre_reset()
# check if we need to signal the data change
for msg in self.message_queue:
if msg.data_change():
screenful.changed()
break
# do update
for msg in self.message_queue:
msg.update_model(self.model)
if reset:
self.model.post_reset()
self.message_queue = []
self.view.view(self.model)