2019-11-20 23:28:49 +00:00
|
|
|
from message.message import Message
|
2019-11-17 20:33:58 +00:00
|
|
|
from message.translation_edit import AddTranslation, EditTranslation
|
2020-01-14 21:16:47 +00:00
|
|
|
from message.simple_messages import ClickMessage, KeyPlusClickMessage
|
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
|
|
|
|
|
|
|
|
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.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()
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(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.sense = self.get_arg(0, Sense)
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(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):
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(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.entry.make_copy()
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(lambda: modals.edit_variants(model.entry))
|
2019-11-18 19:27:11 +00:00
|
|
|
|
|
|
|
|
2020-01-14 21:16:47 +00:00
|
|
|
class ShowExampleEdit(KeyPlusClickMessage):
|
|
|
|
def update_model_default(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
example = self.get_arg(0, Example)
|
2020-01-14 21:59:30 +00:00
|
|
|
example.make_copy()
|
2019-11-15 21:24:32 +00:00
|
|
|
|
2020-01-02 13:22:35 +00:00
|
|
|
# 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
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model.entry))
|
2020-01-02 13:22:35 +00:00
|
|
|
else:
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(lambda: modals.edit_example(example))
|
2020-01-02 13:22:35 +00:00
|
|
|
|
|
|
|
def update_model_ctrl(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
2020-01-04 13:36:39 +00:00
|
|
|
|
|
|
|
if example in model.chosen_examples:
|
|
|
|
model.chosen_examples.remove(example)
|
|
|
|
else:
|
|
|
|
model.chosen_examples.append(example)
|
2020-01-14 21:16:47 +00:00
|
|
|
|
|
|
|
def update_model_shift(self, model):
|
|
|
|
first_example = self.get_arg(0, Example)
|
|
|
|
last_example = model.chosen_examples[model.chosen_examples.length - 1]
|
|
|
|
adding = False
|
|
|
|
|
|
|
|
# logic to add all senses between these two
|
|
|
|
for sense in model.entry.senses:
|
|
|
|
for example in sense.examples:
|
|
|
|
match = example in (first_example, last_example)
|
|
|
|
|
|
|
|
if adding and match:
|
|
|
|
adding = False
|
|
|
|
elif match:
|
|
|
|
adding = True
|
|
|
|
elif not adding:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if example not in model.chosen_examples:
|
|
|
|
model.chosen_examples.append(example)
|
2019-11-15 21:24:32 +00:00
|
|
|
|
2020-01-02 13:22:35 +00:00
|
|
|
def reset(self):
|
|
|
|
# special case, when choosing messages dont reset
|
2020-01-14 21:16:47 +00:00
|
|
|
return not (self.ctrl or self.shift)
|
2019-11-16 13:18:37 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowEditTranslation(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
# 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()
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(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!")
|
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class ShowAddTranslation(ClickMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
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()
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(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.entry.make_copy()
|
2020-01-05 22:58:07 +00:00
|
|
|
model.modal_set(lambda: modals.edit_entry_labels(model.entry))
|
2020-01-14 21:59:30 +00:00
|
|
|
|