You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.2 KiB
97 lines
3.2 KiB
from message.message import Message, ClickMessage
|
|
from message.translation_edit import AddTranslation ,EditTranslation
|
|
|
|
from model.sense import NewSense
|
|
import modals
|
|
|
|
|
|
class GenericShowModal(ClickMessage):
|
|
def __init__(self, event, arg):
|
|
super().__init__(event)
|
|
self.arg = arg
|
|
|
|
def update_model(self, model):
|
|
model.modal_shown = True
|
|
|
|
|
|
class ShowMenu(ClickMessage):
|
|
def __init__(self, event, translation):
|
|
super().__init__(event)
|
|
location_x = event.currentTarget.offsetLeft
|
|
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
|
|
self.menu_location = (location_x, location_y)
|
|
console.log(self.menu_location, event.currentTarget)
|
|
self.translation = translation
|
|
|
|
def update_model(self, model):
|
|
model.menu_location = self.menu_location
|
|
model.menu_shown = True
|
|
model.translation = self.translation
|
|
|
|
|
|
class ShowSenseLabelEdit(GenericShowModal):
|
|
def update_model(self, model):
|
|
super().update_model(model)
|
|
model.sense = self.arg
|
|
|
|
model.sense.make_copy()
|
|
model.modal = lambda: modals.edit_sense_label(model.sense)
|
|
|
|
|
|
class ShowSenseDefinitionEdit(GenericShowModal):
|
|
def update_model(self, model):
|
|
super().update_model(model)
|
|
model.sense = self.arg
|
|
model.modal = lambda: modals.edit_sense_definition(self.arg)
|
|
|
|
|
|
class ShowSenseAdd(GenericShowModal):
|
|
def update_model(self, model):
|
|
super().update_model(model)
|
|
model.modal = lambda: modals.add_sense(NewSense())
|
|
|
|
|
|
class ShowCommentEdit(ClickMessage):
|
|
def update_model(self, model):
|
|
model.modal_shown = True
|
|
model.modal = lambda: modals.edit_comment(model.entry.comment)
|
|
|
|
|
|
class ShowExampleEdit(GenericShowModal):
|
|
def update_model(self, model):
|
|
super().update_model(model)
|
|
model.modal = lambda: modals.edit_example(self.arg)
|
|
|
|
|
|
class ShowEditTranslation(GenericShowModal):
|
|
def update_model(self, model):
|
|
model.modal_shown = True
|
|
|
|
# I need to get number of all clusters and cluster of self.arg
|
|
translation = self.arg
|
|
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!
|
|
model.modal = lambda: modals.edit_translation(
|
|
translation, cidx, num_clusters, EditTranslation, (translation, cidx))
|
|
return
|
|
|
|
console.log("Should not be here!")
|
|
|
|
|
|
class ShowAddTranslation(GenericShowModal):
|
|
def update_model(self, model):
|
|
model.modal_shown = True
|
|
chosen_sense = self.arg
|
|
|
|
for sense in model.entry.senses:
|
|
if sense == chosen_sense:
|
|
model.modal = lambda: modals.edit_translation(
|
|
sense, -1, len(sense.translations), AddTranslation, sense)
|
|
return
|
|
|
|
console.log("Should not be here!")
|