from model.entry import Entry from model.example import Example from browser import window from model.example_clusters import ExampleClusters class Model: def __init__(self): # main data stuff self.entry = None # report everything that happens! self.log = [] #runtime info self.menu_location = (0, 0) self.menu_target = None # modal handling self.modal = lambda: [] self.modal_shown = False # currently edited stuff self.translation = None self.sense = None # choosing and hiding examples self.chosen_examples = [] self.examples_shown = True # hiding cluster numbers self.clusters_shown = True 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 self.modal_reset() def post_reset(self): # the reset after updating the models self.chosen_examples = [] def modal_reset(self): self.modal = lambda: [] 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) def import_xml(self, xml_text): parser = __new__(DOMParser()) xmlDoc = parser.parseFromString(xml_text, "text/xml") self.entry = Entry(xmlDoc.querySelector("entry")) self.reset()