2019-11-11 22:04:45 +00:00
|
|
|
from message.message import Message, ClickMessage
|
2019-11-17 20:33:58 +00:00
|
|
|
from message.translation_edit import AddTranslation, EditTranslation
|
2019-11-11 22:04:45 +00:00
|
|
|
|
2019-11-17 20:33:58 +00:00
|
|
|
from model import Example, Sense, Translation
|
2019-11-16 13:41:29 +00:00
|
|
|
from view import modals
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ShowMenu(ClickMessage):
|
2019-11-17 20:30:30 +00:00
|
|
|
def on_event(self, event):
|
2019-11-15 21:24:32 +00:00
|
|
|
location_x = event.currentTarget.offsetLeft
|
|
|
|
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
|
|
|
|
self.menu_location = (location_x, location_y)
|
2019-11-17 20:30:30 +00:00
|
|
|
super().on_event(event)
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
def update_model(self, model):
|
|
|
|
model.menu_location = self.menu_location
|
2019-11-17 20:30:30 +00:00
|
|
|
model.translation = self.get_arg(0, Translation)
|
2019-11-20 22:24:16 +00:00
|
|
|
model.menu_target = model.translation
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowSenseLabelEdit(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
model.modal_shown = True
|
|
|
|
model.sense = self.get_arg(0, Sense)
|
2019-11-11 23:34:52 +00:00
|
|
|
|
2019-11-13 22:20:34 +00:00
|
|
|
model.sense.make_copy()
|
2019-11-11 23:34:52 +00:00
|
|
|
model.modal = lambda: modals.edit_sense_label(model.sense)
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowSenseDefinitionEdit(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
model.modal_shown = True
|
|
|
|
model.sense = self.get_arg(0, Sense)
|
|
|
|
model.modal = lambda: modals.edit_sense_definition(model.sense)
|
2019-11-15 21:24:32 +00:00
|
|
|
|
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
class ShowCommentEdit(ClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
model.modal_shown = True
|
2019-11-11 23:34:52 +00:00
|
|
|
model.modal = lambda: modals.edit_comment(model.entry.comment)
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2019-11-18 19:27:11 +00:00
|
|
|
class ShowVariantsEdit(ClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
model.modal_shown = True
|
|
|
|
model.entry.make_copy()
|
|
|
|
model.modal = lambda: modals.edit_variants(model.entry)
|
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowExampleEdit(ClickMessage):
|
2019-11-15 21:24:32 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
model.modal_shown = True
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
model.modal = lambda: modals.edit_example(example)
|
2019-11-15 21:24:32 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowExampleTranslationEdit(ClickMessage):
|
2019-11-16 13:18:37 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
model.modal_shown = True
|
|
|
|
example = self.get_arg(0, Example)
|
2019-11-16 13:18:37 +00:00
|
|
|
example.make_copy()
|
|
|
|
model.modal = lambda: modals.edit_example_translation(example)
|
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowEditTranslation(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
model.modal_shown = True
|
|
|
|
|
|
|
|
# I need to get number of all clusters and cluster of self.arg
|
2019-11-17 20:30:30 +00:00
|
|
|
translation = self.get_arg(0, Translation)
|
2019-11-11 22:04:45 +00:00
|
|
|
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:
|
2019-11-17 20:33:58 +00:00
|
|
|
# fount the one!
|
|
|
|
translation.make_copy()
|
2019-11-11 23:34:52 +00:00
|
|
|
model.modal = lambda: modals.edit_translation(
|
2019-11-17 20:33:58 +00:00
|
|
|
translation, cidx, num_clusters, EditTranslation(translation, cidx))
|
2019-11-11 22:04:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
console.log("Should not be here!")
|
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowAddTranslation(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
model.modal_shown = True
|
2019-11-17 20:30:30 +00:00
|
|
|
chosen_sense = self.get_arg(0, Sense)
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
for sense in model.entry.senses:
|
|
|
|
if sense == chosen_sense:
|
2019-11-17 20:23:28 +00:00
|
|
|
translation = Translation.new_empty()
|
|
|
|
translation.make_copy()
|
2019-11-11 23:34:52 +00:00
|
|
|
model.modal = lambda: modals.edit_translation(
|
2019-11-17 20:23:28 +00:00
|
|
|
translation, -1, len(sense.translations), AddTranslation(translation, -1, sense))
|
2019-11-11 22:04:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
console.log("Should not be here!")
|
2019-11-18 19:57:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ShowEntryLabelsEdit(ClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
model.modal_shown = True
|
|
|
|
model.entry.make_copy()
|
|
|
|
model.modal = lambda: modals.edit_entry_labels(model.entry)
|