Gio.Settings では、次を使用して再配置可能なスキーマを一覧表示できます
Gio.Settings.list_relocatable_schemas()
そして私は使用することができます
Gio.Settings.new_with_path(schema_id, path)
インスタンスを取得しGio.Settingsます。pathしかし、特定の に現在使用されているすべての値を取得するにはどうすればよいschema_idですか?
通常、スキーマには、設定の概念的なグローバル ツリーで設定が保存される場所を決定する固定パスがあります。ただし、スキーマは「再配置可能」、つまり固定パスを備えていない場合もあります。これは、スキーマが「アカウント」を記述していて、任意の数のアカウントを保存できるようにしたい場合などに便利です。
それだけじゃないのnew_with_path?アカウントに関連付けられた場所にスキーマを保存する必要がありますが、それは設定システムの責任ではありません。new_with_pathスキーマがアカウントに依存している場合だと思います。
詳細については、GSettingsSchemasを参照してください。これは、スキーマがプラグインの一部である場合の説明の例です。
残念ながら、Gio.Settings からはできません。
ここに 2 つのオプションがあります。
低レベルの構成システムであるdconf API を利用します。Python バインディングがないため (Python の質問だと推測します)、C とのバインディングに ctypes を使用することをお勧めします。再配置可能なスキーマのルート パスがわかっている場合は、以下のスニペット リストで使用できます。
import ctypes
from ctypes import Structure, POINTER, byref, c_char_p, c_int, util
from typing import List
class DconfClient:
def __init__(self):
self.__dconf_client = _DCONF_LIB.dconf_client_new()
def list(self, directory: str) -> List[str]:
length_c = c_int()
directory_p = c_char_p(directory.encode())
result_list_c = _DCONF_LIB.dconf_client_list(self.__dconf_client, directory_p, byref(length_c))
result_list = self.__decode_list(result_list_c, length_c.value)
return result_list
def __decode_list(self, list_to_decode_c, length):
new_list = []
for i in range(length):
# convert to str and remove slash at the end
decoded_str = list_to_decode_c[i].decode().rstrip("/")
new_list.append(decoded_str)
return new_list
class _DConfClient(Structure):
_fields_ = []
_DCONF_LIB = ctypes.CDLL(util.find_library("dconf"))
_DCONF_LIB.dconf_client_new.argtypes = []
_DCONF_LIB.dconf_client_new.restype = POINTER(_DConfClient)
_DCONF_LIB.dconf_client_new.argtypes = []
_DCONF_LIB.dconf_client_list.argtypes = [POINTER(_DConfClient), c_char_p, POINTER(c_int)]
_DCONF_LIB.dconf_client_list.restype = POINTER(c_char_p)