# Example using GSettings in Python and Gtk3
# Full description at http://www.micahcarrick.com/gsettings-p ... ome-3.html
from gi.
repository import Gio, Gtk
class App
(object):
BASE_KEY =
"apps.gsettings-example-py"
def __init__(self):
# setup a check button and associate it with a GSettings key
settings = Gio.
Settings.
new(self.
BASE_KEY)
check_button = Gtk.
CheckButton("This is my boolean setting")
check_button.
set_active(settings.
get_boolean("my-setting"))
settings.
connect("changed::my-setting",
self.
on_my_setting_changed, check_button
)
check_button.
connect('toggled',
self.
on_check_button_toggled, settings
)
# main window
window = Gtk.
Window(type=Gtk.
WindowType.
TOPLEVEL)
window.
set_title('GSettings Example')
window.
set_border_width(24)
window.
connect_after('destroy',
self.
on_window_destroy)
window.
add(check_button
)
window.
show_all()
Gtk.
main()
def on_my_setting_changed
(self, settings, key, check_button
):
check_button.
set_active(settings.
get_boolean("my-setting"))
def on_check_button_toggled
(self, button, settings
):
settings.
set_boolean("my-setting", button.
get_active())
def on_window_destroy
(self, widget, data=
None):
Gtk.
main_quit()
if __name__ ==
"__main__":
app = App
()Parsed in 0.017 seconds, using
GeSHi 1.0.8.4