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.
 
 
 
 
 
 

244 lines
10 KiB

from lib.snabbdom import h
import message
from view.modal_templates import *
from view.utils import show_toggle_cluster_buttons
from export import export_to_xml, export_example_to_entry_xml
from update import update
from model.entry import Entry
import lib.screenful as screenful
from model.model import Model
import model
def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
def split_line2(left, right):
return h("div.flex.two", {}, [
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)])
content = []
if type(parent) is model.Example:
content.extend([
h("span.translation-original-title", {}, "Primer: "),
h("span.translation-original", {}, parent.simple_view()),
h("hr", {}, None)])
# first line: transalation itself
content.extend([
split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
content.extend(explanation_editor("Razlage:", lambda: translation.explanationList))
# cluster number
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
content.append(split_line2("Stevilka gruce:", h("select#cluster-num", {}, options)))
content.append(h("h4", {}, "Tags"))
content.extend(label_list_editor(translation.copy().tags, [message.AddToLabelList, translation.copy().tags]))
return modal_template(content, "Translation", cls)
def edit_sense_label(sense):
content = label_list_editor(sense.copy().labels, [message.AddToLabelList, sense.copy().labels])
return modal_template(content, "Translation", (message.EditSenseLabel, sense))
def edit_example(example, sense):
example_original = example
example = example_original.copy()
def role_msg(idx, role):
return message.msg(message.ExampleRoleChange, example_original, idx, role)
divs = []
def list_of_right_buttons(idx, component):
result = [
h("span.example-component-button.example-component-headword",
{"on": {"click": role_msg(idx, "headword")}}, "H"),
h("span.example-component-button.example-component-collocate",
{"on": {"click": role_msg(idx, "collocate")}}, "C"),
h("span.example-component-button.example-component-other",
{"on": {"click": role_msg(idx, "other")}}, "O")]
if example.is_multiword():
additional_class = ".example-component-no-space" if component.no_space else ""
click_message = message.msg(message.ExampleComponentSpace, example_original, idx)
result.append(h("span.example-component-button" + additional_class,
{"on": {"click": click_message }}, ""))
else:
result.append(h("span.example-component-button.example-component-none",
{"on": {"click": role_msg(idx, "none")}}, "N"))
if "-" not in example.inner.other_attributes["structureName"]:
result.extend([
h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")])
return result
divs.append(h("div.flex.five.example-component", {}, [h("div.one-fifth", {}, "Struktura:"),
h("div.three-fifth", {}, example.inner.other_attributes["structureName"])]))
for idx, component in enumerate(example.components):
role_txt = component.role if component.role is not None else "none"
color_class = ".example-component-" + role_txt
left = [h("span" + color_class, {}, role_txt)]
if component.role is None:
middle = [h("textarea.example-component-text", {"props": {"value": component.text}}, "")]
else:
middle = [h("input.example-component-text", {"props": {"type": "text", "value": component.text}}, "")]
divs.append(h("div.flex.five.example-component", {}, [
h("div.one-fifth", {}, left),
h("div.three-fifth", {}, middle),
h("div.one-fifth", {}, list_of_right_buttons(idx, component))]))
return modal_template(divs, "Edit Example",
(message.EditExampleText, example_original, sense))
def edit_variants(entry):
vget = lambda: entry.copy().variants
content = generic_list_editor("Variants", vget)
return modal_template(content, "Add or remove variants", (message.EditVariants,), (message.DeleteVariants,))
def edit_homonymy(entry):
hget = lambda: entry.copy().homonymy
content = generic_key_value_editor("Homonymy", hget, "name")
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
def edit_related_entries(entry):
reget = lambda: entry.copy().related_entries
content = generic_list_editor("Related entries", reget)
return modal_template(content, "Add or remove related entries", (message.EditRelatedEntries,), (message.DeleteRelatedEntries,))
def edit_entry_labels(entry):
content = label_list_editor(entry.copy().labels, [message.AddToLabelList, entry.copy().labels])
return modal_template(content, "Translation", (message.EditEntryLabels,), (message.DeleteEntryLabels,))
def edit_sense_definition(sense):
indicator = ""
explanation = ""
for x in sense.copy().definitions:
if indicator == "" and x["type"] == "indicator":
indicator = x.value
if explanation is not "":
break
if explanation == "" and x["type"] == "explanation":
explanation = x.value
if indicator is not "":
break
content = sense_definitions_editor(indicator, explanation)
return modal_template(content, "Definicije pomena", (message.EditSenseDefinition, sense))
def edit_comment(comment):
return modal_template(big_question("Edit comment", comment), "Comment", (message.EditComment,), (message.DeleteComment,))
def do_chosen_examples(example_list, model, multiword_example):
if multiword_example is False:
return move_examples_to_sense(example_list, model.entry)
else:
return modal_template([
h("button.shyButton", {"on": {"click": (lambda: move_to_view(example_list, model))}}, "Premakni v pomen"),
h("button.shyButton", {"on": {"click": (lambda: export_to_new_entry(multiword_example, example_list))}},
"Izvozi v novo geslo")], "Izberite željeno akcijo", None)
def move_to_view(example_list, model):
model.modal_reset()
model.modal_set(lambda: move_examples_to_sense(example_list, model.entry))
update.view.view(model, True)
def export_to_new_entry(multiword_example, example_list):
other_examples = []
for example in example_list:
if example.is_multiword() is False:
other_examples.append(example)
entry_xml = export_example_to_entry_xml(multiword_example, other_examples if len(example_list) > 0 else None)
new_entry = Entry()
new_entry.import_xml(entry_xml)
new_model = Model()
new_model.entry = new_entry
screenful.screenful().Editor['new'](None, export_to_xml(new_model))
def move_examples_to_sense(example_list, entry):
example_senses = []
for idx, sense in enumerate(entry.senses):
for ex in sense.examples:
if ex in example_list:
example_senses.append(idx)
break
sense_of_first_example = example_senses[0]
options = [h("p", {}, "Choose sense for examples")]
for idx, sense in enumerate(entry.senses):
text = "{}: {}".format(idx + 1, sense.definition["indicator"])
id_ = "choose-example-{}".format(idx)
props = {"type": "radio", "name": "choose-example"}
if idx == sense_of_first_example:
props["checked"] = True
options.append(h("input#{}.checkable-input".format(id_), {"props": props}, []))
options.append(h("label.checkable", {"attrs": {"for": id_}}, text))
options.append(h("br", {}, []))
return modal_template(options, "Examples picker", (message.MoveExamplesToSense, example_list))
def ske_list(search_term, data, page_num, senses, ske_kinds):
list_contents = []
ske_list_hidden = False
if data is None:
list_contents.append(h("div.loadingspinner", {}, ""))
elif type(data) is list:
for line in data:
list_contents.append(h("label.ske-line", {}, [
h("input.ske-line-check", {"props": { "type": "checkbox" }}, ""),
h("span.checkable", {}, line.view())]))
elif type(data) is str:
ske_list_hidden = True
else:
list_contents.append(h("span.error", {}, "Something went wrong in SKE: {}".format(data)))
contents = [
h("div.flex.four", {}, [
h("select#ske-select.fourth", {}, [
h("option", {}, "{}".format(x)) for x in ske_kinds]),
h("label.fourth.ske-mid-input", {}, [
h("input#ske-search", {"props": {"value": search_term, "type": "text"}}, "")]),
h("label.fourth.ske-mid-input", {}, [
h("input#ske-page-num", {"attrs": {
"value": str(page_num),
"type": "number",
"min": 1,
"step": 1}}, "")]),
h("label.fourth.ske-mid-input", {}, [
h("select#ske-pos-query", {}, [h("option", {}, "{}".format(pos)) for pos in ["simple", "samostalnik", "glagol", "pridevnik", "prislov", "zaimek"]])
]),
h("span.fourth.button.ske-right-button",
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
h("div.ske-list",
{"style": {"visibility": "hidden" if ske_list_hidden else "visible"}},
list_contents),
h("div.flex.three", {}, [
h("span.third", {}, "Vstavi v:"),
h("select#ske-sense-select.two-third", {}, [ h("option", {}, "{} {}".format(
idx + 1, sense.definition["indicator"])) for idx, sense in enumerate(senses)])])]
return modal_template(contents, "SKE", (message.SkeInsert, data))