from message.message import Message, ClickMessage from message.translation_edit import AddTranslation ,EditTranslation from model.sense import NewSense from view import modals class GenericShowModal(ClickMessage): def __init__(self, event, arg): super().__init__(event) self.arg = arg def update_model(self, model): model.modal_shown = True class ShowMenu(ClickMessage): def __init__(self, event, translation): super().__init__(event) location_x = event.currentTarget.offsetLeft location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight self.menu_location = (location_x, location_y) console.log(self.menu_location, event.currentTarget) self.translation = translation def update_model(self, model): model.menu_location = self.menu_location model.menu_shown = True model.translation = self.translation class ShowSenseLabelEdit(GenericShowModal): def update_model(self, model): super().update_model(model) model.sense = self.arg model.sense.make_copy() model.modal = lambda: modals.edit_sense_label(model.sense) class ShowSenseDefinitionEdit(GenericShowModal): def update_model(self, model): super().update_model(model) model.sense = self.arg model.modal = lambda: modals.edit_sense_definition(self.arg) class ShowSenseAdd(GenericShowModal): def update_model(self, model): super().update_model(model) model.modal = lambda: modals.add_sense(NewSense()) # I don't need GenericShowModal since there is only one comment class ShowCommentEdit(ClickMessage): def update_model(self, model): model.modal_shown = True model.modal = lambda: modals.edit_comment(model.entry.comment) class ShowExampleEdit(GenericShowModal): def update_model(self, model): super().update_model(model) model.modal = lambda: modals.edit_example(self.arg) class ShowExampleTranslationEdit(GenericShowModal): def update_model(self, model): super().update_model(model) example = self.arg example.make_copy() model.modal = lambda: modals.edit_example_translation(example) class ShowEditTranslation(GenericShowModal): def update_model(self, model): model.modal_shown = True # I need to get number of all clusters and cluster of self.arg translation = self.arg for sense in model.entry.senses: num_clusters = len(sense.translations) for cidx, cluster in enumerate(sense.translations): for t in cluster: if t == translation: # fount the one! model.modal = lambda: modals.edit_translation( translation, cidx, num_clusters, EditTranslation, (translation, cidx)) return console.log("Should not be here!") class ShowAddTranslation(GenericShowModal): def update_model(self, model): model.modal_shown = True chosen_sense = self.arg for sense in model.entry.senses: if sense == chosen_sense: model.modal = lambda: modals.edit_translation( sense, -1, len(sense.translations), AddTranslation, sense) return console.log("Should not be here!")