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.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

View File

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

View File

@ -26,6 +26,18 @@ class Reset(ClickMessage):
class NoReset(Reset):
def reset(self):
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 #

View File

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

View File

@ -12,6 +12,9 @@ class View:
self.vdom = h('div', {}, "Loading...")
self.model = None
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):
self.model = model