2019-11-20 21:25:31 +00:00
|
|
|
import lib.screenful as screenful
|
|
|
|
|
2019-11-05 21:18:20 +00:00
|
|
|
class Update:
|
|
|
|
def __init__(self):
|
|
|
|
self.message_queue = []
|
|
|
|
self.model = None
|
|
|
|
self.view = None
|
|
|
|
|
|
|
|
def update_model(self):
|
2020-01-02 12:15:04 +00:00
|
|
|
# check if we need to reset the model
|
|
|
|
reset = False
|
2019-11-11 22:04:45 +00:00
|
|
|
for msg in self.message_queue:
|
|
|
|
if msg.reset():
|
2020-01-02 12:15:04 +00:00
|
|
|
reset = True
|
2019-11-11 22:04:45 +00:00
|
|
|
break
|
2020-01-02 12:15:04 +00:00
|
|
|
|
|
|
|
if reset:
|
|
|
|
self.model.pre_reset()
|
2019-11-20 21:25:31 +00:00
|
|
|
|
2020-01-02 12:15:04 +00:00
|
|
|
# check if we need to signal the data change
|
2019-11-20 21:25:31 +00:00
|
|
|
for msg in self.message_queue:
|
|
|
|
if msg.data_change():
|
|
|
|
screenful.changed()
|
2020-01-02 12:15:04 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
# do update
|
2019-11-05 21:18:20 +00:00
|
|
|
for msg in self.message_queue:
|
|
|
|
msg.update_model(self.model)
|
2020-01-02 12:15:04 +00:00
|
|
|
|
|
|
|
if reset:
|
|
|
|
self.model.post_reset()
|
2019-11-05 21:18:20 +00:00
|
|
|
|
|
|
|
self.message_queue = []
|
|
|
|
self.view.view(self.model)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def set_view(self, view):
|
|
|
|
self.view = view
|
|
|
|
|
|
|
|
|
|
|
|
update = Update()
|
|
|
|
|