Setup.Inputs package
Submodules
Setup.Inputs.GetUserInput module
- class Setup.Inputs.GetUserInput.UserInput
Bases:
object
UserInput contains several methods for getting user input for POD device setup.
- static AskForBool(prompt: str) bool
Asks user for bool type input.
- Parameters:
prompt (str) – Statement requesting input from the user.
- Returns:
Boolean type input from user.
- Return type:
bool
- static AskForFloat(prompt: str) float
Asks user for float type input.
- Parameters:
prompt (str) – Statement requesting input from the user.
- Returns:
Float type input from user.
- Return type:
float
- static AskForFloatInList(prompt: str, goodInputs: list, badInputMessage: str | None = None) float
Asks the user for a float that exists in the list of valid options.
- Parameters:
prompt (str) – Statement requesting input from the user.
goodInputs (list) – List of valid input options.
badInputMessage (str | None, optional) – Error message to be printed if invalid input is given. Defaults to None.
- Returns:
User’s choice from the options list as a float.
- Return type:
float
- static AskForFloatInRange(prompt: str, minimum: float, maximum: float, thisIs: str = 'Input', unit: str = '') float
Asks the user for an float value that falls in a given range.
- Parameters:
prompt (str) – Statement requesting input from the user.
minimum (float) – Minimum value of range.
maximum (float) – Maximum value of range.
thisIs (str, optional) – Description of the input/what is being asked for. Used when printing the error message. Defaults to ‘Input’.
unit (str, optional) – Unit of the requested value. Use when printing the error message. Defaults to ‘’.
- Returns:
Float value given by the user that falls in the given range.
- Return type:
float
- static AskForInput(prompt: str, append: str = ': ') str
Asks user for input given a prompt. Will append a colon ‘:’ to the end of prompt by default
- Parameters:
prompt (str) – Statement requesting input from the user
append (str, optional) – Appended to the end of the prompt. Defaults to ‘: ‘.
- Returns:
String of the user input
- Return type:
str
- static AskForInt(prompt: str) int
Asks user for int type input.
- Parameters:
prompt (str) – Statement requesting input from the user.
- Returns:
Integer type input from user.
- Return type:
int
- static AskForIntInList(prompt: str, goodInputs: list, badInputMessage: str | None = None) int
Asks the user for an integer that exists in the list of valid options.
- Parameters:
prompt (str) – Statement requesting input from the user
goodInputs (list) – List of valid input options.
badInputMessage (str | None, optional) – Error message to be printed if invalid input is given. Defaults to None.
- Returns:
User’s choice from the options list as an integer.
- Return type:
int
- static AskForIntInRange(prompt: str, minimum: int, maximum: int, thisIs: str = 'Input', unit: str = '') int
Asks the user for an integer value that falls in a given range.
- Parameters:
prompt (str) – Statement requesting input from the user.
minimum (int) – Minimum value of range.
maximum (int) – Maximum value of range.
thisIs (str, optional) – Description of the input/what is being asked for. Used when printing the error message. Defaults to ‘Input’.
unit (str, optional) – Unit of the requested value. Use when printing the error message. Defaults to ‘’.
- Returns:
Integer value given by the user that falls in the given range.
- Return type:
int
- static AskForStrInList(prompt: str, goodInputs: list, badInputMessage: str | None = None) str
Asks the user for a string that exists in the list of valid options.
- Parameters:
prompt (str) – Statement requesting input from the user.
goodInputs (list) – List of valid input options
badInputMessage (str | None, optional) – Error message to be printed if invalid input is given. Defaults to None.
- Returns:
User’s choice from the options list as a string.
- Return type:
str
- static AskForType(typecast: function, prompt: str) int | float | str
Ask user for input of a specific data type. If invalid input is given, an error message will print and the user will be prompted again.
- Parameters:
typecast (function) – Datatype to cast the user input (ex. _CastInt, _CastFloat, _CastStr)
prompt (str) – Statement requesting input from the user
- Returns:
Input from user as the requested type.
- Return type:
int|float|str
- static AskForTypeInList(typecast: function, prompt: str, goodInputs: list, badInputMessage: str | None = None) int | float | str
Asks the user for a value of a given type that exists in the list of valid options. If invalid input is given, an error message will print and the user will be prompted again.
- Parameters:
typecast (function) – Datatype to cast the user input (ex. _CastInt, _CastFloat, _CastStr).
prompt (str) – Statement requesting input from the user.
goodInputs (list) – List of valid input options.
badInputMessage (str | None, optional) – Error message to be printed if invalid input is given. Defaults to None.
- Returns:
User’s choice from the goodInputs list as the given datatype.
- Return type:
int|float|str
- static AskForTypeInRange(typecast: function, prompt: str, minimum: int | float, maximum: int | float, thisIs: str = 'Input', unit: str = '') int | float
Asks user for a numerical value that falls between two numbers. If invalid input is given, an error message will print and the user will be prompted again.
- Parameters:
typecast (function) – Datatype to cast the user input (ex. _CastInt, _CastFloat, _CastStr).
prompt (str) – Statement requesting input from the user.
minimum (int | float) – Minimum value of range.
maximum (int | float) – Maximum value of range.
thisIs (str, optional) – Description of the input/what is being asked for. Used when printing the error message. Defaults to ‘Input’.
unit (str, optional) – Unit of the requested value. Use when printing the error message. Defaults to ‘’.
- Returns:
Numerical value given by the user that falls in the given range.
- Return type:
int|float
- static AskYN(question: str, append: str = ' (y/n): ') bool
Asks the user a yes or no question. If invalid input is given, an error message will print and the user will be prompted again.
- Parameters:
question (str) – Statement requesting input from the user.
append (str, optional) – Appended to the end of the question. Defaults to ‘ (y/n): ‘.
- Returns:
True for yes, false for no.
- Return type:
bool
- static CastFloat(value) float
Casts the argument as an float.
- Parameters:
value – Value to type casted.
- Returns:
Value type casted as a float.
- Return type:
float
- static CastInt(value) int
Casts the argument as an integer.
- Parameters:
value – Value to type casted.
- Returns:
Value type casted as an integer.
- Return type:
int
- static CastStr(value) str
Casts the argument as an string.
- Parameters:
value – Value to type casted.
- Returns:
Value type casted as a string.
- Return type:
str
- static CheckFileExt(f: str, fIsExt: bool = True, goodExt: list[str] = ['.txt'], printErr: bool = True) bool
Checks if a file name has a valid extension.
- Parameters:
f (str) – file name or extension
fIsExt (bool, optional) – Boolean flag that is true if f is an extension, false otherwise. Defaults to True.
goodExt (list[str], optional) – List of valid file extensions. Defaults to [‘.txt’,].
printErr (bool, optional) – Boolean flag that, when true, will print an error statement. Defaults to True.
- Returns:
True if extension is in goodExt list, False otherwise.
- Return type:
bool
- static GetFileName(goodExt: list[str] = ['.txt']) str
Asks the user for a filename. :param goodExt: List of valid file extensions. Defaults to [‘.txt’]. :type goodExt: list[str], optional
- Returns:
String of the file name and extension.
- Return type:
str
- static GetFilePath(prompt: str | None = None, goodExt: list[str] = ['.txt']) str
Asks the user for a file path and file name.
- Parameters:
prompt (str | None, optional) – Text to print to the user before requesting the path. Defaults to None.
goodExt (list[str], optional) – List of valid file extensions. Defaults to [‘.txt’].
- Returns:
File path and name.
- Return type:
str