Commit 294388a5 authored by Roman Alifanov's avatar Roman Alifanov

GSettingsBackend: does not crash if the scheme is not found

parent 3e423c08
......@@ -4,36 +4,51 @@ from .base import Backend
class GSettingsBackend(Backend):
def _get_schema(self, schema_name):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(schema_name, True) is None:
print(f"[ERROR] Scheme {schema_name} is not installed")
return None
return Gio.Settings.new(schema_name)
def get_value(self, key, gtype):
schema_name, key_name = key.rsplit('.', 1)
schema = Gio.Settings.new(schema_name)
schema = self._get_schema(schema_name)
if not schema:
return None
print(f"[DEBUG] Получение значения: schema={schema_name}, key={key_name}, gtype={gtype}")
try:
value = schema.get_value(key_name)
return value.unpack()
except Exception as e:
print(f"[ERROR] Ошибка при получении значения {key}: {e}")
print(f"[ERROR] Error when getting the value {key}: {e}")
return None
def get_range(self, key, gtype):
schema_name, key_name = key.rsplit('.', 1)
schema = Gio.Settings.new(schema_name)
schema = self._get_schema(schema_name)
if not schema:
return None
print(f"[DEBUG] Получение значения: schema={schema_name}, key={key_name}, gtype={gtype}")
try:
value = schema.get_range(key_name)
return value.unpack()[1]
except Exception as e:
print(f"[ERROR] Ошибка при получении значения {key}: {e}")
print(f"[ERROR] Error when getting the range {key}: {e}")
return None
def set_value(self, schema_key, value, gtype):
schema_name, key_name = schema_key.rsplit('.', 1)
schema = Gio.Settings.new(schema_name)
schema = self._get_schema(schema_name)
if not schema:
return
print(f"[DEBUG] Установка значения: schema={schema_name}, key={key_name}, value={value}, gtype={gtype}")
try:
schema.set_value(key_name, GLib.Variant(gtype, value))
except Exception as e:
print(f"[ERROR] Ошибка при установке значения {schema_key}: {e}")
print(f"[ERROR] Error when setting the value {schema_key}: {e}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment