Inputbox#
- squap.add_inputbox(
- name,
- init_value=1.0,
- type_func=None,
- var_name=None,
- print_value=False,
- row=None,
Adds a
inputboxto the main input widget, or to allinput tablesif 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,setandNone. Iftype_funcis set toNone(default value), then it will be set toast.literal_eval()ifinit_valueis one of the mentioned data types. Ifinit_valueis anumpy.ndarrayor arangeobject, this is also handled, buttype_funcneeds to be explicitly changed toast.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 thatast.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 settingtype_func=float.type_funccan also be set toint, so that each value is turned into anint. Iftype_funcis not given, it is automatically determined, which works for the following instances:str,float,complex,bool,range, and the following iterables:tuple,list,dict,setandnumpy.ndarray.var_name (str, optional) – The name of the created variable. If
var_nameis not provided, the variable will be namedname.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:
- class squap.widgets.InputTable.InputBox#
- InputBox.bind(func)#
Bind function
functo 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 tovalue, 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, exceptinit_valueandrow.
- InputBox.refresh_type_func(value)#
Updates the type function so that
valuewould parse successfully.
- InputBox.print_val()#
Print the current value of the box. Used for the
print_valuekeyword argument.
- InputBox.remove()#
Remove this box.