UI Module

Widget Groups

Tab

class hublib.ui.Tab(wlist[, titles=None])

Creates a tabbed dialog containing wlist, the list of widgets. The name of each widget will appear in the tabs.

Parameters:
  • wlist – A list of widgets that make up the form.
  • titles – An optional list of titles for the tabs. If None, the names of the widgets in wlist will be used.

Attributes:

disabled

Set to True to disable all the contained widgets.

>>> f = ui.Tab([form1, form2])

Form

class hublib.ui.Form(wlist[, name="", desc="", disabled=False, width=None])

A form is a vertically-stacked list of widgets grouped together.

Parameters:
  • wlist – A list of widgets that make up the form.
  • name – The name of the form. Will appear in a tab or label if the form is put in another Form or Tab.
  • desc – An optional description that will appear in a popover dialog.
  • disabled – The initial state of the form. Defaults to False.
  • width – Optional width of the form as a percent string (for example, ‘50%’). Default is None which sets the width automatically to contain all the widgets.

Attributes:

desc

The form description.

disabled

Set to True to disable all the contained widgets.

name

The form name.

visible

Set to False to hide the form.

width

The form width.

>>> f = ui.Form([checkbox1, checkbox2, num1, string1], name="My Parameters")

Numerical Widgets

Number

class hublib.ui.Number(name, value[, cb=None, desc='', disabled=False, units=None, width='auto', min=None, max=None])

A text field that contains a floating point number with optional units and optional minimum and maximum. Units are converted and min and max checked dynamically.

Parameters:
  • name – The name that will appear in the field.
  • value – The initial value.
  • cb – An optional callback function.
  • desc – An optional description. This will appear in a popover dialog along with unit and min and max values when available.
  • disabled – The initial state of the form. Defaults to False.
  • units – A string containing an abbreviation or full name for the unit of measurement.
  • width – Optional width of the form as a percent string (for example, ‘50%’). Default sets the width automatically to contain all the widgets.
  • min
  • max – Minimum and maximum values. If a string, may contain units. Otherwise units will be assumed to be the same as those set by the units parameter.
Attributes:
Attributes are parameters that may be modified or read after the object is created. Unless noted, attributes are read/write.
desc
disabled

Set to True to disable the widget.

max
min
name
str

Read-only. The value as a string, including units. For example “5.2 m”

value

When read, the value expressed as a floating point number.

When writing, you can set the value to any expression that can be converted to the proper units. Bad units or values outside the permitted min/max values will cause an exception.

visible

Set to False to hide the widget.

width
>>> e1 = ui.Number(
    name='E1',
    description="Longitudinal Young's Modulus",
    units='GPa',
    min=0,
    max=500,
    value='138 GPa',
    width='20%'
)
_images/number.gif

Integer

class hublib.ui.Integer(name, value[, cb=None, desc='', disabled=False, width='auto', min=None, max=None])

A text field that contains an integer with optional minimum and maximum. Min and max are checked dynamically.

Parameters:
  • name – The name that will appear in the field.
  • value – The initial value.
  • cb – An optional callback function.
  • desc – An optional description. This will appear in a popover dialog along with min and max values when available.
  • disabled – The initial state of the form. Defaults to False.
  • width – Optional width of the form as a percent string (for example, ‘50%’). Default sets the width automatically to contain all the widgets.
  • min
  • max – Minimum and maximum values.
Attributes:
Attributes are parameters that may be modified or read after the object is created. Unless noted, attributes are read/write.
desc
disabled

Set to True to disable the widget.

max
min
name
str

Read-only. The value as a string, including units. For example “5.2 m”

value

When read, the integer value.

When writing, values outside the permitted min/max values will cause an exception.

visible

Set to False to hide the widget.

width
>>> loops = ui.Integer(
    name='Loops',
    description="Number of Loops to Run",
    min=0,
    max=500,
    value=12,
    width='20%'
)
_images/integer.png

Input Widgets

Checkbox

class hublib.ui.Checkbox(name, desc, value[, cb=None, disabled=False, width='auto'])
>>> check = ui.Checkbox('Advanced Options', 'Show the Advanced Options', value=False, width='50%')
print check.value
False

Radiobuttons

class hublib.ui.Radiobuttons(name, desc, options, value[, cb=None, disabled=False, width='auto'])
>>> r = ui.Radiobuttons(
        name='Nut',
        description="Type of nut to eat.",
        value='almond',
        options=['peanut', 'walnut', 'almond', 'pecan'],
        width='20%'
    )
print r.value
'almond'

Togglebuttons

