WIP: on_event instead of constructor and constructor acceppting args
This commit is contained in:
@@ -3,12 +3,6 @@ from browser import document, window
|
||||
from model.translation import TAGS, NewTranslation
|
||||
|
||||
|
||||
class TranslationActionMessage(ClickMessage):
|
||||
def __init__(self, event, translation):
|
||||
super().__init__(event)
|
||||
self.translation = translation
|
||||
|
||||
|
||||
def get_translation_location(entry, translation):
|
||||
for si, sense in enumerate(entry.senses):
|
||||
for ci, cluster in enumerate(sense.translations):
|
||||
@@ -72,25 +66,28 @@ class EditTranslation(TranslationActionMessage):
|
||||
sense.translations.splice(cidx, 1)
|
||||
|
||||
|
||||
class MoveRight(TranslationActionMessage):
|
||||
class MoveRight(ClickMessage):
|
||||
def update_model(self, model):
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, self.translation)
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||
if idx != len(cluster) - 1:
|
||||
cluster[idx], cluster[idx + 1] = cluster[idx + 1], cluster[idx]
|
||||
model.translation = None
|
||||
|
||||
|
||||
class MoveLeft(TranslationActionMessage):
|
||||
class MoveLeft(ClickMessage):
|
||||
def update_model(self, model):
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, self.translation)
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||
if idx != 0 and len(cluster) > 1:
|
||||
cluster[idx], cluster[idx - 1] = cluster[idx - 1], cluster[idx]
|
||||
model.translation = None
|
||||
|
||||
|
||||
class BinTranslation(TranslationActionMessage):
|
||||
class BinTranslation(ClickMessage):
|
||||
def update_model(self, model):
|
||||
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, self.translation)
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, translation)
|
||||
if len(cluster) == 1:
|
||||
# remove empty cluster
|
||||
sense.translations.splice(cidx, 1)
|
||||
|
||||
Reference in New Issue
Block a user