lexonomy_custom_editor/src/model/model.py

66 lines
1.7 KiB
Python
Raw Normal View History

2019-11-05 21:18:20 +00:00
from model.entry import Entry
from model.example import Example
2019-11-11 22:04:45 +00:00
from browser import window
from model.example_clusters import ExampleClusters
2019-11-05 21:18:20 +00:00
class Model:
2020-01-24 00:47:27 +00:00
def __init__(self):
2019-11-11 22:04:45 +00:00
# main data stuff
2020-02-16 22:18:07 +00:00
self.entry = Entry()
2019-11-11 22:04:45 +00:00
# report everything that happens!
2019-11-05 21:18:20 +00:00
self.log = []
2019-11-11 22:04:45 +00:00
#runtime info
self.menu_location = (0, 0)
self.menu_target = None
# modal handling
self.modal = lambda: []
2019-11-11 22:04:45 +00:00
self.modal_shown = False
# currently edited stuff
self.translation = None
self.sense = None
2020-01-25 22:22:23 +00:00
# choosing and hiding examples
self.chosen_examples = []
2020-01-25 22:22:23 +00:00
self.examples_shown = True
2020-02-03 05:11:26 +00:00
# hiding cluster numbers
self.clusters_shown = True
2019-11-05 21:18:20 +00:00
2019-11-11 22:04:45 +00:00
def reset(self):
# do both resets at once
self.pre_reset()
self.post_reset()
def pre_reset(self):
# the reset before updating models
self.menu_target = None
2020-01-05 22:58:07 +00:00
self.modal_reset()
def post_reset(self):
# the reset after updating the models
self.chosen_examples = []
def modal_reset(self):
self.modal = lambda: []
2020-01-05 22:58:07 +00:00
self.modal_shown = False
def modal_set(self, modal):
self.modal = modal
self.modal_shown = True
def pre_view(self):
# this should go into "after data change" or something
ExampleClusters.rebuild_lists(self)
2019-11-05 21:18:20 +00:00
def import_xml(self, xml_text):
parser = __new__(DOMParser())
xmlDoc = parser.parseFromString(xml_text, "text/xml")
2020-02-16 22:18:07 +00:00
self.entry.import_xml(xmlDoc.querySelector("entry"))
2020-01-28 22:05:48 +00:00
self.reset()