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

Source Code for Module muntjac.ui.native_select

 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 simple drop-down select.""" 
17   
18  from muntjac.ui.abstract_select import AbstractSelect 
19  from muntjac.data.container import IContainer 
20   
21   
22 -class NativeSelect(AbstractSelect):
23 """This is a simple drop-down select without, for instance, support 24 for multiselect, new items, lazyloading, and other advanced features. 25 Sometimes "native" select without all the bells-and-whistles of the 26 ComboBox is a better choice. 27 """ 28 29 CLIENT_WIDGET = None #ClientWidget(VNativeWidget) 30
31 - def __init__(self, *args):
32 # width in characters, mimics TextField 33 self._columns = 0 34 35 args = args 36 nargs = len(args) 37 if nargs == 0: 38 super(NativeSelect, self).__init__() 39 elif nargs == 1: 40 caption, = args 41 super(NativeSelect, self).__init__(caption) 42 elif nargs == 2: 43 if isinstance(args[1], IContainer): 44 caption, dataSource = args 45 super(NativeSelect, self).__init__(caption, dataSource) 46 else: 47 caption, options = args 48 super(NativeSelect, self).__init__(caption, options) 49 else: 50 raise ValueError, 'too many arguments'
51 52
53 - def setColumns(self, columns):
54 """Sets the number of columns in the editor. If the number of columns 55 is set 0, the actual number of displayed columns is determined 56 implicitly by the adapter. 57 58 @param columns: 59 the number of columns to set. 60 """ 61 if columns < 0: 62 columns = 0 63 64 if self._columns != columns: 65 self._columns = columns 66 self.requestRepaint()
67 68
69 - def getColumns(self):
70 return self._columns
71 72
73 - def paintContent(self, target):
74 target.addAttribute('type', 'native') 75 # Adds the number of columns 76 if self._columns != 0: 77 target.addAttribute('cols', self._columns) 78 79 super(NativeSelect, self).paintContent(target)
80 81
82 - def setMultiSelect(self, multiSelect):
83 if multiSelect == True: 84 raise NotImplementedError, 'Multiselect not supported'
85 86
87 - def setNewItemsAllowed(self, allowNewOptions):
88 if allowNewOptions == True: 89 raise NotImplementedError, 'newItemsAllowed not supported'
90