GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri May 24, 2013 12:05 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Example using GSettings in Python and Gtk3
PostPosted: Mon May 09, 2011 1:47 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
From Using GSettings with Python/PyGObject...

Syntax: [ Download ] [ Hide ]
Using python Syntax Highlighting
# 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

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group