Commit af67a347 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'mnt/organise' into 'master'

Clean up python component

See merge request !1
parents c1545f35 71de6ce9
# fsl-gui-bet
# `fsl-bet-gui`
The GUI and websocket server for BET.
\ No newline at end of file
This repository contains the `fsl-bet-gui` project, which is the graphical
front-end for the FSL `bet` (Brain Extraction) utility.
The BET front-end is separated into two components:
- `bet_server` is a Python application which starts a HTTP server that can be
sent messages to invoke `bet`. The `bet_server` command is provided by the
`fsl-gui-bet` Python library, contained within the `python` sub-directory.
- The BET front-end is a [Vue.js](https://vuejs.org/) plugin which displays
the BET interface. It communicates with the `bet_server` process, and
allows the user to run BET and view the results. The BET front-end is
contained within the `javascript` sub-directory.
# FSL BET GUI server
This directory contains the `fsl-gui-bet` Python library, which provides the
`bet_server` command that runs the back-end for the BET GUI.
#!/usr/bin/env python
from fsl.gui.bet.bet import main
__version__ = '0.0.1'
#!/usr/bin/env python
#
# bet.py - The bet_server entry point.
#
import sys
import fsl.utils.run as run
import fsl.data.image as fslimage
import fsl.wrappers as wrappers
import fsl.gui.server as common
def set_input(sio, msg):
"""This handler is called when a message of type ``'input'`` is received.
When the user selects an input file, a default output file name is
generated and emitted via a message of type ``'output'``.
"""
infile = msg['filename']
outfile = fslimage.removeExt(infile) + '_brain'
sio.emit('output', {'filename' : outfile})
def run_bet(sio, msg):
"""This handler is called when a message of type ``'run'`` is received.
It expects to be passed all of the parameters required to run BET via the
:func:`fsl.wrappers.bet` function.
"""
cmd = wrappers.bet(**msg, v=True, cmdonly=True)
common.run_command(sio, cmd)
def main(argv=None):
"""Entry point. Starts the bet_server web server. Expects to be
given a HTTP port number to listen on as the sole command-line argument.
"""
if argv is None:
argv = sys.argv[1:]
port = int(argv[0])
handlers = {
'input' : set_input,
'run' : run_bet,
}
common.start_server(port, handlers)
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/env python
#
import sys
import socketio
import textwrap as tw
def main():
server_url = sys.argv[1]
infile = sys.argv[2]
sio = socketio.Client()
sio.connect(server_url)
def on_connect():
print(f'Connected - sending input file')
sio.emit('input', {'filename' : infile})
def on_output(data):
outfile = data['filename']
print(f'Received output event {data}')
sio.emit('run', {'input' : infile, 'output' : outfile})
def on_command(data):
print('Received command event:')
print(' ', data['command'])
def on_finished(data):
sio.disconnect()
print('Received finished event')
print(' code: ', data['exitcode'])
print(' stdout:')
print(tw.indent(data['stdout'], ' '))
print(' stderr:')
print(tw.indent(data['stderr'], ' '))
sio.on('connect', on_connect)
sio.on('output', on_output)
sio.on('command', on_command)
sio.on('finished', on_finished)
sio.wait()
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/env python
import os.path as op
from setuptools import setup, find_packages
basedir = op.dirname(__file__)
def read_version():
version = {}
with open(op.join(basedir, 'fsl', 'gui', 'bet', '__init__.py')) as f:
for line in f:
if line.startswith('__version__'):
exec(line, version)
break
return version['__version__']
def read_requirements():
return ['fsl-gui-core']
setup(name='fsl-gui-core',
description='',
author='',
version=read_version(),
packages=find_packages(),
install_requires=read_requirements(),
entry_points={'console_scripts' : {'bet_server = fsl.gui.bet:main'}})
Supports Markdown
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