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

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

  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 common import * 
 25  from basictextwidget import BasicTextWidget 
 26   
27 -class Label(BasicTextWidget):
28 """ 29 A basic label - displaying a string. 30 31 Also allows text wrapping and onMouse hover callbacks. 32 33 New Attributes 34 ============== 35 36 - wrap_text: Boolean: Enable/Disable automatic text wrapping. Disabled by default. 37 Currently to actually see text wrapping you have to explicitly set a max_size with 38 the desired width of the text, as the layout engine is not capable of deriving 39 the maximum width from a parent container. 40 41 """ 42 43 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ BoolAttr('wrap_text') ] 44 45 DEFAULT_WRAP_TEXT = False 46
47 - def __init__(self, 48 parent = None, 49 name = None, 50 size = None, 51 min_size = None, 52 max_size = None, 53 helptext = None, 54 position = None, 55 style = None, 56 hexpand = None, 57 vexpand = None, 58 font = None, 59 base_color = None, 60 background_color = None, 61 foreground_color = None, 62 selection_color = None, 63 border_size = None, 64 position_technique = None, 65 is_focusable = None, 66 comment = None, 67 margins = None, 68 text = None, 69 wrap_text = None):
70 71 self.real_widget = fife.Label("") 72 self.wrap_text = self.DEFAULT_WRAP_TEXT 73 super(Label,self).__init__(parent=parent, 74 name=name, 75 size=size, 76 min_size=min_size, 77 max_size=max_size, 78 helptext=helptext, 79 position=position, 80 style=style, 81 hexpand=hexpand, 82 vexpand=vexpand, 83 font=font, 84 base_color=base_color, 85 background_color=background_color, 86 foreground_color=foreground_color, 87 selection_color=selection_color, 88 border_size=border_size, 89 position_technique=position_technique, 90 is_focusable=is_focusable, 91 comment=comment, 92 margins=margins, 93 text=text) 94 95 if wrap_text is not None: self.wrap_text = wrap_text
96
97 - def clone(self, prefix):
98 lblClone = Label(None, 99 self._createNameWithPrefix(prefix), 100 self.size, 101 self.min_size, 102 self.max_size, 103 self.helptext, 104 self.position, 105 self.style, 106 self.hexpand, 107 self.vexpand, 108 self.font, 109 self.base_color, 110 self.background_color, 111 self.foreground_color, 112 self.selection_color, 113 self.border_size, 114 self.position_technique, 115 self.is_focusable, 116 self.comment, 117 self.margins, 118 self.text, 119 self.wrap_text) 120 121 return lblClone;
122 123
124 - def resizeToContent(self, recurse=True):
125 self.real_widget.setWidth( self.max_size[0] ) 126 self.real_widget.adjustSize() 127 self.height = self.real_widget.getHeight() + self.margins[1]*2 128 self.width = self.real_widget.getWidth() + self.margins[0]*2
129 #print self.width,self.max_size[0] 130
131 - def _setTextWrapping(self,wrapping): self.real_widget.setTextWrapping(wrapping)
132 - def _getTextWrapping(self): self.real_widget.isTextWrapping()
133 wrap_text = property(_getTextWrapping,_setTextWrapping)
134