Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know where I can find documentation on the Switch Widget on glade??

I tried finding on the GTK website, but it doesn't have an entry for it.


Thank you to Timo for pointing me in the right direction. I am loving askubuntu!.

Basically my problem was that the connect function by defualts pushes the Window's Object, The Widget's Object and the Active State to whichever function you run on the callback.

This is the before:

self.daymon.connect("notify::active", self.toggle_day("mon"))

And this is the after:

self.daymon.connect('notify::active', self.toggle_day, "mon")

The latter works like a charm when running the following function:

def toggle_day(self, widget, active, day):  
    if widget.get_active():  
        state = True  
        state = False  

Full code to follow should you be interested:

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# This file is in the public domain

import gettext
from gettext import gettext as _

from gi.repository import Gtk # pylint: disable=E0611
import logging
logger = logging.getLogger('snooze')

import ConfigParser, os # We need to be able to store and recal settings

from snooze_lib import Window
from snooze.AboutSnoozeDialog import AboutSnoozeDialog
from snooze.PreferencesSnoozeDialog import PreferencesSnoozeDialog

#first try to read the config.cfg file
config = ConfigParser.RawConfigParser()
configFile = 'data/config.cfg'
monState = False
tueState = False
wedState = False
thurState = False
friState = False
satState = False
sunState = False

# Creating the Config file
def createConfigFile(fileName):
    config.set('Preferences', 'mon', False)
    config.set('Preferences', 'tues', False)
    config.set('Preferences', 'wed', False)
    config.set('Preferences', 'thur', False)
    config.set('Preferences', 'fri', False)
    config.set('Preferences', 'sat', False)
    config.set('Preferences', 'sun', False)

# Writing our configuration file to the failename as specifeid
def rewriteConfigFile(filename):    
    with open(filename, 'wb') as configfile:

# Reading the config file 
def readConfigFile(fileName):
    print "READING CONFIG"
    global monState, tueState, wedState, thurState, friState, satState, sunState
    monState = config.getboolean('Preferences', 'mon')
    tueState = config.getboolean('Preferences', 'tues')
    wedState = config.getboolean('Preferences', 'wed')
    thurState = config.getboolean('Preferences', 'thur')
    friState = config.getboolean('Preferences', 'fri')
    satState = config.getboolean('Preferences', 'sat')
    sunState = config.getboolean('Preferences', 'sun')

# If the config does not exist, create it then read it. Otherwise read it
if not    

# See for more details about how this class works
class SnoozeWindow(Window):
    __gtype_name__ = "SnoozeWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(SnoozeWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutSnoozeDialog
        self.PreferencesDialog = PreferencesSnoozeDialog

        # Code for other initialization actions should be added here.
        self.daymon = self.builder.get_object("daymon")
        self.daytues = self.builder.get_object("daytues")
        self.daywed = self.builder.get_object("daywed")
        self.daythur = self.builder.get_object("daythur")
        self.dayfri = self.builder.get_object("dayfri")
        self.daysat = self.builder.get_object("daysat")
        self.daysun = self.builder.get_object("daysun")

        # Set the values based on the config file        
        if monState == True:

        if tueState == True:

        if wedState == True:

        if thurState == True:

        if friState == True:

        if satState == True:

        if sunState == True:

        self.daymon.connect('notify::active', self.toggle_day, "mon")
        self.daytues.connect('notify::active', self.toggle_day, "tues")
        self.daywed.connect('notify::active', self.toggle_day, "wed")
        self.daythur.connect('notify::active', self.toggle_day, "thur")
        self.dayfri.connect('notify::active', self.toggle_day, "fri")
        self.daysat.connect('notify::active', self.toggle_day, "sat")
        self.daysun.connect('notify::active', self.toggle_day, "sun")

    # Toggle the setting and store the information in the config file
    def toggle_day(self, widget, active, day):
        if widget.get_active():
            state = True
            state = False

        # Set the config option and update the config file
        global configFile
        config.set('Preferences', day, state)

share|improve this question
up vote 2 down vote accepted

Here you go:

Complete reference with all widgets and more useful info:

The GtkSwitch has only one signal, activate. You shouldn't directly connect to it according to the docs:

Applications should never connect to this signal, but use the notify::active signal.

So connecting should be as simple as:

switch.connect('notify::active', _switch_active_changed_cb)

The notify::foo principle can be used on any widget, it actually listens on property changes.

Read more about connecting signals in the documentation.

share|improve this answer
Thank you Timo, do you possibly know how the event binding works on these? Can't seem to find quickly specific examples – Rudi Strydom Nov 12 '12 at 16:53
These aren't Quickly specific questions, just regular PyGTK (or PyGI nowadays). I'll update my answer a bit, which should look and read better than a comment. – Timo Nov 12 '12 at 17:29
Timo you rock, but seems my PHP brain can't connect the dots. I am using the following in order to reference the button: self.daymon = self.builder.get_object("daymon") But how would I reference the action in relation to it? self.daymon.connect("notify::active", self.toggle_day("mon")) Is this the right way to connect the event to a function? – Rudi Strydom Nov 12 '12 at 18:19
Ermagerd, think I found my issue: self.daymon.connect('notify::active', self.toggle_day, "mon") The connect function takes the data as an additional parameter, that's if I am not crazy. – Rudi Strydom Nov 12 '12 at 18:25
You're right! And your callback function should have following signature: def toggle_day(self, widget, active, user_data) – Timo Nov 12 '12 at 19:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.