1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#
# Kiwi: a Framework and Enhanced Widgets for Python
#
# Copyright (C) 2003-2006 Async Open Source
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# Author(s): Christian Reis <kiko@async.com.br>
# Daniel Saran R. da Cunha <daniel@async.com.br>
# Lorenzo Gil Sanchez <lgs@sicem.biz>
# Gustavo Rahal <gustavo@async.com.br>
#
"""GtkRadioButton support for the Kiwi Framework"""
import gtk
from kiwi import ValueUnset
from kiwi.python import deprecationwarn
from kiwi.utils import PropertyObject, gproperty, type_register
from kiwi.ui.proxywidget import ProxyWidgetMixin
class ProxyRadioButton(PropertyObject, gtk.RadioButton, ProxyWidgetMixin):
__gtype_name__ = 'ProxyRadioButton'
gproperty('data-value', str, nick='Data Value')
def __init__(self, group=None, label=None, use_underline=True):
gtk.RadioButton.__init__(self, None, label, use_underline)
if group:
self.set_group(group)
ProxyWidgetMixin.__init__(self)
PropertyObject.__init__(self)
self.connect('group-changed', self._on_group_changed)
def _on_radio__toggled(self, radio):
self.emit('content-changed')
def _on_group_changed(self, radio):
for radio in radio.get_group():
radio.connect('toggled', self._on_radio__toggled)
def get_selected(self):
"""
Get the currently selected radiobutton.
@returns: The selected L{RadioButton} or None if there are no
selected radiobuttons.
"""
for button in self.get_group():
if button.get_active():
return button
def read(self):
button = self.get_selected()
if button is None:
return ValueUnset
return self._from_string(button.data_value)
def update(self, data):
if data is None:
# In a group of radiobuttons, the only widget which is in
# the proxy is ourself, the other buttons do not get their
# update() method called, so the default value is activate
# ourselves when the model is empty
self.set_active(True)
return
data = self._as_string(data)
for rb in self.get_group():
if rb.get_property('data-value') == data:
rb.set_active(True)
class RadioButton(ProxyRadioButton):
def __init__(self):
deprecationwarn(
'RadioButton is deprecated, use ProxyRadioButton instead',
stacklevel=3)
ProxyRadioButton.__init__(self)
type_register(RadioButton)
|