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

Source Code for Module muntjac.ui.progress_indicator

  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 component that shows user state of a process.""" 
 17   
 18  from muntjac.data.util.object_property import ObjectProperty 
 19  from muntjac.ui.abstract_field import AbstractField 
 20   
 21  from muntjac.data import property as prop 
 22   
 23   
24 -class ProgressIndicator(AbstractField, prop.IValueChangeListener, 25 prop.IProperty, prop.IViewer):
26 """C{ProgressIndicator} is component that shows user state of 27 a process (like long computing or file upload) 28 29 C{ProgressIndicator} has two mainmodes. One for indeterminate processes 30 and other (default) for processes which progress can be measured. 31 32 May view an other property that indicates progress 0...1 33 34 @author: Vaadin Ltd. 35 @author: Richard Lincoln 36 @version: 1.1.2 37 """ 38 39 CLIENT_WIDGET = None #ClientWidget(VProgressIndicator, LoadStyle.EAGER) 40 41 #: Content mode, where the label contains only plain text. The getValue() 42 # result is coded to XML when painting. 43 CONTENT_TEXT = 0 44 45 #: Content mode, where the label contains preformatted text. 46 CONTENT_PREFORMATTED = 1 47 48
49 - def __init__(self, *args):
50 """Creates an a new ProgressIndicator. 51 52 @param args: tuple of the form 53 - () 54 - (value) 55 - (contentSource) 56 """ 57 super(ProgressIndicator, self).__init__() 58 59 self._indeterminate = False 60 self._dataSource = None 61 self._pollingInterval = 1000 62 63 nargs = len(args) 64 if nargs == 0: 65 self.setPropertyDataSource( ObjectProperty(0.0, float) ) 66 elif nargs == 1: 67 if isinstance(args[0], prop.IProperty): 68 contentSource, = args 69 self.setPropertyDataSource(contentSource) 70 else: 71 value, = args 72 self.setPropertyDataSource( ObjectProperty(value, float) ) 73 else: 74 raise ValueError, 'too many arguments'
75 76
77 - def setReadOnly(self, readOnly):
78 """Sets the component to read-only. Readonly is not used in 79 ProgressIndicator. 80 81 @param readOnly: 82 True to enable read-only mode, False to disable it. 83 """ 84 if self._dataSource is None: 85 raise ValueError, 'datasource must be set' 86 87 self._dataSource.setReadOnly(readOnly)
88 89
90 - def isReadOnly(self):
91 """Is the component read-only ? Readonly is not used in 92 ProgressIndicator - this returns allways false. 93 94 @return: True if the component is in read only mode. 95 """ 96 if self._dataSource is None: 97 raise ValueError, 'datasource must be set' 98 99 return self._dataSource.isReadOnly()
100 101
102 - def paintContent(self, target):
103 """Paints the content of this component. 104 105 @param target: 106 the Paint Event. 107 @raise PaintException: 108 if the Paint Operation fails. 109 """ 110 target.addAttribute('indeterminate', self._indeterminate) 111 target.addAttribute('pollinginterval', self._pollingInterval) 112 target.addAttribute('state', str(self.getValue()))
113 114
115 - def getValue(self):
116 """Gets the value of the ProgressIndicator. Value of the 117 ProgressIndicator is a float between 0 and 1. 118 119 @return: the Value of the ProgressIndicator. 120 @see: L{AbstractField.getValue} 121 """ 122 if self._dataSource is None: 123 raise ValueError, 'datasource must be set' 124 125 return self._dataSource.getValue()
126 127
128 - def setValue(self, newValue, repaintIsNotNeeded=None):
129 """Sets the value of the ProgressIndicator. Value of the 130 ProgressIndicator is the float between 0 and 1. 131 132 @param newValue: the new value of the ProgressIndicator. 133 @see: L{AbstractField.setValue} 134 """ 135 if repaintIsNotNeeded is None: 136 if self._dataSource is None: 137 raise ValueError, 'datasource must be set' 138 139 self._dataSource.setValue(newValue) 140 else: 141 super(ProgressIndicator, self).setValue(newValue, 142 repaintIsNotNeeded)
143 144
145 - def __str__(self):
146 """@see: L{AbstractField.__str__}""" 147 if self._dataSource is None: 148 raise ValueError, 'datasource must be set' 149 150 return str(self._dataSource)
151 152
153 - def getType(self):
154 """@see: L{AbstractField.getType}""" 155 if self._dataSource is None: 156 raise ValueError, 'datasource must be set' 157 158 return self._dataSource.getType()
159 160
161 - def getPropertyDataSource(self):
162 """Gets the viewing data-source property. 163 164 @return: the datasource. 165 @see: L{AbstractField.getPropertyDataSource} 166 """ 167 return self._dataSource
168 169
170 - def setPropertyDataSource(self, newDataSource):
171 """Sets the property as data-source for viewing. 172 173 @param newDataSource: 174 the new data source. 175 @see: L{AbstractField.setPropertyDataSource} 176 """ 177 # Stops listening the old data source changes 178 if (self._dataSource is not None 179 and issubclass(self._dataSource.__class__, 180 prop.IValueChangeNotifier)): 181 self._dataSource.removeListener(self, 182 prop.IValueChangeListener) 183 184 # Sets the new data source 185 self._dataSource = newDataSource 186 187 # Listens the new data source if possible 188 if (self._dataSource is not None 189 and issubclass(self._dataSource.__class__, 190 prop.IValueChangeNotifier)): 191 self._dataSource.addListener(self, prop.IValueChangeListener)
192 193
194 - def getContentMode(self):
195 """Gets the mode of ProgressIndicator. 196 197 @return: true if in indeterminate mode. 198 """ 199 return self._indeterminate
200 201
202 - def setIndeterminate(self, newValue):
203 """Sets wheter or not the ProgressIndicator is indeterminate. 204 205 @param newValue: 206 true to set to indeterminate mode. 207 """ 208 self._indeterminate = newValue 209 self.requestRepaint()
210 211
212 - def isIndeterminate(self):
213 """Gets whether or not the ProgressIndicator is indeterminate. 214 215 @return: true to set to indeterminate mode. 216 """ 217 return self._indeterminate
218 219
220 - def setPollingInterval(self, newValue):
221 """Sets the interval that component checks for progress. 222 223 @param newValue: 224 the interval in milliseconds. 225 """ 226 self._pollingInterval = newValue 227 self.requestRepaint()
228 229
230 - def getPollingInterval(self):
231 """Gets the interval that component checks for progress. 232 233 @return: the interval in milliseconds. 234 """ 235 return self._pollingInterval
236