From 557ccfc2dba4ba0ebb639d12f103936551c76264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Mar 2018 16:04:33 +0200 Subject: [PATCH] Update event_handler_main to pre-baseimage split version --- solvable/src/demo/event_handler_main.py | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/solvable/src/demo/event_handler_main.py b/solvable/src/demo/event_handler_main.py index 8e43203..b6427ae 100644 --- a/solvable/src/demo/event_handler_main.py +++ b/solvable/src/demo/event_handler_main.py @@ -4,14 +4,47 @@ from tfw.components.source_code_event_handler import SourceCodeEventHandler from tfw.components.terminado_event_handler import TerminadoEventHandler from tfw.components.process_managing_event_handler import ProcessManagingEventHandler from tfw.config import TFWENV +from tfw.message_sender import MessageSender +from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.config.logs import logging log = logging.getLogger(__name__) +def cenator(history): + log.debug('User executed command: "{}"'.format(history[-1])) + MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.format(history[-1])) + + +def selectdir(history): + try: + cmd = history[-1].split() + if cmd[0] == 'selectdir': + ServerUplinkConnector().send_to_eventhandler('webide', + {'data': {'command': 'selectdir', + 'directory': cmd[1]}}) + except Exception: + log.exception('Selectdir failed!') + + +def toggle_next(history): + toggle_next.button_state = not toggle_next.button_state + try: + cmd = history[-1].split() + if cmd[0] == 'togglenext': + ServerUplinkConnector().send('messagecontrol', + {'data': {'command': 'showbutton', + 'next_visibility': toggle_next.button_state}}) + except Exception: + log.exception('Togglenext failed!') +toggle_next.button_state = False + + if __name__ == '__main__': - ide = SourceCodeEventHandler(key='webide', directory=TFWENV.WEBIDE_WD, exclude=['__pycache__']) + ide = SourceCodeEventHandler(key='webide', directory=TFWENV.WEBIDE_WD, exclude=['*.pyc']) terminado = TerminadoEventHandler(key='shell') - terminado.historymonitor.subscribe_callback(callback=lambda hist: log.debug('User executed command: "{}"'.format(hist[-1]))) + terminado.historymonitor.subscribe_callback(cenator) + terminado.historymonitor.subscribe_callback(selectdir) + terminado.historymonitor.subscribe_callback(toggle_next) processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor) eventhandlers = {ide, terminado, processmanager}