New editor written in Python dialect
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

2 years ago
2 years ago
2 years ago
  1. import lib.screenful as screenful
  2. class Update:
  3. def __init__(self):
  4. self.model = None
  5. self.view = None
  6. def update_model(self, msg):
  7. # check if completely no action needed
  8. if msg.no_action():
  9. return
  10. # by default, no need to redraw entry
  11. entry_redraw = False
  12. # check if we need to signal the data change
  13. if msg.data_change():
  14. screenful.changed()
  15. entry_redraw = True
  16. # redraw of view can happen even if no data changed
  17. entry_redraw |= msg.entry_redraw()
  18. # check if we need to reset the model
  19. reset = msg.reset()
  20. if reset:
  21. self.model.pre_reset()
  22. # actually run the update_model
  23. msg.update_model(self.model)
  24. msg.clear_args()
  25. # post reset comes now
  26. if reset:
  27. self.model.post_reset()
  28. self.view.view(self.model, entry_redraw)
  29. def set_model(self, model):
  30. self.model = model
  31. def set_view(self, view):
  32. self.view = view
  33. update = Update()