Package muntjac :: Package ui :: Module check_box
[hide private]
[frames] | no frames]

Source Code for Module muntjac.ui.check_box

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  """Defines a switch button.""" 
17   
18  from warnings import warn 
19   
20  from muntjac.ui.button import Button, IClickListener 
21  from muntjac.data.property import IProperty 
22   
23   
24 -class CheckBox(Button):
25 26 CLIENT_WIDGET = None #ClientWidget(VCheckBox) 27
28 - def __init__(self, *args):
29 """Creates a new switch button. 30 31 @param args: tuple of the form 32 - (caption, initialState) 33 1. the caption of the switch button 34 2. the initial state of the switch button 35 - (caption, listener) 36 1. the caption of the switch button 37 2. the click listener 38 - (caption, target, methodName) 39 1. the Button caption. 40 2. the Object having the method for listening button clicks. 41 3. the name of the method in target object, that receives 42 button click events. 43 - (state, dataSource) 44 1. the Initial state of the switch-button. 45 2. boolean property 46 - (caption) 47 1. the switch button caption 48 """ 49 nargs = len(args) 50 if nargs == 0: 51 super(CheckBox, self).__init__() 52 self.setSwitchMode(True) 53 elif nargs == 1: 54 caption, = args 55 super(CheckBox, self).__init__(caption, False) 56 elif nargs == 2: 57 if isinstance(args[1], IClickListener): 58 caption, listener = args 59 super(CheckBox, self).__init__(caption, listener) 60 self.setSwitchMode(True) 61 elif isinstance(args[1], IProperty): 62 caption, dataSource = args 63 super(CheckBox, self).__init__(caption, dataSource) 64 self.setSwitchMode(True) 65 else: 66 caption, initialState = args 67 super(CheckBox, self).__init__(caption, initialState) 68 elif nargs == 3: 69 caption, target, methodName = args 70 super(CheckBox, self).__init__(caption, target, methodName) 71 self.setSwitchMode(True) 72 else: 73 raise ValueError, 'too many arguments'
74 75
76 - def setSwitchMode(self, switchMode):
77 warn('CheckBox is always in switch mode', DeprecationWarning) 78 79 if self._switchMode and not switchMode: 80 raise NotImplementedError, ('CheckBox is always in switch ' 81 'mode (consider using a Button)') 82 83 super(CheckBox, self).setSwitchMode(True)
84 85
86 - def setDisableOnClick(self, disableOnClick):
87 raise NotImplementedError, "CheckBox does not support disable on click"
88