33from gi .repository import Gio
44
55# GSettings path destkop/ibus/keyman/options
6- GSETTINGS_BASE = " com.keyman.options"
6+ GSETTINGS_BASE = ' com.keyman.options'
77
88# Utilities to get and set Keyman options in GSettings:
99# /desktop/ibus/keyman/options/packageID/keyboardID/options
1010
1111
1212def get_child_schema (info ):
13+ if 'packageID' not in info or 'keyboardID' not in info or not info ['packageID' ] or not info ['keyboardID' ]:
14+ return None
15+
1316 settings = Gio .Settings .new (GSETTINGS_BASE )
1417 path = settings .get_property ('path' )
1518 if not path .endswith ('/' ):
1619 path += '/'
1720 path += info ['packageID' ] + '/' + info ['keyboardID' ] + '/'
18- return Gio .Settings (f'{ GSETTINGS_BASE } .child' , path )
21+ return Gio .Settings . new_with_path (f'{ GSETTINGS_BASE } .child' , path )
1922
2023
2124def get_option (info ):
@@ -32,10 +35,10 @@ def get_option(info):
3235 result (dictionary): Keyboard options
3336 """
3437 result = {}
35- if " packageID" in info and " keyboardID" in info :
36- child_schema = get_child_schema (info )
37- list_options = child_schema .get_strv (" options" )
38- result = dict (option .split ("=" ) for option in list_options )
38+ if ' packageID' in info and ' keyboardID' in info :
39+ if child_schema : = get_child_schema (info ):
40+ list_options = child_schema .get_strv (' options' )
41+ result = dict (option .split ("=" ) for option in list_options )
3942 return result
4043
4144
@@ -50,11 +53,11 @@ def set_option(info, options):
5053 options: dictionary
5154 key and values to store
5255 """
53- if " packageID" in info and " keyboardID" in info and options :
56+ if ' packageID' in info and ' keyboardID' in info and options :
5457 # Convert dictionary of options into a list of option strings
55- list_options = [f" { key } ={ value } " for key , value in options .items ()]
56- child_schema = get_child_schema (info )
57- child_schema .set_strv (" options" , list_options )
58+ list_options = [f' { key } ={ value } ' for key , value in options .items ()]
59+ if child_schema : = get_child_schema (info ):
60+ child_schema .set_strv (' options' , list_options )
5861
5962
6063if __name__ == '__main__' :
0 commit comments