show/hide examples
This commit is contained in:
parent
27409b6f63
commit
932400a06c
|
@ -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.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
|
||||
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.message import msg
|
||||
|
|
|
@ -82,3 +82,9 @@ class ExampleComponentRemove(NoReset):
|
|||
component_num = self.get_arg(1, int)
|
||||
|
||||
example.copy().components.splice(component_num, 1)
|
||||
|
||||
|
||||
class ToggleExamples(Message):
|
||||
def update_model(self, model):
|
||||
model.examples_shown = not model.examples_shown
|
||||
|
||||
|
|
|
@ -63,6 +63,10 @@ class Example(Editable):
|
|||
def set_cluster(self, cluster):
|
||||
self.inner.cluster = cluster
|
||||
|
||||
def is_collocation(self):
|
||||
return type(self.inner) is CorpusExample
|
||||
|
||||
|
||||
class CorpusExample:
|
||||
def __init__(self, example_xml):
|
||||
self.other_attributes = {}
|
||||
|
@ -82,6 +86,7 @@ class CorpusExample:
|
|||
def get_valid_cluster(self):
|
||||
return None
|
||||
|
||||
|
||||
class MultiwordExample:
|
||||
def __init__(self, example_xml):
|
||||
self.other_attributes = {}
|
||||
|
|
|
@ -22,8 +22,9 @@ class Model:
|
|||
self.translation = None
|
||||
self.sense = None
|
||||
|
||||
# choosing examples
|
||||
# choosing and hiding examples
|
||||
self.chosen_examples = []
|
||||
self.examples_shown = True
|
||||
|
||||
self.reset()
|
||||
self.modal_reset()
|
||||
|
|
|
@ -34,17 +34,28 @@ class View:
|
|||
def view_entry(entry, model):
|
||||
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", {}, [
|
||||
h("div#entry-status", {}, entry.status),
|
||||
h("div#entry-header", {}, [
|
||||
h("span#headword", {}, entry.headword),
|
||||
h("span#grammar", {}, entry.grammar),
|
||||
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("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
|
||||
def view_entry_button_section(entry, model):
|
||||
clk = lambda cls: {"on": {"click": msg(cls)}}
|
||||
|
@ -130,7 +141,11 @@ class View:
|
|||
if "logDice" in example.other_attributes:
|
||||
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(example_tag, {}, [
|
||||
h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content),
|
||||
|
|
Loading…
Reference in New Issue
Block a user