comparison engine/python/fife/extensions/pychan/widgets/textbox.py @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2009 by the FIFE team
5 # http://www.fifengine.de
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 widget import Widget
26
27 class TextBox(Widget):
28 """
29 An editable B{multiline} text edit widget.
30
31 New Attributes
32 ==============
33
34 - text: The text in the TextBox.
35 - filename: A write-only attribute - assigning a filename will cause the widget to load it's text from it.
36
37 Data
38 ====
39 The text can be read and set via L{distributeData} and L{collectData}.
40 """
41
42 ATTRIBUTES = Widget.ATTRIBUTES + [UnicodeAttr('text'),Attr('filename')]
43 DEFAULT_HEXPAND = 1
44 DEFAULT_VEXPAND = 1
45
46 def __init__(self,text=u"",filename = "", **kwargs):
47 self.real_widget = fife.TextBox()
48 self.text = text
49 self.filename = filename
50 super(TextBox,self).__init__(**kwargs)
51
52 # Prepare Data collection framework
53 self.accepts_data = True
54 self.accepts_initial_data = True # Make sense in a way ...
55 self._realSetInitialData = self._setText
56 self._realSetData = self._setText
57 self._realGetData = self._getText
58
59 def _getFileName(self): return self._filename
60 def _loadFromFile(self,filename):
61 self._filename = filename
62 if not filename: return
63 try:
64 # FIXME needs encoding detection.
65 self.text = unicode(open(filename).read(),"utf8")
66 except Exception, e:
67 self.text = str(e)
68 filename = property(_getFileName, _loadFromFile)
69
70 def resizeToContent(self,recurse=True):
71 rows = [self.real_widget.getTextRow(i) for i in range(self.real_widget.getNumberOfRows())]
72 max_w = max(map(self.real_font.getWidth,rows))
73 self.width = max_w
74 self.height = (self.real_font.getHeight() + 2) * self.real_widget.getNumberOfRows()
75
76 def _getText(self): return gui2text(self.real_widget.getText())
77 def _setText(self,text): self.real_widget.setText(text2gui(text))
78 text = property(_getText,_setText)
79
80 def _setOpaque(self,opaque): self.real_widget.setOpaque(opaque)
81 def _getOpaque(self): return self.real_widget.isOpaque()
82 opaque = property(_getOpaque,_setOpaque)