class hublib.ui.Togglebuttons(name, desc, options, value[, cb=None, disabled=False, width='auto'])

Creates a horizontal bar of buttons. Only one can be selected.

Parameters:
  • name – The name that will appear in the field.
  • desc – An optional description. This will appear in a popover dialog.
  • options – A list of strings or dictionay of strings with values.
  • value – The initial value.
  • cb – An optional callback function.
  • disabled – The initial state of the form. Defaults to False.
  • width – Optional width of the form as a percent string (for example, ‘50%’). Default sets the width automatically to contain all the widgets.
Attributes:
Attributes are parameters that may be modified or read after the object is created. Unless noted, attributes are read/write.
disabled

Set to True to disable the widget.

value
visible

Set to False to hide the widget.

width
>>> tb = ui.Togglebuttons(
        name='Nut',
        description="Type of nut to eat.",
        value='almond',
        options=['peanut', 'walnut', 'almond', 'pecan'],
        width='20%'
    )
>>> tb.value
'almond'

or using a dictionary:

>>> tb = ui.Togglebuttons(
        name='Nut',
        description="Type of nut to eat.",
        value=2,
        options={'peanut':1, 'walnut':2, 'almond':3, 'pecan':4},
        width='20%'
    )
>>> tb.value
2
_images/togglebuttons.png

String

class hublib.ui.String(name, desc, value=''[, cb=None, disabled=False, width='auto'])

A single-line text input box.

>>> xstr = ui.String(name="Name", description='Name (First and Last)', value='<name>')
>>> print xstr.value
<name>

Text

class hublib.ui.Text(name, desc, value=''[, cb=None, disabled=False, width='auto'])

A multi-line text input box.

>>> xtxt = ui.Text(name="Description",
                   description='Experiment Description',
                   value='Starting Content')
>>> print xtxt.value
Starting Content

Download

class hublib.ui.Download(filename, **kwargs)

A button that downloads a remote file to the browser.

Parameters:
  • filename – The file that will be downloaded.
  • label – The label on the button. Default is the filename.
  • icon – Optional icon name. Must be from http://fontawesome.io/icons/
  • tooltip – An optional tooltip.
  • style – Default is ‘’. Supported values are “success”, “info”, “warning”, and “danger”.
  • cb – Optional callback function.

File Upload

class hublib.ui.FileUpload(name, desc[, dir='tmpdir', maxnum=1, maxsize='1M', cb=None, width='auto'])

A button that opens a file browser on your computer that allows you to upload a single or multiple files.

Parameters:
  • name – The name that will appear in the field.
  • desc – Description. This will appear in a popover dialog.
  • dir – The subdirectory name whene the files will be uploaded. Defaults to ‘tmpdir’
  • cb – An optional callback function called when the upload completes. cb() will be called with a two parameters; a widget reference and the filename that has finished uploading.
  • maxnum – Maximum number of files to be selected. Default is 1.
  • maxsize – Maximum size of uploaded files. String or integer. Strings contain numbers optionally followed by ‘M’, ‘K’, or ‘G’. For example ‘2G’. Files selected larger than this number will not be uploaded and an error will be displayed to stderr. Default is ‘1M’.
  • basic – Boolean (default False). No name or description. Just a basic upload widget. Progress bar appears to the right of the widget when uploading.
  • width – Optional width as a percent string (for example, ‘50%’).
Attributes:
Attributes are parameters that may be modified or read after the object is created. Unless noted, attributes are read/write.
visible

Set to False to hide the widget.

_images/fileupload.png
list()

Returns a list of filenames that were uploaded.

>>> f.list()
['quote1.txt', 'quote2.txt']
reset()

Clears the filename(s) and progress bar(s). Re-enables the widget to allow more files to be selected for uploading.

>>> # called when all files finish uploading
>>> def done_cb(w, name):
>>>    print("%s downloaded" % name)
>>>    w.reset()
>>>
>>> # this will allow you to select a single file to be uploaded
>>> f = FileUpload("Really Interesting File",
       "This is a description that appears when the mouse hovers over the name.",
        cb=done_cb)
>>> display(f)

ListManager

class hublib.ui.ListManager(value=[], button_text='Add', list_text='New Value...')

A list manager widget. Allows adding and removing items from a list.

Parameters:
  • body – The text for the dialog body.
  • title – The title for the dialog.
  • buttons – A list of button labels.
  • primary – The name or the index of the default button. It will be highlighted.
  • cb – Optional callback function.
Attributes:
Attributes are parameters that may be modified or read after the object is created. Unless noted, attributes are read/write.
value

