Splitting reset into pre and post reset.
This commit is contained in:
parent
4bac269257
commit
00827e7b0b
|
@ -21,13 +21,26 @@ class Model:
|
||||||
self.translation = None
|
self.translation = None
|
||||||
self.sense = None
|
self.sense = None
|
||||||
|
|
||||||
|
# choosing examples
|
||||||
|
self.chosen_examples = []
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
self.modal_reset()
|
self.modal_reset()
|
||||||
|
|
||||||
def reset(self):
|
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.menu_target = None
|
||||||
self.modal_shown = False
|
self.modal_shown = False
|
||||||
|
|
||||||
|
def post_reset(self):
|
||||||
|
# the reset after updating the models
|
||||||
|
self.chosen_examples = []
|
||||||
|
|
||||||
def modal_reset(self):
|
def modal_reset(self):
|
||||||
self.modal = lambda: []
|
self.modal = lambda: []
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,29 @@ class Update:
|
||||||
self.view = None
|
self.view = None
|
||||||
|
|
||||||
def update_model(self):
|
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:
|
for msg in self.message_queue:
|
||||||
if msg.reset():
|
if msg.reset():
|
||||||
self.model.reset()
|
reset = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if reset:
|
||||||
|
self.model.pre_reset()
|
||||||
|
|
||||||
|
# check if we need to signal the data change
|
||||||
for msg in self.message_queue:
|
for msg in self.message_queue:
|
||||||
if msg.data_change():
|
if msg.data_change():
|
||||||
screenful.changed()
|
screenful.changed()
|
||||||
|
break
|
||||||
|
|
||||||
|
# do update
|
||||||
for msg in self.message_queue:
|
for msg in self.message_queue:
|
||||||
msg.update_model(self.model)
|
msg.update_model(self.model)
|
||||||
|
|
||||||
|
if reset:
|
||||||
|
self.model.post_reset()
|
||||||
|
|
||||||
self.message_queue = []
|
self.message_queue = []
|
||||||
self.view.view(self.model)
|
self.view.view(self.model)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user