def _get_keyfile(): """Load keyfile from CONFIG_FILE Returns: keyfile containing settings """ _keyfile = GLib.KeyFile() try: _keyfile.load_from_file(CONFIG_FILE, GLib.KeyFileFlags.KEEP_COMMENTS) except GLib.Error as error: error_message(error) finally: return _keyfile
def get_integer(self, key) -> int: """Return integer value of the key setting Args: key: the name of the setting containing the integer value to be retrieved Returns: the value associated with the key as an integer, or 0 if the key was not found or could not be parsed. """ keyfile = self._get_keyfile() try: result = keyfile.get_integer(SETTINGS_GROUP_NAME, key) except GLib.Error as error: error_message(error.message) result = 0 return result
def get_boolean(self, key) -> bool: """Return boolean value of the key setting Args: key: the name of the setting containing the boolean value to be retrieved Returns: the value associated with the key as a boolean, or False if the key was not found or could not be parsed. """ keyfile = self._get_keyfile() try: result = keyfile.get_boolean(SETTINGS_GROUP_NAME, key) except GLib.Error as error: error_message(error.message) result = False return result
def get_integer_list(self, key) -> [int]: """Return a list of integer values of the key setting Args: key: the name of the setting containing the list of integer values to be retrieved Returns: the values associated with the key as a list of integers, or an empty list [] if the key was not found or could not be parsed. The returned list of integers should be freed with GLib.free() when no longer needed. """ keyfile = self._get_keyfile() try: result = keyfile.get_integer_list(SETTINGS_GROUP_NAME, key) except GLib.Error as error: error_message(error.message) result = [0] return result
def set_integer_list(self, key, my_list): """ Associates a list of integer values with key. If key cannot be found then it is created. Args: key: key name my_list: an array of integer values Return: True if value is set, False otherwise """ keyfile = self._get_keyfile() result = False if all(isinstance(item, int) for item in my_list): try: keyfile.set_integer_list(SETTINGS_GROUP_NAME, key, my_list) keyfile.save_to_file(CONFIG_FILE) except GLib.Error as error: error_message(error.message) finally: result = True return result
def set_integer(self, key, value): """ Associates a new integer value with key. If key cannot be found then it is created. Args: key: key name value: an integer value Return: True if value is set, False otherwise """ keyfile = self._get_keyfile() result = False if isinstance(value, int): try: keyfile.set_integer(SETTINGS_GROUP_NAME, key, value) keyfile.save_to_file(CONFIG_FILE) except GLib.Error as error: error_message(error.message) finally: result = True return result
def test_error_message(self): """Error message popup.""" # Not much can happen here, if all attributes are set correctly it will # also run helpers.error_message("Test error", True)