Package fife :: Package extensions :: Package pychan :: Package widgets' :: Module basictextwidget
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.pychan.widgets'.basictextwidget

  1  # -*- coding: utf-8 -*- 
  2   
  3  # #################################################################### 
  4  #  Copyright (C) 2005-2011 by the FIFE team 
  5  #  http://www.fifengine.net 
  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 widget import Widget 
 25  from common import * 
 26   
27 -class BasicTextWidget(Widget):
28 """ 29 The base class for widgets which display a string - L{Label},L{Button}, etc. 30 Do not use directly. 31 32 New Attributes 33 ============== 34 35 - text: The text (depends on actual widget) 36 37 Data 38 ==== 39 40 The text can be set via the L{distributeInitialData} method. 41 """ 42 43 ATTRIBUTES = Widget.ATTRIBUTES + [ UnicodeAttr('text') ] 44 DEFAULT_HEXPAND = 1 45 DEFAULT_VEXPAND = 0 46 DEFAULT_MARGINS = 5,5 47 DEFAULT_TEXT = u"" 48
49 - def __init__(self, 50 parent = None, 51 name = None, 52 size = None, 53 min_size = None, 54 max_size = None, 55 helptext = None, 56 position = None, 57 style = None, 58 hexpand = None, 59 vexpand = None, 60 font = None, 61 base_color = None, 62 background_color = None, 63 foreground_color = None, 64 selection_color = None, 65 border_size = None, 66 position_technique = None, 67 is_focusable = None, 68 comment = None, 69 margins = None, 70 text = None):
71 72 self.margins = self.DEFAULT_MARGINS 73 self.text = self.DEFAULT_TEXT 74 super(BasicTextWidget,self).__init__(parent=parent, 75 name=name, 76 size=size, 77 min_size=min_size, 78 max_size=max_size, 79 helptext=helptext, 80 position=position, 81 style=style, 82 hexpand=hexpand, 83 vexpand=vexpand, 84 font=font, 85 base_color=base_color, 86 background_color=background_color, 87 foreground_color=foreground_color, 88 selection_color=selection_color, 89 border_size=border_size, 90 position_technique=position_technique, 91 is_focusable=is_focusable, 92 comment=comment) 93 94 # Prepare Data collection framework 95 self.accepts_initial_data = True 96 self._realSetInitialData = self._setText 97 98 # Override anything set when stylize was called 99 if margins is not None: self.margins = margins 100 if text is not None: self.text = text
101
102 - def _getText(self): return gui2text(self.real_widget.getCaption())
103 - def _setText(self,text): self.real_widget.setCaption(text2gui(text))
104 105 text = property(_getText,_setText) 106
107 - def resizeToContent(self, recurse = True):
108 self.height = self.real_font.getHeight() + self.margins[1]*2 109 self.width = self.real_font.getWidth(text2gui(self.text)) + self.margins[0]*2
110