Added bool support to WinConfig

This commit is contained in:
A_D authored and Athanasius committed 2021-04-01 14:45:45 +01:00
1 parent 82fc4b56f7
commit 9e1bb0a2a2
1 file changed
+20 -1
+20 -1
View File
@@ -419,7 +419,22 @@ class WinConfig(AbstractConfig):
return res
def set(self, key: str, val: Union[int, str, List[str]]) -> None:
def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]:
"""
Return the bool found at the given key, or the default if none exists.
:param key: The key to access
:param default: Default to return when key does not exist, defaults to None
:raises ValueError: If the data returned is of an unexpected type
:return: The data requested or the default
"""
res = self.get_int(key)
if res is None:
return default
return bool(res)
def set(self, key: str, val: Union[int, str, List[str], bool]) -> None:
"""
Set sets the given key to the given value.
@@ -439,6 +454,10 @@ class WinConfig(AbstractConfig):
elif isinstance(val, list):
reg_type = winreg.REG_MULTI_SZ
elif isinstance(val, bool):
reg_type = winreg.REG_DWORD
val = int(val)
else:
raise ValueError(f'Unexpected type for value {type(val)=}')