Package fife :: Package extensions :: Package pychan :: Package widgets' :: Module radiobutton
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.pychan.widgets'.radiobutton

  1  # -*- coding: utf-8 -*- 
  2   
  3  # #################################################################### 
  4  #  Copyright (C) 2005-2011 by the FIFE team 
  5  #  http://www.fifengine.net 
  6  #  This file is part of FIFE. 
  7  # 
  8  #  FIFE is free software; you can redistribute it and/or 
  9  #  modify it under the terms of the GNU Lesser General Public 
 10  #  License as published by the Free Software Foundation; either 
 11  #  version 2.1 of the License, or (at your option) any later version. 
 12  # 
 13  #  This library is distributed in the hope that it will be useful, 
 14  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 16  #  Lesser General Public License for more details. 
 17  # 
 18  #  You should have received a copy of the GNU Lesser General Public 
 19  #  License along with this library; if not, write to the 
 20  #  Free Software Foundation, Inc., 
 21  #  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
 22  # #################################################################### 
 23   
 24  from common import * 
 25  from basictextwidget import BasicTextWidget 
 26   
27 -class RadioButton(BasicTextWidget):
28 """ 29 A basic radiobutton (an exclusive checkbox). 30 31 New Attributes 32 ============== 33 34 - marked: Boolean: Whether the checkbox is checked or not. 35 - group: String: All RadioButtons with the same group name 36 can only be checked exclusively. 37 38 Data 39 ==== 40 The marked status can be read and set via L{distributeData} and L{collectData} 41 """ 42 43 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ BoolAttr('marked'), 44 Attr('group') 45 ] 46 DEFAULT_GROUP = "_no_group_" 47
48 - def __init__(self, 49 parent = None, 50 name = None, 51 size = None, 52 min_size = None, 53 max_size = None, 54 helptext = None, 55 position = None, 56 style = None, 57 hexpand = None, 58 vexpand = None, 59 font = None, 60 base_color = None, 61 background_color = None, 62 foreground_color = None, 63 selection_color = None, 64 border_size = None, 65 position_technique = None, 66 is_focusable = None, 67 comment = None, 68 margins = None, 69 text = None, 70 group = None):
71 72 self.real_widget = fife.RadioButton() 73 self.group = self.DEFAULT_GROUP 74 75 super(RadioButton,self).__init__(parent=parent, 76 name=name, 77 size=size, 78 min_size=min_size, 79 max_size=max_size, 80 helptext=helptext, 81 position=position, 82 style=style, 83 hexpand=hexpand, 84 vexpand=vexpand, 85 font=font, 86 base_color=base_color, 87 background_color=background_color, 88 foreground_color=foreground_color, 89 selection_color=selection_color, 90 border_size=border_size, 91 position_technique=position_technique, 92 is_focusable=is_focusable, 93 comment=comment, 94 text=text) 95 96 if group is not None: self.group = group 97 98 # Prepare Data collection framework 99 self.accepts_data = True 100 self._realGetData = self._isMarked 101 self._realSetData = self._setMarked
102 103 # Initial data stuff inherited. 104
105 - def clone(self, prefix):
106 rbuttonClone = RadioButton(None, 107 self._createNameWithPrefix(prefix), 108 self.size, 109 self.min_size, 110 self.max_size, 111 self.helptext, 112 self.position, 113 self.style, 114 self.hexpand, 115 self.vexpand, 116 self.font, 117 self.base_color, 118 self.background_color, 119 self.foreground_color, 120 self.selection_color, 121 self.border_size, 122 self.position_technique, 123 self.is_focusable, 124 self.comment, 125 self.margins, 126 self.text, 127 self.group) 128 129 return rbuttonClone
130 131 132
133 - def _isMarked(self): return self.real_widget.isSelected()
134 - def _setMarked(self,mark): self.real_widget.setSelected(mark)
135 marked = property(_isMarked,_setMarked) 136
137 - def _setGroup(self,group): self.real_widget.setGroup(group)
138 - def _getGroup(self): return self.real_widget.getGroup()
139 group = property(_getGroup,_setGroup) 140
141 - def resizeToContent(self,recurse=True):
142 self.width = self.real_font.getWidth(text2gui(self.text)) + 35# Size of the Checked box? 143 self.height = self.real_font.getHeight()
144