lexonomy_custom_editor/src/update.py

49 lines
1.1 KiB
Python

import lib.screenful as screenful
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
# by default, no need to redraw entry
entry_redraw = False
# 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()
# check if we need to reset the model
reset = msg.reset()
if reset:
self.model.pre_reset()
# actually run the update_model
msg.update_model(self.model)
msg.clear_args()
# post reset comes now
if reset:
self.model.post_reset()
self.view.view(self.model, entry_redraw)
def set_model(self, model):
self.model = model
def set_view(self, view):
self.view = view
update = Update()