129 lines
4.6 KiB
Python
129 lines
4.6 KiB
Python
from message.message import Message
|
|
from message.translation_edit import AddTranslation, EditTranslation
|
|
from message.simple_messages import ClickMessage, KeyPlusClickMessage
|
|
|
|
from model import Example, Sense, Translation
|
|
from view import modals
|
|
|
|
|
|
class ShowSenseLabelEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.sense = self.get_arg(0, Sense)
|
|
|
|
model.sense.make_copy()
|
|
model.modal_set(lambda: modals.edit_sense_label(model.sense))
|
|
|
|
|
|
class ShowSenseDefinitionEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.sense = self.get_arg(0, Sense)
|
|
model.modal_set(lambda: modals.edit_sense_definition(model.sense))
|
|
|
|
|
|
class ShowCommentEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.modal_set(lambda: modals.edit_comment(model.entry.comment))
|
|
|
|
|
|
class ShowVariantsEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.entry.make_copy()
|
|
model.modal_set(lambda: modals.edit_variants(model.entry))
|
|
|
|
|
|
class ShowRelatedEntriesEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.entry.make_copy()
|
|
model.modal_set(lambda: modals.edit_related_entries(model.entry))
|
|
|
|
|
|
class ShowExampleEdit(KeyPlusClickMessage):
|
|
def update_model_default(self, model):
|
|
example = self.get_arg(0, Example)
|
|
example.make_copy()
|
|
|
|
# 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_set(lambda: modals.do_chosen_examples(chosen_examples, model.entry))
|
|
else:
|
|
model.modal_set(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 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)
|
|
|
|
def reset(self):
|
|
# special case, when choosing messages dont reset
|
|
return not (self.ctrl or self.shift)
|
|
|
|
|
|
class ShowEditTranslation(ClickMessage):
|
|
def update_model(self, model):
|
|
# 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_set(lambda: modals.edit_translation(
|
|
translation, (cidx, num_clusters), EditTranslation(translation, cidx)))
|
|
return
|
|
|
|
|
|
# if here, that his must be example translation
|
|
translation.make_copy()
|
|
model.modal_set(lambda: modals.edit_translation(
|
|
translation, None, EditTranslation(translation, -1)))
|
|
|
|
|
|
class ShowAddTranslation(ClickMessage):
|
|
def update_model(self, model):
|
|
chosen_sense_or_example = self.get_arg(0)
|
|
|
|
if isinstance(chosen_sense_or_example, Sense):
|
|
cluster = (-1, len(chosen_sense_or_example.translations))
|
|
else:
|
|
cluster = None
|
|
|
|
translation = Translation.new_empty()
|
|
translation.make_copy()
|
|
model.modal_set(lambda: modals.edit_translation(
|
|
translation,
|
|
cluster,
|
|
AddTranslation(translation, -1, chosen_sense_or_example)))
|
|
|
|
|
|
class ShowEntryLabelsEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.entry.make_copy()
|
|
model.modal_set(lambda: modals.edit_entry_labels(model.entry))
|
|
|