Skip to content

Tutorial: How to create a new GUI in NEURON UI from Python

Adrian Quintana edited this page Feb 14, 2017 · 5 revisions

To create a new GUI (panel + widgets), simply import the neuron_utils library that ships with GeppetoJupyter and make use of neuron_utils utility functions to create panel/s and widgets/s elements (various input fields as needed) and add panel elements to them.

Examples of this in action can be seen on run_control.py, cell_builder.py and point_process.py.

Creating a Panel

Panel elements can be buttons, checkbox, labels, text and dropdown fields and even other panels, and can be configured to execute NEURON commands in response to user actions.

A basic example of how to create a simple button with neuron_util and associate an action to the click event is shown below:

stopButton = neuron_utils.add_button('Stop')

stopButton.on_click(['h.stoprun = 1'])

Alternatively the event handler can be passed via init parameters in the following fashion:

singleStepButton = neuron_utils.add_button('Single Step', execute_neuron_command, extraData={'commands': ['h.steprun()']})

In the code above execute_neuron_command is a custom defined callback handler in charge of running commands upon user events (default user event for buttons is of course the click event), see run_control.py for an implementation example.

A panel can also be embedded in another panel A wide range of properties, such as position, dimensions and layout, can be configured in a panel. By default, panel displays element in a column layout although direction can be set to row layout.

Displaying the panel/s

A panel can then be initialized with panel items in the following way:

runControlPanel = neuron_utils.add_panel('Run Control', items=[self.stopButton, self.singleStepButton, ...], widget_id='runControlPanel', position_x=700, position_y=150)

self.runControlPanel.display()

Creating a Widget

To add a widget a new library needs to be imported: from geppettoJupyter.geppetto_comm import GeppettoCoreAPI as G

Currently, only plot and popup widgets are accessible and they can be initialized in this way:

self.plotWidget = G.plotVariable('Plot', ['SimpleCell.v_vec_dend', 'SimpleCell.v_vec_soma'])
self.popupWidget = G.popupVariable('Popup', ['Just a message'])

Note that to be able to plot a variable, the variable has to be created in advance using the createStateVariable API (see related tutorial on how to work with your own model):

neuron_utils.createStateVariable(id='time', name='time',
                              units='ms', python_variable={"record_variable": self.t_vec,
                                                           "segment": None})
neuron_utils.createStateVariable(id='v_vec_dend', name='v_vec_dend',
                              units='mV', python_variable={"record_variable": self.v_vec_dend, "segment":self.dend(1.0)}  )

Others

Remember to specify as well what should be done when the panel is closed by creating a close method and link it with the panel:

self.runControlPanel.on_close(self.close)

def close(self, component, args):
        # Close Jupyter object
        self.runControlPanel.close()
        del self.runControlPanel

        # Destroy this class
        RunControl.delete()

If there can be only one instance of the panel on the screen you can add the @Singleton annotation at the top of the file.

Please refer to run_control.py, cell_builder.py and point_process.py for self-contained meaningful examples.

Clone this wiki locally