From bcd8d3ced97670e97d45c83c9f4d97fe57425852 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Wed, 20 Nov 2019 23:24:16 +0100 Subject: [PATCH] Refactored show menu so that it will be able to accept sense --- res/main.less | 6 +++--- src/message/show_messages.py | 2 +- src/model/model.py | 4 ++-- src/view/view.py | 30 ++++++++++++++++++++---------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/res/main.less b/res/main.less index 1666f2b..e85310d 100644 --- a/res/main.less +++ b/res/main.less @@ -194,9 +194,9 @@ background-color: @white; border-radius: 0.2em; - // by default hidden - visibility: hidden; - opacity: 0; + // by default shown + visibility: visible; + opacity: 1; transition: visibility 0s, opacity 0.1s linear; button { diff --git a/src/message/show_messages.py b/src/message/show_messages.py index fda7057..f8d5bd4 100644 --- a/src/message/show_messages.py +++ b/src/message/show_messages.py @@ -14,8 +14,8 @@ class ShowMenu(ClickMessage): def update_model(self, model): model.menu_location = self.menu_location - model.menu_shown = True model.translation = self.get_arg(0, Translation) + model.menu_target = model.translation class ShowSenseLabelEdit(ClickMessage): diff --git a/src/model/model.py b/src/model/model.py index db8ac33..4f0d9be 100644 --- a/src/model/model.py +++ b/src/model/model.py @@ -11,7 +11,7 @@ class Model: #runtime info self.menu_location = (0, 0) - self.menu_shown = False + self.menu_target = None # modal handling self.modal = lambda: [] @@ -25,7 +25,7 @@ class Model: self.modal_reset() def reset(self): - self.menu_shown = False + self.menu_target = None self.modal_shown = False def modal_reset(self): diff --git a/src/view/view.py b/src/view/view.py index fb0b656..1070072 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -2,6 +2,7 @@ from lib.snabbdom import h, patch from message import * import random from view.utils import * +from model import Translation, Sense from export import export_to_xml @@ -22,7 +23,7 @@ class View: return h("div", {"on": { "click": msg(Reset()) }}, [ View.view_entry(self.model.entry), h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"), - View.view_menu(self.model.menu_location, self.model.menu_shown, self.model.translation), + View.view_menu(self.model.menu_location, self.model.menu_target), View.view_modal(self.model.modal_shown, self.model.modal)]) @staticmethod @@ -128,20 +129,29 @@ class View: @staticmethod - def view_menu(location, menu_shown, translation): + def view_menu(location, menu_target): style = { "left": "{}px".format(location[0]), "top": "{}px".format(location[1]) } - if menu_shown: - style["opacity"] = "1" - style["visibility"] = "visible" - return h("span.popup-menu", { "style": style }, [ - h("button.shyButton", { "on": {"click": msg(ShowEditTranslation(translation))}}, "✎"), - h("button.shyButton", { "on": {"click": msg(MoveRight(translation))}}, "→"), - h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, "←"), - h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")]) + console.log(menu_target) + console.log(type(menu_target)) + + if menu_target is None: + style["opacity"] = "0" + style["visibility"] = "hidden" + + elif type(menu_target) is Translation: + translation = menu_target + return h("span.popup-menu", { "style": style }, [ + h("button.shyButton", { "on": {"click": msg(ShowEditTranslation(translation))}}, "✎"), + h("button.shyButton", { "on": {"click": msg(MoveRight(translation))}}, "→"), + h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, "←"), + h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")]) + + else: + console.log("Should not be heree!!") @staticmethod