Finished refactoring menu showing, now also sense editing works!
This commit is contained in:
parent
38d1139d2d
commit
f50d812efb
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
.sense-num {
|
.sense-num {
|
||||||
float: left;
|
float: left;
|
||||||
|
._hoverable();
|
||||||
}
|
}
|
||||||
|
|
||||||
.sense {
|
.sense {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from message.simple_messages import NoReset, Reset, ModalNotOkClose
|
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage
|
||||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||||
from message.show_messages import ShowMenu, ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
|
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
|
||||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
|
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
|
||||||
|
from message.show_menu import ShowTranslationMenu, ShowSenseMenu
|
||||||
|
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
||||||
|
|
||||||
from message.message import msg
|
from message.message import msg
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,6 @@ class Message:
|
||||||
def reset(self):
|
def reset(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ClickMessage(Message):
|
|
||||||
def on_event(self, event):
|
|
||||||
event.stopPropagation()
|
|
||||||
|
|
||||||
def data_change(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def msg(message, params):
|
def msg(message, params):
|
||||||
if not issubclass(type(message), Message):
|
if not issubclass(type(message), Message):
|
||||||
|
|
40
src/message/sense_edit.py
Normal file
40
src/message/sense_edit.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
from message.simple_messages import DataChgClickMessage
|
||||||
|
from model import Sense
|
||||||
|
|
||||||
|
|
||||||
|
def _get_sense_idx(sense, model):
|
||||||
|
for idx, s in enumerate(model.entry.senses):
|
||||||
|
if s == sense:
|
||||||
|
return idx
|
||||||
|
|
||||||
|
class SenseMoveUp(DataChgClickMessage):
|
||||||
|
def update_model(self, model):
|
||||||
|
sense = self.get_arg(0, Sense)
|
||||||
|
sidx = _get_sense_idx(sense, model)
|
||||||
|
|
||||||
|
assert(sidx >= 0)
|
||||||
|
if sidx == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
model.entry.senses[sidx], model.entry.senses[sidx - 1] = model.entry.senses[sidx - 1], model.entry.senses[sidx]
|
||||||
|
|
||||||
|
|
||||||
|
class SenseMoveDown(DataChgClickMessage):
|
||||||
|
def update_model(self, model):
|
||||||
|
sense = self.get_arg(0, Sense)
|
||||||
|
sidx = _get_sense_idx(sense, model)
|
||||||
|
|
||||||
|
assert(sidx >= 0)
|
||||||
|
if sidx == len(model.senses) - 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
model.entry.senses[sidx], model.entry.senses[sidx + 1] = model.entry.senses[sidx + 1], model.entry.senses[sidx]
|
||||||
|
|
||||||
|
|
||||||
|
class SenseBin(DataChgClickMessage):
|
||||||
|
def update_model(self, model):
|
||||||
|
sense = self.get_arg(0, Sense)
|
||||||
|
sidx = _get_sense_idx(sense, model)
|
||||||
|
|
||||||
|
assert(sidx >= 0)
|
||||||
|
model.entry.senses.splice(sidx, 1)
|
24
src/message/show_menu.py
Normal file
24
src/message/show_menu.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from model import Translation, Sense
|
||||||
|
from message.simple_messages import ClickMessage
|
||||||
|
|
||||||
|
|
||||||
|
class ShowMenu(ClickMessage):
|
||||||
|
def on_event(self, event):
|
||||||
|
location_x = event.currentTarget.offsetLeft
|
||||||
|
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
|
||||||
|
self.menu_location = (location_x, location_y)
|
||||||
|
super().on_event(event)
|
||||||
|
|
||||||
|
|
||||||
|
class ShowTranslationMenu(ShowMenu):
|
||||||
|
def update_model(self, model):
|
||||||
|
model.menu_location = self.menu_location
|
||||||
|
model.translation = self.get_arg(0, Translation)
|
||||||
|
model.menu_target = model.translation
|
||||||
|
|
||||||
|
|
||||||
|
class ShowSenseMenu(ShowMenu):
|
||||||
|
def update_model(self, model):
|
||||||
|
model.menu_location = self.menu_location
|
||||||
|
sense = self.get_arg(0, Sense)
|
||||||
|
model.menu_target = sense
|
|
@ -1,21 +1,9 @@
|
||||||
from message.message import Message, ClickMessage
|
from message.message import Message
|
||||||
from message.translation_edit import AddTranslation, EditTranslation
|
from message.translation_edit import AddTranslation, EditTranslation
|
||||||
|
from message.simple_messages import ClickMessage
|
||||||
|
|
||||||
from model import Example, Sense, Translation
|
from model import Example, Sense, Translation
|
||||||
from view import modals
|
from view import modals
|
||||||
|
|
||||||
|
|
||||||
class ShowMenu(ClickMessage):
|
|
||||||
def on_event(self, event):
|
|
||||||
location_x = event.currentTarget.offsetLeft
|
|
||||||
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
|
|
||||||
self.menu_location = (location_x, location_y)
|
|
||||||
super().on_event(event)
|
|
||||||
|
|
||||||
def update_model(self, model):
|
|
||||||
model.menu_location = self.menu_location
|
|
||||||
model.translation = self.get_arg(0, Translation)
|
|
||||||
model.menu_target = model.translation
|
|
||||||
|
|
||||||
|
|
||||||
class ShowSenseLabelEdit(ClickMessage):
|
class ShowSenseLabelEdit(ClickMessage):
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
from message.message import Message, ClickMessage, msg
|
|
||||||
from browser import window
|
from browser import window
|
||||||
|
from message.message import Message, msg
|
||||||
|
|
||||||
|
|
||||||
|
# click messages stuff
|
||||||
|
|
||||||
|
|
||||||
|
class DataChgClickMessage(Message):
|
||||||
|
def on_event(self, event):
|
||||||
|
event.stopPropagation()
|
||||||
|
|
||||||
|
|
||||||
|
class ClickMessage(DataChgClickMessage):
|
||||||
|
def data_change(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# reset messages stuff
|
||||||
|
|
||||||
|
|
||||||
class Reset(ClickMessage):
|
class Reset(ClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
pass
|
pass
|
||||||
|
@ -11,7 +27,7 @@ class NoReset(Reset):
|
||||||
def reset(self):
|
def reset(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# a "hack" message for reseting modals #
|
# a "hack" message for reseting modals #
|
||||||
# everytime a modal closes, run 100ms later model.modal = []
|
# everytime a modal closes, run 100ms later model.modal = []
|
||||||
# this is done to achieve nice close animation
|
# this is done to achieve nice close animation
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from message.message import Message, ClickMessage
|
from message.message import Message
|
||||||
|
from message.simple_messages import DataChgClickMessage
|
||||||
import message.common_accessors as common_accessors
|
import message.common_accessors as common_accessors
|
||||||
from browser import document, window
|
from browser import document, window
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
|
@ -13,12 +14,7 @@ def get_translation_location(entry, translation):
|
||||||
return (si, ci, ti), (sense, cluster)
|
return (si, ci, ti), (sense, cluster)
|
||||||
|
|
||||||
|
|
||||||
class TranslationEditMessage(ClickMessage):
|
class EditTranslation(DataChgClickMessage):
|
||||||
def data_change(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class EditTranslation(TranslationEditMessage):
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
self.translation = self.get_arg(0, Translation)
|
self.translation = self.get_arg(0, Translation)
|
||||||
self.old_cluster_idx = self.get_arg(1, int)
|
self.old_cluster_idx = self.get_arg(1, int)
|
||||||
|
@ -65,7 +61,7 @@ class EditTranslation(TranslationEditMessage):
|
||||||
sense.translations.splice(cidx, 1)
|
sense.translations.splice(cidx, 1)
|
||||||
|
|
||||||
|
|
||||||
class MoveRight(TranslationEditMessage):
|
class MoveRight(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
translation = self.get_arg(0, Translation)
|
translation = self.get_arg(0, Translation)
|
||||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||||
|
@ -74,7 +70,7 @@ class MoveRight(TranslationEditMessage):
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class MoveLeft(TranslationEditMessage):
|
class MoveLeft(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
translation = self.get_arg(0, Translation)
|
translation = self.get_arg(0, Translation)
|
||||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||||
|
@ -83,7 +79,7 @@ class MoveLeft(TranslationEditMessage):
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class BinTranslation(TranslationEditMessage):
|
class BinTranslation(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
translation = self.get_arg(0, Translation)
|
translation = self.get_arg(0, Translation)
|
||||||
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, translation)
|
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, translation)
|
||||||
|
@ -95,7 +91,7 @@ class BinTranslation(TranslationEditMessage):
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class AddTranslation(TranslationEditMessage):
|
class AddTranslation(DataChgClickMessage):
|
||||||
def handle_cluster_change(self, new_cluster_idx, _):
|
def handle_cluster_change(self, new_cluster_idx, _):
|
||||||
# we need to cheat here
|
# we need to cheat here
|
||||||
# sense was actually given in constructor in third place
|
# sense was actually given in constructor in third place
|
||||||
|
|
|
@ -79,7 +79,7 @@ class View:
|
||||||
examples = [View.view_example(example) for example in sense.examples]
|
examples = [View.view_example(example) for example in sense.examples]
|
||||||
|
|
||||||
return h("div.elm-div", {}, [
|
return h("div.elm-div", {}, [
|
||||||
h("div.sense-num", {}, str(senseNum + 1)),
|
h("div.sense-num", {"on": {"click": msg(ShowSenseMenu(sense))}}, str(senseNum + 1)),
|
||||||
h("div.sense", {}, [
|
h("div.sense", {}, [
|
||||||
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [
|
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [
|
||||||
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in sense.labels ]),
|
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in sense.labels ]),
|
||||||
|
@ -125,7 +125,7 @@ class View:
|
||||||
explanation_class = ".translation-explanation" if translation.translation else ""
|
explanation_class = ".translation-explanation" if translation.translation else ""
|
||||||
elements.append(h("span{}".format(explanation_class), {}, translation.explanation))
|
elements.append(h("span{}".format(explanation_class), {}, translation.explanation))
|
||||||
|
|
||||||
return h("div.translation-div", {"on": {"click": msg(ShowMenu(translation)) }}, elements)
|
return h("div.translation-div", {"on": {"click": msg(ShowTranslationMenu(translation)) }}, elements)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -135,9 +135,6 @@ class View:
|
||||||
"top": "{}px".format(location[1])
|
"top": "{}px".format(location[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(menu_target)
|
|
||||||
console.log(type(menu_target))
|
|
||||||
|
|
||||||
if menu_target is None:
|
if menu_target is None:
|
||||||
style["opacity"] = "0"
|
style["opacity"] = "0"
|
||||||
style["visibility"] = "hidden"
|
style["visibility"] = "hidden"
|
||||||
|
@ -150,6 +147,12 @@ class View:
|
||||||
h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, "←"),
|
h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, "←"),
|
||||||
h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")])
|
h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")])
|
||||||
|
|
||||||
|
elif type(menu_target) is Sense:
|
||||||
|
sense = menu_target
|
||||||
|
return h("span.popup-menu", { "style": style }, [
|
||||||
|
h("button.shyButton", { "on": {"click": msg(SenseMoveUp(sense))}}, "↑"),
|
||||||
|
h("button.shyButton", { "on": {"click": msg(SenseMoveDown(sense))}}, "↓"),
|
||||||
|
h("button.shyButton", { "on": {"click": msg(SenseBin(sense))}}, "🗑")])
|
||||||
else:
|
else:
|
||||||
console.log("Should not be heree!!")
|
console.log("Should not be heree!!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user