New editor written in Python dialect
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.
 
 
 
 
 
 

55 lines
2.2 KiB

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.id = None
self.definitions = []
self.labels = []
self.translations = []
self.examples = []
def import_xml(self, sense_xml, idx):
self.original_idx = idx
self.id = sense_xml.getAttribute("id") if sense_xml.hasAttribute("id") else None
self.definitions = [{"value": v.textContent, "type": v.getAttribute("type")} for v in sense_xml.querySelectorAll("definitionList definition")]
self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list(
sense_xml.querySelectorAll('sense > 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]
definition = ""
for x in self.definitions:
if x["type"] == "indicator":
definition = x.value
break
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) }}, definition),
h("div", {}, View.view_translations(self.translations, self, model)),
h("div", {}, examples)])])
return result