Inputbox#

squap.add_inputbox(
name,
init_value=1.0,
type_func=None,
var_name=None,
print_value=False,
row=None,
)[source]#

Adds a inputbox to the main input widget, or to all input tables if there are more.

Parameters:
  • name (str) – The name in front of the inputbox.

  • init_value (optional) – The initial value of the inputbox. Can be any object that can be turned into a string.

  • type_func (callable, optional) –

    The function that takes in a string and returns the value as the correct type. Usually, this will default to ast.literal_eval(), which works for a lot of data types: str, float, complex, bool, tuple, list, dict, set and None. If type_func is set to None (default value), then it will be set to ast.literal_eval() if init_value is one of the mentioned data types. If init_value is a numpy.ndarray or a range object, this is also handled, but type_func needs to be explicitly changed to ast.literal_eval() if the data type is changed during runtime. If you have a different data type that doesn’t work with the automatic behavior, a function can be passed to this argument that takes in a string and returns the desired value. Note that ast.literal_eval() is a lot slower than, for example, float, so if you are sure the input is a float, a minor speedup can be achieved by explicitly setting type_func=float.

    type_func can also be set to int, so that each value is turned into an int. If type_func is not given, it is automatically determined, which works for the following instances: str, float, complex, bool, range, and the following iterables: tuple, list, dict, set and numpy.ndarray.

  • var_name (str, optional) – The name of the created variable. If var_name is not provided, the variable will be named name.

  • print_value (bool) – Whether to print the value of the inputbox when it changes. Defaults to False.

  • row (int, optional) – Row to which the inputbox is added. Defaults to first empty row.

Returns:

The created inputbox widget(s).

Return type:

InputBox or list of InputBox

class squap.widgets.InputTable.InputBox#
InputBox.bind(func)#

Bind function func to this box, meaning that when the value of the box is changed, the function is called.

Parameters:

func (callable) – function to bind to this box.

InputBox.unbind(func)#

Unbind function. Is used internally when removing a box.

Parameters:

func (callable) – function to unbind from this box.

InputBox.set_value(value)#

Set the value of the box and var.var_name to value. Note that for a slider, the new slider position will be the closest possible position to value, and the new value of var.var_name will be the value corresponding to the new slider position.

InputBox.value()#

Return the current value of var.var_name

InputBox.change_params(**kwargs)#

Changes the parameters of the inputbox. Only keyword arguments are accepted, and takes all arguments that squap.add_inputbox() accepts, except init_value and row.

InputBox.refresh_type_func(value)#

Updates the type function so that value would parse successfully.

InputBox.print_val()#

Print the current value of the box. Used for the print_value keyword argument.

InputBox.remove()#

Remove this box.