lexonomy_custom_editor/src/update.py

49 lines
1.1 KiB
Python
Raw Normal View History

import lib.screenful as screenful
2019-11-05 21:18:20 +00:00
class Update:
def __init__(self):
self.model = None
self.view = None
def update_model(self, msg):
# check if completely no action needed
if msg.no_action():
return
2020-07-16 10:22:54 +00:00
# by default, no need to redraw entry
entry_redraw = False
2020-07-16 10:22:54 +00:00
# check if we need to signal the data change
if msg.data_change():
screenful.changed()
entry_redraw = True
2020-07-16 10:22:54 +00:00
# redraw of view can happen even if no data changed
entry_redraw |= msg.entry_redraw()
2020-07-16 10:22:54 +00:00
2020-02-19 22:08:21 +00:00
# check if we need to reset the model
reset = msg.reset()
2020-07-16 10:22:54 +00:00
if reset:
self.model.pre_reset()
2020-07-16 10:22:54 +00:00
# actually run the update_model
msg.update_model(self.model)
msg.clear_args()
2020-07-16 10:22:54 +00:00
# post reset comes now
if reset:
self.model.post_reset()
2019-11-05 21:18:20 +00:00
self.view.view(self.model, entry_redraw)
2020-07-16 10:22:54 +00:00
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()