Commit 8713a26f authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Manage GUI launching in cli.py, handle CLI ctrl-C

When starting GUI from CLI, the user may stop it with a keyboard
interrupt. We treat this as equivalent to quitting the application
through the GUI, therefore the interrupt is caught and handled
accordingly.

The implementation required to move some launching code from
"gui.py" to "cli.py", which enabled the reuse of some CLI
methods (_start and _shutdown).
parent cef8c2ca
......@@ -449,4 +449,23 @@ class AgkyraCLI(cmd.Cmd):
"""
if self.must_help('gui'):
return
gui.run(callback=self.callback, debug=self.args.debug)
session = self.helper.load_active_session()
if not session:
self._start('')
session = self.helper.wait_session_to_load()
if session:
LOGGER.info('Start new GUI')
new_gui = gui.GUI(session, debug=self.args.debug)
try:
new_gui.start()
except KeyboardInterrupt:
LOGGER.info('GUI interrupted by user')
sys.stderr.write('GUI interrupted by user, exiting\n')
sys.stderr.flush()
new_gui.clean_exit()
LOGGER.info('GUI is shutdown')
if self.client:
self._shutdown('')
else:
sys.stderr.write('Session failed to load\n')
sys.stderr.flush()
......@@ -101,24 +101,3 @@ class GUI(WebSocketBaseClient):
finally:
self.clean_exit()
LOG.debug('GUI finished, close GUI wrapper connection')
def run(callback, debug):
"""Prepare SessionHelper and GUI and run them in the proper order"""
launch_server(callback, debug)
LOG.info('Client blocks until session is ready')
session = SessionHelper().wait_session_to_load()
assert session, 'UI server failed to load...'
LOG.info('Server session is ready, setup the GUI session')
gui = GUI(session, debug=debug)
try:
LOG.info('Start GUI')
gui.start()
except KeyboardInterrupt:
LOG.info('Shutdown GUI')
gui.clean_exit()
if __name__ == '__main__':
logging.basicConfig(filename='agkyra.log', level=logging.DEBUG)
run(os.path.abspath('gui/app'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment