52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
from model.example import Example
|
|
from model.translation import from_container_list
|
|
from model.data import Data
|
|
from model.tags import import_label_list
|
|
from view import View
|
|
import message as M
|
|
from lib.snabbdom import h
|
|
from view.utils import clean_label
|
|
|
|
|
|
class Sense(Data):
|
|
def __init__(self):
|
|
self.original_idx = -1
|
|
self.definition = {}
|
|
self.labels = []
|
|
self.translations = []
|
|
self.examples = []
|
|
|
|
def import_xml(self, sense_xml, idx):
|
|
self.original_idx = idx
|
|
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
|
key = definition.getAttribute("type")
|
|
self.definition[key] = definition.textContent
|
|
|
|
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)
|
|
|
|
|
|
def merge_labels(self):
|
|
return ", ".join(val for _, val in self.labels)
|
|
|
|
|
|
def view(self, model, sense_num):
|
|
examples = [example.view(model, self) for example in self.examples]
|
|
|
|
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
|
|
|