Adding ESC key press action.
This commit is contained in:
parent
ed16384063
commit
b5e77d3996
|
@ -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
|
||||
|
|
|
@ -34,6 +34,9 @@ class Message:
|
|||
def reset(self):
|
||||
return True
|
||||
|
||||
def clear_args(self):
|
||||
self._args = []
|
||||
|
||||
|
||||
def msg(message, params):
|
||||
if not issubclass(type(message), Message):
|
||||
|
|
|
@ -28,6 +28,18 @@ class NoReset(Reset):
|
|||
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 #
|
||||
# everytime a modal closes, run 100ms later model.modal = []
|
||||
# this is done to achieve nice close animation
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -13,6 +13,9 @@ class View:
|
|||
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
|
||||
new_vdom = self._view()
|
||||
|
|
Loading…
Reference in New Issue
Block a user