diff --git a/res/main.less b/res/main.less index 22380c3..80aef98 100644 --- a/res/main.less +++ b/res/main.less @@ -212,23 +212,6 @@ } } - .example-cluster, .example-logdice, .example-frequency { - vertical-align: super; - font-size: 0.7em; - margin-left: 0.1em; - margin-right: 0.1em; - } - - .example-cluster { - color: @blue; - } - .example-logdice { - color: @gray; - } - .example-frequency { - color: @darkred; - } - .example-rest { border: 1px transparent solid; @@ -266,6 +249,26 @@ margin-top: 0.3em; } + +.example-text { + .example-cluster, .example-logdice, .example-frequency { + vertical-align: super; + font-size: 0.7em; + margin-left: 0.1em; + margin-right: 0.1em; + } + + .example-cluster { + color: @blue; + } + .example-logdice { + color: @gray; + } + .example-frequency { + color: @darkred; + } +} + .example-component { .example-component-button { padding-left: 0.3em; diff --git a/src/lib/preferences.py b/src/lib/preferences.py new file mode 100644 index 0000000..881ee0a --- /dev/null +++ b/src/lib/preferences.py @@ -0,0 +1,8 @@ +from browser import window +# interface to plugin properties + +def get_preference(key): + return window.customizeEditor[key] if window.customizeEditor else None + + + diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index 6fb0774..f780bc2 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -3,11 +3,14 @@ from message.message import msg, Message from view import modals from browser import window, document from lib.snabbdom import h +from lib.preferences import get_preference +from lib.structure_conversions import convert_structure from model.example.example import Example from model.example.corpus_example import CorpusExample from model.example.multiword_example import MultiwordExample from model.example.component_lexeme import ComponentLexeme +from model.example_clusters import ExampleClusters class SkeExample: @@ -15,6 +18,7 @@ class SkeExample: self.left = "" self.right = "" self.mid = "" + self.s_id = "" for left_el in line.Left: self.left += left_el.str @@ -25,6 +29,11 @@ class SkeExample: for mid_el in line.Kwic: self.mid += mid_el.str + for ref in line.Refs: + if ref.startswith("s.id"): + self.s_id = ref.split("=")[1] + + def view(self): return [h("span", {}, self.left + " "), h("span", {"style": {"font-weight": "bold"}}, self.mid), @@ -40,16 +49,14 @@ class SkeCollocation: self.other = {"score": data.score, "cm": data.cm} def view(self): - return [ - h("span.grey1", {}, self.word), + return [h("span.example-text", {}, [ + h("span.example-text-2", {}, self.word), + h("span.example-frequency", {}, self.frequency), + h("span.example-logdice", {}, self.other["score"]), + h("span", {}, "; "), + h("span.grey1", {}, self.other["cm"]), h("span", {}, ","), - h("span.grey2", {}, self.frequency), - h("span", {}, ","), - h("span.grey1", {}, self.other["score"]), - h("span", {}, ","), - h("span.grey2", {}, self.other["cm"]), - h("span", {}, ","), - h("span.grey1", {}, self.structure_name)] + h("span.grey2", {}, self.structure_name)])] def get_parser(ske_index_type): @@ -67,26 +74,38 @@ class SkeModal(ClickMessage): if type(event) in [list, int]: self.add_arg(event) else: - if len(self._args) < 3: + if len(self._args) < 4: self.add_arg(None) super().on_event(event) def update_model(self, model): - search_term = self.get_arg(0, str) - ske_index = self.get_arg(1, int) + page_num = self.get_arg(0, int) + search_term = self.get_arg(1, str) + ske_index = self.get_arg(2, int) ske_lookup = model.ske.url_for_kind_index(ske_index) # could be none if empty - data = self.get_arg(2) + data = self.get_arg(3) if data is None: - model.ske.request(search_term, - msg(SkeModal, search_term, ske_index), - ske_lookup, - {"additional_refs": "s.id,p.id", - "error_callback": msg(SkeModal, search_term, ske_index), - "data_parser": get_parser(ske_index)}) + params = {"additional_refs": "s.id,p.id", + "page_num": page_num, + "error_callback": msg(SkeModal, page_num, search_term, ske_index), + "data_parser": get_parser(ske_index)} - model.modal_set(lambda: modals.ske_list(search_term, data, model.entry.senses, model.ske.request_kinds)) + gdex = get_preference("ske_gdex") + if gdex: + if not len(gdex) == 2: + window.console.log("Strange gdex setting, should be a list of length 2: [gdexconf, gdexcnt]") + return + params["gdex"] = gdex + + model.ske.request(search_term, + msg(SkeModal, page_num, search_term, ske_index), + ske_lookup, + params) + + model.modal_set(lambda: modals.ske_list( + search_term, data, page_num, model.entry.senses, model.ske.request_kinds)) def reset(self): return False @@ -101,6 +120,7 @@ class ShowSkeModal(SkeModal): class SearchInSkeModal(SkeModal): def on_event(self, event): + self.add_arg(int(document.getElementById("ske-page-num").value)) self.add_arg(document.getElementById("ske-search").value) self.add_arg(document.getElementById("ske-select").selectedIndex) super().on_event(event) @@ -139,6 +159,8 @@ class SkeInsert(DataChgClickMessage): def _as_corpus_example(self, example): new_example = Example() new_example.inner = CorpusExample() + new_example.inner.other_attributes["example_id"] = example.s_id + new_example.inner.cluster = ExampleClusters.first_empty_cluster() lex_left = ComponentLexeme() lex_left.text = example["left"] diff --git a/src/model/example/example.py b/src/model/example/example.py index c5e3d5d..f37e690 100644 --- a/src/model/example/example.py +++ b/src/model/example/example.py @@ -22,12 +22,13 @@ class Example(Data): inner_xml = example_xml.querySelector("corpusExample") if inner_xml is not None: - self.inner = CorpusExample(inner_xml) + self.inner = CorpusExample() else: inner_xml = example_xml.querySelector("multiwordExample") self.inner = MultiwordExample() - self.inner.import_xml(inner_xml) + self.inner.import_xml(inner_xml) + for comp_xml in inner_xml.childNodes: comp = ComponentLexeme() comp.import_xml(comp_xml) diff --git a/src/view/modals.py b/src/view/modals.py index ec6e35f..812d96b 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -131,7 +131,7 @@ def do_chosen_examples(example_list, entry): return modal_template(options, "Examples picker", (message.DoChosenExamples, example_list)) -def ske_list(search_term, data, senses, ske_kinds): +def ske_list(search_term, data, page_num, senses, ske_kinds): list_contents = [] ske_list_hidden = False @@ -148,12 +148,18 @@ def ske_list(search_term, data, senses, ske_kinds): list_contents.append(h("span.error", {}, "Something went wrong in SKE: {}".format(data))) contents = [ - h("div.flex.three", {}, [ - h("select#ske-select.third", {}, [ + h("div.flex.four", {}, [ + h("select#ske-select.fourth", {}, [ h("option", {}, "{}".format(x)) for x in ske_kinds]), - h("label.third.ske-mid-input", {}, [ + h("label.fourth.ske-mid-input", {}, [ h("input#ske-search", {"props": {"value": search_term, "type": "text"}}, "")]), - h("span.third.button.ske-right-button", + h("label.fourth.ske-mid-input", {}, [ + h("input#ske-page-num", {"attrs": { + "value": str(page_num), + "type": "number", + "min": 1, + "step": 1}}, "")]), + 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"}}, diff --git a/src/view/view.py b/src/view/view.py index d95168b..91f0628 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -58,7 +58,7 @@ class View: def view_ske_button(model): return h( "span#ske-button.button.toggle", - { "on": {"click": msg(ShowSkeModal, model.entry.headword, 0)} }, + { "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0)} }, h("svg#ske-img", { "attrs": { "xmlns": "http://www.w3.org/2000/svg",