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.model = None
|
|
|
|
self.view = None
|
|
|
|
|
2020-03-30 18:25:17 +00:00
|
|
|
def update_model(self, msg):
|
|
|
|
# check if completely no action needed
|
|
|
|
if msg.no_action():
|
|
|
|
return
|
|
|
|
|
|
|
|
# by default, no need to redraw entry
|
2020-02-19 22:15:42 +00:00
|
|
|
entry_redraw = False
|
2020-03-30 18:25:17 +00:00
|
|
|
|
|
|
|
# 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()
|
2020-02-19 22:08:21 +00:00
|
|
|
|
|
|
|
# check if we need to reset the model
|
2020-03-30 18:25:17 +00:00
|
|
|
reset = msg.reset()
|
2020-01-02 12:15:04 +00:00
|
|
|
|
|
|
|
if reset:
|
|
|
|
self.model.pre_reset()
|
2019-11-20 21:25:31 +00:00
|
|
|
|
2020-03-30 18:25:17 +00:00
|
|
|
# actually run the update_model
|
|
|
|
msg.update_model(self.model)
|
|
|
|
msg.clear_args()
|
2020-01-02 12:15:04 +00:00
|
|
|
|
2020-03-30 18:25:17 +00:00
|
|
|
# post reset comes now
|
2020-01-02 12:15:04 +00:00
|
|
|
if reset:
|
|
|
|
self.model.post_reset()
|
2019-11-05 21:18:20 +00:00
|
|
|
|
2020-02-19 22:15:42 +00:00
|
|
|
self.view.view(self.model, entry_redraw)
|
2019-11-05 21:18:20 +00:00
|
|
|
|
|
|
|
def set_model(self, model):
|
|
|
|
self.model = model
|
|
|
|
|
|
|
|
def set_view(self, view):
|
|
|
|
self.view = view
|
|
|
|
|
|
|
|
|
|
|
|
update = Update()
|
|
|
|
|