Sets or gets the values in the widgets’s list.

visible

Set to False to hide the widget.

width
>>> initial_list = ['Hydrogen', 'Helium', 'Lithium']
>>> lm = ListManager(value = initial_list, list_text='Element..', button_text='', cb=LMCB)
>>> print(lm.value)
['Hydrogen', 'Helium', 'Lithium']
_images/listmanager.gif

RunAllButton

class hublib.ui.RunAllButton(label='Run All Cells', icon='', tooltip='', style='', cb=None, hide=False)

A button that runs all the code cells.

Parameters:
  • label – The text for button.
  • icon – Optional icon name. Must be from http://fontawesome.io/icons/
  • tooltip – optional tooltip.
  • style – Default is ‘’. Supported values are “success”, “info”, “warning”, and “danger”.
  • cb – Optional callback function.
  • hide – If True, hide code cells.

HideCodeButton

class hublib.ui.HideCodeButton(label, icon='', tooltip='', style='', cb=None)

A button that hides all the code cells.

Parameters:
  • label – The text for button. It can be a string or a list of two strings. The default is [‘Hide Code Cells’, ‘Show Code Cells’]
  • icon – Optional icon name. Must be from http://fontawesome.io/icons/
  • tooltip – optional tooltip.
  • style – Default is ‘’. Supported values are “success”, “info”, “warning”, and “danger”.
  • cb – Optional callback function.

PathSelector

class hublib.ui.PathSelector(start_dir, select_file=True)

The PathSelector widget allows the user to choose a path in the server (container). It cannot access files from the user’s computer.

Parameters:
  • start_dir – The directory to display.
  • select_file – True for file select. False for directory select.

RunCommand

class hublib.ui.RunCommand(label='Run', tooltip='Run Simulation', start_func=None, done_func=None, outcb=None, width='auto', cachename=None, cachedir=None, cachecb=None, showcache=True)

A widget to run a Linux command and monitor progress.

Use this to run external code locally that might take a couple of minutes. Results are optionally cached.

If you are using ‘submit’ on a hub, you should use the Submit widget.

Parameters:
  • label – The label for the start button.
  • tooltip – The tooltip for the start button.
  • start_func – Required. Function to be called when the start button is pressed.
  • done_func – Optional function to be called when the command is completed.
  • outcb – Optional function to be called when standard output is received. Any returned value is written to the submit output widget, otherwise that widget will be empty when this is used.
  • cachename – Optional. Name of the tool or other unique name that will be used for the cache directory.
  • cachecb – Optional function to call when the cache is cleared.
  • width – Default is ‘auto’.
run(cmd, runname=None)

Starts the command.

Parameters:
  • cmd – The Linux shell command to run.
  • runname – (Optional) Name for the results. Required when caching is enabled.

Submit

class hublib.ui.Submit(label='Run', tooltip='Run Simulation', start_func=None, done_func=None, outcb=None, show_progress=True, width='auto', cachename=None, cachecb=None, showcache=True)

A widget to run the submit command and monitor progress. Includes optional local caching of results.

Parameters:
  • label – The label for the start button.
  • tooltip – The tooltip for the start button.
  • start_func – Required. Function to be called when the start button is pressed.
  • done_func – Optional function to be called when the submit function is completed.
  • cachename – Optional. Name of the tool or other unique name that will be used for the cache directory.
  • cachecb – Optional function to call when the cache is cleared.
  • outcb – Optional function to be called when standard output is received. Any returned value is written to the submit output widget, otherwise that widget will be empty when this is used.
  • show_progress – Show progress bar? Default is True.
  • width – Default is ‘auto’.
make_rname(*args)

Creates a unique directory name given a variable number of input arguments.

Returns:A long string which is guaranteed to be a unique directory in ~/data/results/.submit_cache/${cachename}
run(runname, cmd)

Starts the submit command.

Parameters:
  • runname – Name for the results.
  • cmd – The command to pass along to the command-line submit. Do not include runName or progress.

Submit() can cache results. If cachename is not None, it must be a unique name for the tool or notebook. A user directory will be created for storing results in ~/data/results/.submit_cache/${cachename} Each run will need a unique name, runname. The developer is responsible for generating this. For very simple cases, the runs can be simply named, like “run1”, or “volt5cap6”. However, submit requires alphanumeric characters only, so no dashes, underscores or periods. This makes naming challenging. To assist with this, Submit includes a handy method, make_rname(). make_rname() takes a variable number or args of any type and produces a unique runname.

For more information, see the example notebooks.