lexonomy_custom_editor/src/message/show_messages.py

98 lines
3.4 KiB
Python

from message.message import Message, ClickMessage
from message.translation_edit import AddTranslation, EditTranslation
from model import Example, Sense, Translation
from view import modals
class ShowMenu(ClickMessage):
def on_event(self, event):
location_x = event.currentTarget.offsetLeft
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
self.menu_location = (location_x, location_y)
super().on_event(event)
def update_model(self, model):
model.menu_location = self.menu_location
model.menu_shown = True
model.translation = self.get_arg(0, Translation)
class ShowSenseLabelEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
model.sense = self.get_arg(0, Sense)
model.sense.make_copy()
model.modal = lambda: modals.edit_sense_label(model.sense)
class ShowSenseDefinitionEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
model.sense = self.get_arg(0, Sense)
model.modal = lambda: modals.edit_sense_definition(model.sense)
class ShowSenseAdd(ClickMessage):
def update_model(self, model):
model.modal_shown = True
model.modal = lambda: modals.add_sense()
class ShowCommentEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
model.modal = lambda: modals.edit_comment(model.entry.comment)
class ShowExampleEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
example = self.get_arg(0, Example)
model.modal = lambda: modals.edit_example(example)
class ShowExampleTranslationEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
example = self.get_arg(0, Example)
example.make_copy()
model.modal = lambda: modals.edit_example_translation(example)
class ShowEditTranslation(ClickMessage):
def update_model(self, model):
model.modal_shown = True
# I need to get number of all clusters and cluster of self.arg
translation = self.get_arg(0, Translation)
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!
translation.make_copy()
model.modal = lambda: modals.edit_translation(
translation, cidx, num_clusters, EditTranslation(translation, cidx))
return
console.log("Should not be here!")
class ShowAddTranslation(ClickMessage):
def update_model(self, model):
model.modal_shown = True
chosen_sense = self.get_arg(0, Sense)
for sense in model.entry.senses:
if sense == chosen_sense:
translation = Translation.new_empty()
translation.make_copy()
model.modal = lambda: modals.edit_translation(
translation, -1, len(sense.translations), AddTranslation(translation, -1, sense))
return
console.log("Should not be here!")