Preferences
- class wpilib.Preferences
Bases:
pybind11_objectThe preferences class provides a relatively simple way to save important values to the roboRIO to access the next time the roboRIO is booted.
This class loads and saves from a file inside the roboRIO. The user cannot access the file directly, but may modify values at specific fields which will then be automatically periodically saved to the file by the NetworkTable server.
This class is thread safe.
This will also interact with NetworkTable by creating a table called “Preferences” with all the key-value pairs.
- static contains_key(key: str) bool
Returns whether or not there is a key with the given name.
- Parameters:
key – the key
- Returns:
if there is a value at the given key
- static get_boolean(key: str, default_value: bool = False) bool
Returns the boolean at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static get_double(key: str, default_value: SupportsFloat | SupportsIndex = 0.0) float
Returns the double at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static get_float(key: str, default_value: SupportsFloat | SupportsIndex = 0.0) float
Returns the float at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static get_int(key: str, default_value: SupportsInt | SupportsIndex = 0) int
Returns the int at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static get_keys() list[str]
Returns a vector of all the keys.
- Returns:
a vector of the keys
- static get_long(key: str, default_value: SupportsInt | SupportsIndex = 0) int
Returns the long (int64_t) at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static get_string(key: str, default_value: str = '') str
Returns the string at the given key. If this table does not have a value for that position, then the given defaultValue will be returned.
- Parameters:
key – the key
default_value – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static init_boolean(key: str, value: bool) None
Puts the given boolean into the preferences table if it doesn’t already exist.
- static init_double(key: str, value: SupportsFloat | SupportsIndex) None
Puts the given double into the preferences table if it doesn’t already exist.
- static init_float(key: str, value: SupportsFloat | SupportsIndex) None
Puts the given float into the preferences table if it doesn’t already exist.
- static init_int(key: str, value: SupportsInt | SupportsIndex) None
Puts the given int into the preferences table if it doesn’t already exist.
- static init_long(key: str, value: SupportsInt | SupportsIndex) None
Puts the given long into the preferences table if it doesn’t already exist.
- static init_string(key: str, value: str) None
Puts the given string into the preferences table if it doesn’t already exist.
- static remove(key: str) None
Remove a preference.
- Parameters:
key – the key
- static remove_all() None
Remove all preferences.
- static set_boolean(key: str, value: bool) None
Puts the given boolean into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static set_double(key: str, value: SupportsFloat | SupportsIndex) None
Puts the given double into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static set_float(key: str, value: SupportsFloat | SupportsIndex) None
Puts the given float into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static set_int(key: str, value: SupportsInt | SupportsIndex) None
Puts the given int into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static set_long(key: str, value: SupportsInt | SupportsIndex) None
Puts the given long (int64_t) into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static set_string(key: str, value: str) None
Puts the given string into the preferences table.
The value may not have quotation marks, nor may the key have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value