changing the way sense editing works, now general
This commit is contained in:
parent
b7b91fa6d6
commit
daa56ba7ac
|
@ -30,7 +30,7 @@ class ShowSenseLabelEdit(GenericShowModal):
|
||||||
super().update_model(model)
|
super().update_model(model)
|
||||||
model.sense = self.arg
|
model.sense = self.arg
|
||||||
|
|
||||||
model.sense.temporary_labels = model.sense.labels[:]
|
model.sense.make_copy()
|
||||||
model.modal = lambda: modals.edit_sense_label(model.sense)
|
model.modal = lambda: modals.edit_sense_label(model.sense)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@ class AddSenseLabel(NoReset):
|
||||||
self.sense = prop
|
self.sense = prop
|
||||||
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
self.sense.temporary_labels.append("")
|
# just adding to the copy to show in the modal
|
||||||
|
self.sense.copy().labels.append("")
|
||||||
|
|
||||||
|
|
||||||
class EditSenseDefinition(SimpleEditMessage):
|
class EditSenseDefinition(SimpleEditMessage):
|
||||||
|
|
|
@ -70,7 +70,7 @@ def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
|
||||||
def edit_sense_label(sense):
|
def edit_sense_label(sense):
|
||||||
content = [h("span", {}, "Edit sense labels")]
|
content = [h("span", {}, "Edit sense labels")]
|
||||||
|
|
||||||
for slabel in sense.temporary_labels:
|
for slabel in sense.copy().labels:
|
||||||
content.append(h("label", {}, [
|
content.append(h("label", {}, [
|
||||||
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||||
|
|
||||||
|
|
25
src/model/editable.py
Normal file
25
src/model/editable.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
class Editable:
|
||||||
|
def make_copy(self):
|
||||||
|
# delete old copy
|
||||||
|
if hasattr(self, "_copy"):
|
||||||
|
if self._copy is not None:
|
||||||
|
self._copy = None
|
||||||
|
|
||||||
|
# make new copy
|
||||||
|
self._copy = JSON.parse(JSON.stringify(self))
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
# check if even initialized
|
||||||
|
if hasattr(self, "_copy"):
|
||||||
|
return self._copy
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def overwrite_with_copy(self):
|
||||||
|
for key, value in dict(self._copy).items():
|
||||||
|
if key == "_copy":
|
||||||
|
continue
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
self._copy = None
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
from model.example import Example
|
from model.example import Example
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
|
from model.editable import Editable
|
||||||
|
|
||||||
|
|
||||||
class Sense:
|
class Sense(Editable):
|
||||||
def __init__(self, sense_xml):
|
def __init__(self, sense_xml):
|
||||||
definition = sense_xml.querySelector("definitionList definition")
|
definition = sense_xml.querySelector("definitionList definition")
|
||||||
|
|
||||||
|
@ -23,7 +24,4 @@ class Sense:
|
||||||
self.translations = [[] for _ in range(max_num_cluster)]
|
self.translations = [[] for _ in range(max_num_cluster)]
|
||||||
for clusterNum, translation in translations:
|
for clusterNum, translation in translations:
|
||||||
self.translations[clusterNum - 1].append(translation)
|
self.translations[clusterNum - 1].append(translation)
|
||||||
|
|
||||||
# useful for editing
|
|
||||||
self.temporary_labels = None
|
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,11 @@ class View:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_translations(translations, sense):
|
def view_translations(translations, sense):
|
||||||
joiner = lambda: h("span.translation-semicolon", {}, ";")
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
for cluster in translations:
|
for cluster in translations:
|
||||||
result.extend([View.view_one_translation(t) for t in cluster])
|
result.append(h("div.translation-div-cluster", {}, [View.view_one_translation(t) for t in cluster]))
|
||||||
result.append(joiner())
|
|
||||||
|
|
||||||
# remove last ';' and add + button; [-1] does not work in transcrypt
|
result.append(h("button", {"on": {"click": msg(ShowAddTranslation, sense)}}, "+"))
|
||||||
result[len(result) - 1] = h("button", {"on": {"click": msg(ShowAddTranslation, sense)}}, "+")
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user