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.
 
 
 
 
 
 

147 lines
4.5 KiB

from message.message import Message
from message.simple_messages import NoReset, DataChgClickMessage
import message.common_accessors as common_accessors
from browser import document
from model import Sense, Example
from model.example_clusters import ExampleClusters
class QuestionMessage(Message):
def on_event(self, event):
input_element = document.getElementById("modal-question")
self.new_text = input_element.value
class EditSenseLabel(Message):
def update_model(self, model):
sense = self.get_arg(0, Sense)
sense.labels = common_accessors.label_list_getter()
class AddToGenericList(NoReset):
def update_model(self, model):
list_getter = self.get_arg(0)
list_getter().append("")
def data_change(self):
return False
class AddToLabelList(NoReset):
def update_model(self, model):
list_to_add_to = self.get_arg(0, list)
thing_to_add_getter = self.get_arg(1)
thing_to_add = thing_to_add_getter()
# just adding to the copy to show in the modal
list_to_add_to.append(thing_to_add)
def data_change(self):
return False
class AddSense(Message):
def update_model(self, model):
sense = Sense()
sense.definitions = [{"type": "indicator", "value": "Nov pomen"}]
model.entry.senses.append(sense)
class EditSenseDefinition(Message):
def update_model(self, model):
sense = self.get_arg(0, Sense)
definitions_values = common_accessors.definitions_getter()
indicator = None
explanation = None
for x in sense.definitions:
if indicator is None and x["type"] == "indicator":
indicator = x
if explanation is not None:
break
if explanation is None and x["type"] == "explanation":
explanation = x
if indicator is not None:
break
if definitions_values["indicator"] != "":
if indicator is None:
indicator = {"type": "indicator"}
sense.definitions.append(indicator)
indicator["value"] = definitions_values["indicator"]
elif indicator is not None:
sense.definitions.remove(indicator)
if definitions_values["explanation"] != "":
if explanation is None:
explanation = {"type": "explanation"}
sense.definitions.append(explanation)
explanation["value"] = definitions_values["explanation"]
elif explanation is not None:
sense.definitions.remove(explanation)
class EditComment(QuestionMessage):
def update_model(self, model):
model.entry.comment = self.new_text
class MoveExamplesToSense(Message):
def update_model(self, model):
chosen_examples = self.get_arg(0, list)
inputs = document.getElementsByClassName("checkable-input")
selected = None
for idx, el in enumerate(inputs):
if el.checked:
selected = idx
break
# none was selected
if selected is None:
return
# first, remove the selected examples from wherever they were
for sense in model.entry.senses:
for example in chosen_examples:
if example in sense.examples:
sense.examples.remove(example)
# now, append selected examples to chosen sense
model.entry.senses[selected].examples.extend(chosen_examples)
class EditVariants(Message):
def update_model(self, model):
variants = common_accessors.generic_list_getter()
model.entry.variants = variants
class EditHomonymy(Message):
def update_model(self, model):
homonymy = common_accessors.double_list_getter("value", "name")
model.entry.homonymy = homonymy
class EditRelatedEntries(Message):
def update_model(self, model):
related_entries = common_accessors.generic_list_getter()
model.entry.related_entries = related_entries
class EditEntryLabels(Message):
def update_model(self, model):
labels = common_accessors.label_list_getter()
model.entry.labels = labels
class ExampleClusterEdit(DataChgClickMessage):
def update_model(self, model):
example = self.get_arg(0, Example)
cluster = self.get_arg(1, int)
example.set_cluster(cluster)
class ExampleClusterAdd(DataChgClickMessage):
def update_model(self, model):
example = self.get_arg(0, Example)
example.set_cluster(ExampleClusters.first_empty_cluster())