def __present__(self, fragment): def on_execute_key(event, key): self.execute() return True def on_save_key(event, key): self._save_containing_document_and_display_notification(fragment) self.__incr.on_access() contents = [] for block in self.__blocks: contents.extend(['<div>', block, '</div>']) p = Html(*contents) p = p.with_key_handler([KeyAction(KeyAction.KEY_DOWN, 13, ctrl=True)], on_execute_key) p = p.with_key_handler([KeyAction(KeyAction.KEY_DOWN, ord('S'), ctrl=True, prevent_default=True)], on_save_key) return p.use_css('/static/larch/notebook.css')
def __present__(self, fragment): def on_execute(event): self.__console._execute_current_block(self) def on_execute_key(event, key): on_execute(event) return True code_area = Html('<div>', self.__code, '</div>') execute_button = button.button('Execute', on_execute) code_area_with_key_handler = code_area.with_key_handler( [KeyAction(KeyAction.KEY_DOWN, 13, ctrl=True)], on_execute_key) return Html('<div>', code_area_with_key_handler, execute_button, '</div>')