lexonomy_custom_editor/src/model/sense.py

52 lines
2.0 KiB
Python
Raw Normal View History

2019-11-05 21:18:20 +00:00
from model.example import Example
from model.translation import from_container_list
2020-02-16 22:18:07 +00:00
from model.data import Data
from model.tags import import_label_list
2020-02-16 22:18:07 +00:00
from view import View
import message as M
from lib.snabbdom import h
from view.utils import clean_label
2019-11-05 21:18:20 +00:00
2019-11-11 22:04:45 +00:00
2020-02-16 22:18:07 +00:00
class Sense(Data):
def __init__(self):
self.original_idx = -1
2020-01-14 19:59:15 +00:00
self.definition = {}
2020-02-16 22:18:07 +00:00
self.labels = []
self.translations = []
self.examples = []
def import_xml(self, sense_xml, idx):
self.original_idx = idx
2020-01-14 19:59:15 +00:00
for definition in sense_xml.querySelectorAll("definitionList definition"):
key = definition.getAttribute("type")
self.definition[key] = definition.textContent
2019-11-05 21:18:20 +00:00
self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list(
sense_xml.querySelectorAll("translationContainerList translationContainer"))
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
example = Example()
example.import_xml(example_xml)
self.examples.append(example)
2020-02-16 22:18:07 +00:00
def merge_labels(self):
return ", ".join(val for _, val in self.labels)
2020-02-16 22:18:07 +00:00
def view(self, model, sense_num):
examples = [example.view(model, self) for example in self.examples]
2020-02-16 22:18:07 +00:00
result = h("div.elm-div", {}, [
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
h("div", {}, View.view_translations(self.translations, self, model)),
h("div", {}, examples)])])
return result
2020-01-28 22:05:48 +00:00