Alguém sabe onde eu posso encontrar documentação no Widget Switch no glade ??
Eu tentei encontrar no site do GTK, mas ele não tem uma entrada para ele.
EDITAR
Obrigado a Timo por me apontar na direção certa. Eu estou amando askubuntu!.
Basicamente, meu problema é que a função de conexão por defualts envia o Objeto da Janela, o Objeto do Widget e o Estado Ativo para qualquer função que você executar no retorno de chamada.
Este é o antes:
self.daymon.connect("notify::active", self.toggle_day("mon"))
E este é o depois:
self.daymon.connect('notify::active', self.toggle_day, "mon")
O último funciona como um encanto ao executar a seguinte função:
def toggle_day(self, widget, active, day):
if widget.get_active():
state = True
else:
state = False
Código completo a seguir, caso esteja interessado:
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE
import gettext
from gettext import gettext as _
gettext.textdomain('snooze')
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):
print "CREATING CONFIG"
config.add_section('Preferences')
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)
rewriteConfigFile(filename)
# Writing our configuration file to the failename as specifeid
def rewriteConfigFile(filename):
with open(filename, 'wb') as configfile:
config.write(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 config.read(configFile):
createConfigFile(configFile)
readConfigFile(configFile)
else:
readConfigFile(configFile)
# See snooze_lib.Window.py 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:
self.daymon.activate()
if tueState == True:
self.daytues.activate()
if wedState == True:
self.daywed.activate()
if thurState == True:
self.daythur.activate()
if friState == True:
self.dayfri.activate()
if satState == True:
self.daysat.activate()
if sunState == True:
self.daysun.activate()
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
else:
state = False
# Set the config option and update the config file
global configFile
config.set('Preferences', day, state)
rewriteConfigFile(configFile)