refactor(linux): Fix warning

Follow-up of #4999 (which mentions different warnings). This
change fixes other warnings that we were still getting.
This commit is contained in:
Eberhard Beilharz 2023-08-28 19:24:48 +02:00
parent 2673d2e4d9
commit ea249da3b3
No known key found for this signature in database
GPG key ID: E9140597606020D3

View file

@ -3,19 +3,22 @@
from gi.repository import Gio
# GSettings path destkop/ibus/keyman/options
GSETTINGS_BASE = "com.keyman.options"
GSETTINGS_BASE = 'com.keyman.options'
# Utilities to get and set Keyman options in GSettings:
# /desktop/ibus/keyman/options/packageID/keyboardID/options
def get_child_schema(info):
if 'packageID' not in info or 'keyboardID' not in info or not info['packageID'] or not info['keyboardID']:
return None
settings = Gio.Settings.new(GSETTINGS_BASE)
path = settings.get_property('path')
if not path.endswith('/'):
path += '/'
path += info['packageID'] + '/' + info['keyboardID'] + '/'
return Gio.Settings(f'{GSETTINGS_BASE}.child', path)
return Gio.Settings.new_with_path(f'{GSETTINGS_BASE}.child', path)
def get_option(info):
@ -32,10 +35,10 @@ def get_option(info):
result (dictionary): Keyboard options
"""
result = {}
if "packageID" in info and "keyboardID" in info:
child_schema = get_child_schema(info)
list_options = child_schema.get_strv("options")
result = dict(option.split("=") for option in list_options)
if 'packageID' in info and 'keyboardID' in info:
if child_schema := get_child_schema(info):
list_options = child_schema.get_strv('options')
result = dict(option.split("=") for option in list_options)
return result
@ -50,11 +53,11 @@ def set_option(info, options):
options: dictionary
key and values to store
"""
if "packageID" in info and "keyboardID" in info and options:
if 'packageID' in info and 'keyboardID' in info and options:
# Convert dictionary of options into a list of option strings
list_options = [f"{key}={value}" for key, value in options.items()]
child_schema = get_child_schema(info)
child_schema.set_strv("options", list_options)
list_options = [f'{key}={value}' for key, value in options.items()]
if child_schema := get_child_schema(info):
child_schema.set_strv('options', list_options)
if __name__ == '__main__':