Adding ESC key press action.

This commit is contained in:
Ozbolt Menegatti 2020-01-05 09:53:16 +01:00
parent ed16384063
commit b5e77d3996
5 changed files with 20 additions and 1 deletions

View File

@ -1,4 +1,4 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels

View File

@ -34,6 +34,9 @@ class Message:
def reset(self): def reset(self):
return True return True
def clear_args(self):
self._args = []
def msg(message, params): def msg(message, params):
if not issubclass(type(message), Message): if not issubclass(type(message), Message):

View File

@ -28,6 +28,18 @@ class NoReset(Reset):
return False return False
class KeyboardPress(Message):
def on_event(self, event):
self.add_arg(event.key)
def reset(self):
key = self.get_arg(0, str)
return key == "Escape"
def update_model(self, model):
pass
# a "hack" message for reseting modals # # a "hack" message for reseting modals #
# everytime a modal closes, run 100ms later model.modal = [] # everytime a modal closes, run 100ms later model.modal = []
# this is done to achieve nice close animation # this is done to achieve nice close animation

View File

@ -26,6 +26,7 @@ class Update:
# do update # do update
for msg in self.message_queue: for msg in self.message_queue:
msg.update_model(self.model) msg.update_model(self.model)
msg.clear_args()
if reset: if reset:
self.model.post_reset() self.model.post_reset()

View File

@ -13,6 +13,9 @@ class View:
self.model = None self.model = None
patch(container, self.vdom) patch(container, self.vdom)
# this does not work on parent div, so attaching to document here
document.addEventListener("keyup", msg(KeyboardPress()))
def view(self, model): def view(self, model):
self.model = model self.model = model
new_vdom = self._view() new_vdom = self._view()