show/hide examples

This commit is contained in:
Ozbolt Menegatti 2020-01-25 23:22:23 +01:00
parent 27409b6f63
commit 932400a06c
5 changed files with 31 additions and 4 deletions

View File

@ -4,7 +4,7 @@ from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, Show
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentAdd, ExampleComponentRemove, EditExampleText from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples
from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels
from message.message import msg from message.message import msg

View File

@ -82,3 +82,9 @@ class ExampleComponentRemove(NoReset):
component_num = self.get_arg(1, int) component_num = self.get_arg(1, int)
example.copy().components.splice(component_num, 1) example.copy().components.splice(component_num, 1)
class ToggleExamples(Message):
def update_model(self, model):
model.examples_shown = not model.examples_shown

View File

@ -63,6 +63,10 @@ class Example(Editable):
def set_cluster(self, cluster): def set_cluster(self, cluster):
self.inner.cluster = cluster self.inner.cluster = cluster
def is_collocation(self):
return type(self.inner) is CorpusExample
class CorpusExample: class CorpusExample:
def __init__(self, example_xml): def __init__(self, example_xml):
self.other_attributes = {} self.other_attributes = {}
@ -82,6 +86,7 @@ class CorpusExample:
def get_valid_cluster(self): def get_valid_cluster(self):
return None return None
class MultiwordExample: class MultiwordExample:
def __init__(self, example_xml): def __init__(self, example_xml):
self.other_attributes = {} self.other_attributes = {}

View File

@ -22,8 +22,9 @@ class Model:
self.translation = None self.translation = None
self.sense = None self.sense = None
# choosing examples # choosing and hiding examples
self.chosen_examples = [] self.chosen_examples = []
self.examples_shown = True
self.reset() self.reset()
self.modal_reset() self.modal_reset()

View File

@ -34,17 +34,28 @@ class View:
def view_entry(entry, model): def view_entry(entry, model):
view_sense_list = [View.view_sense(sense, idx, model) for idx, sense in enumerate(entry.senses)] view_sense_list = [View.view_sense(sense, idx, model) for idx, sense in enumerate(entry.senses)]
buttons_left = View.view_entry_button_section(entry, model)
buttons_right = View.view_toggle_buttons(model)
return h("div#entry", {}, [ return h("div#entry", {}, [
h("div#entry-status", {}, entry.status), h("div#entry-status", {}, entry.status),
h("div#entry-header", {}, [ h("div#entry-header", {}, [
h("span#headword", {}, entry.headword), h("span#headword", {}, entry.headword),
h("span#grammar", {}, entry.grammar), h("span#grammar", {}, entry.grammar),
h("span#measure", {}, entry.get_measure_text())]), h("span#measure", {}, entry.get_measure_text())]),
View.view_entry_button_section(entry, model), h("div.flex.five", {}, [
h("div.four-fifth", {}, buttons_left),
h("div.one-fifth", {}, buttons_right)]),
h("div#sense-container", {}, view_sense_list), h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")]) h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")])
@staticmethod
def view_toggle_buttons(model):
txt = "Hide examples" if model.examples_shown else "Show examples"
return [ h("span.button.toggle", {"on": {"click": msg(ToggleExamples())}}, txt) ]
@staticmethod @staticmethod
def view_entry_button_section(entry, model): def view_entry_button_section(entry, model):
clk = lambda cls: {"on": {"click": msg(cls)}} clk = lambda cls: {"on": {"click": msg(cls)}}
@ -130,7 +141,11 @@ class View:
if "logDice" in example.other_attributes: if "logDice" in example.other_attributes:
example_content.append(h("span.example-logdice", {}, example.other_attributes["logDice"])) example_content.append(h("span.example-logdice", {}, example.other_attributes["logDice"]))
return h("div.example", {}, [ parent_display = "inherit"
if not model.examples_shown and not example.is_collocation():
parent_display = "none"
return h("div.example", {"style": {"display": parent_display}}, [
h("div.example-dot", dot_attr, ""), h("div.example-dot", dot_attr, ""),
h(example_tag, {}, [ h(example_tag, {}, [
h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content), h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content),