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

Source Code for Module muntjac.ui.text_area

  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 text field that supports multi-line editing.""" 
 17   
 18  from muntjac.ui.abstract_text_field import AbstractTextField 
 19  from muntjac.data.property import IProperty 
 20   
 21   
22 -class TextArea(AbstractTextField):
23 """A text field that supports multi line editing.""" 24 25 CLIENT_WIDGET = None #ClientWidget(VTextArea, LoadStyle.EAGER) 26 27 _DEFAULT_ROWS = 5 28
29 - def __init__(self, *args):
30 """Constructs a TextArea with an optional caption, data source, 31 and/or value. 32 33 @param args: tuple of the form 34 - () 35 - (caption) 36 1. the caption for the field 37 - (dataSource) 38 1. the data source for the field 39 - (caption, dataSource) 40 1. the caption for the field 41 2. the data source for the field 42 - (caption, value) 43 1. the caption for the field 44 2. the value for the field 45 """ 46 # Number of visible rows in the text area. 47 self._rows = self._DEFAULT_ROWS 48 49 # Tells if word-wrapping should be used in the text area. 50 self._wordwrap = True 51 52 nargs = len(args) 53 if nargs == 0: 54 super(TextArea, self).__init__() 55 self.setValue('') 56 elif nargs == 1: 57 if isinstance(args[0], IProperty): 58 dataSource, = args 59 TextArea.__init__(self) 60 self.setPropertyDataSource(dataSource) 61 else: 62 caption, = args 63 TextArea.__init__(self) 64 self.setCaption(caption) 65 elif nargs == 2: 66 if isinstance(args[1], IProperty): 67 caption, dataSource = args 68 TextArea.__init__(self, dataSource) 69 self.setCaption(caption) 70 else: 71 caption, value = args 72 TextArea.__init__(self, caption) 73 self.setValue(value) 74 else: 75 raise ValueError, 'too many arguments'
76 77
78 - def setRows(self, rows):
79 """Sets the number of rows in the text area. 80 81 @param rows: the number of rows for this text area. 82 """ 83 if rows < 0: 84 rows = 0 85 86 if self._rows != rows: 87 self._rows = rows 88 self.requestRepaint()
89 90
91 - def getRows(self):
92 """Gets the number of rows in the text area. 93 94 @return: number of explicitly set rows. 95 """ 96 return self._rows
97 98
99 - def setWordwrap(self, wordwrap):
100 """Sets the text area's word-wrap mode on or off. 101 102 @param wordwrap: 103 the boolean value specifying if the text area should be 104 in word-wrap mode. 105 """ 106 if self._wordwrap != wordwrap: 107 self._wordwrap = wordwrap 108 self.requestRepaint()
109 110
111 - def isWordwrap(self):
112 """Tests if the text area is in word-wrap mode. 113 114 @return: C{True} if the component is in word-wrap mode, 115 C{False} if not. 116 """ 117 return self._wordwrap
118 119
120 - def paintContent(self, target):
121 super(TextArea, self).paintContent(target) 122 123 target.addAttribute('rows', self.getRows()) 124 125 if not self.isWordwrap(): 126 # Wordwrap is only painted if turned off to minimize 127 # communications 128 target.addAttribute('wordwrap', False)
129