lexonomy_custom_editor/src/message/show_messages.py

111 lines
3.9 KiB
Python
Raw Normal View History

from message.message import Message
from message.translation_edit import AddTranslation, EditTranslation
from message.simple_messages import ClickMessage, CtrlClickMessage
2019-11-11 22:04:45 +00:00
from model import Example, Sense, Translation
from view import modals
2019-11-11 22:04:45 +00:00
class ShowSenseLabelEdit(ClickMessage):
2019-11-11 22:04:45 +00:00
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)
2019-11-11 22:04:45 +00:00
class ShowSenseDefinitionEdit(ClickMessage):
2019-11-11 22:04:45 +00:00
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)
2019-11-11 22:04:45 +00:00
class ShowCommentEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
model.modal = lambda: modals.edit_comment(model.entry.comment)
2019-11-11 22:04:45 +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)
class ShowExampleEdit(CtrlClickMessage):
def update_model_noctrl(self, model):
model.modal_shown = True
example = self.get_arg(0, Example)
# if some are chosen, then show modal for choosing senses
if len(model.chosen_examples) > 0 and example in model.chosen_examples:
chosen_examples = model.chosen_examples
model.modal = lambda: modals.do_chosen_examples(chosen_examples, model.entry)
else:
model.modal = lambda: modals.edit_example(example)
def update_model_ctrl(self, model):
example = self.get_arg(0, Example)
if example in model.chosen_examples:
model.chosen_examples.remove(example)
else:
model.chosen_examples.append(example)
def reset(self):
# special case, when choosing messages dont reset
return not self.ctrl
class ShowExampleTranslationEdit(ClickMessage):
2019-11-16 13:18:37 +00:00
def update_model(self, model):
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)
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
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:
# fount the one!
translation.make_copy()
model.modal = lambda: modals.edit_translation(
translation, cidx, num_clusters, EditTranslation(translation, cidx))
2019-11-11 22:04:45 +00:00
return
console.log("Should not be here!")
class ShowAddTranslation(ClickMessage):
2019-11-11 22:04:45 +00:00
def update_model(self, model):
model.modal_shown = True
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:
translation = Translation.new_empty()
translation.make_copy()
model.modal = lambda: modals.edit_translation(
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)