Mercurial > fife-parpg
comparison engine/extensions/pychan/widgets/icon.py @ 248:a2d5e2721489
widgets.py split up.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 26 Mar 2009 16:20:16 +0000 |
parents | |
children | 48c99636453e |
comparison
equal
deleted
inserted
replaced
247:040387b7167f | 248:a2d5e2721489 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 from common import * | |
4 from widget import Widget | |
5 | |
6 class Icon(Widget): | |
7 """ | |
8 An image icon. | |
9 | |
10 New Attributes | |
11 ============== | |
12 | |
13 - image: String or GuiImage: The source location of the Image or a direct GuiImage | |
14 """ | |
15 ATTRIBUTES = Widget.ATTRIBUTES + [Attr('image')] | |
16 | |
17 def __init__(self,image="",**kwargs): | |
18 self.real_widget = fife.Icon(None) | |
19 super(Icon,self).__init__(**kwargs) | |
20 self._source = self._image = None | |
21 if image: | |
22 self.image = image | |
23 | |
24 def _setImage(self,source): | |
25 if isinstance(source,str): | |
26 self._source = source | |
27 self._image = get_manager().loadImage(source) | |
28 elif isinstance(source,fife.GuiImage): | |
29 self._source = None | |
30 self._image = source | |
31 else: | |
32 raise RuntimeError("Icon.image only accepts GuiImage and python strings, not '%s'" % repr(source)) | |
33 self.real_widget.setImage( self._image ) | |
34 | |
35 # Set minimum size accoriding to image | |
36 self.min_size = self.real_widget.getWidth(),self.real_widget.getHeight() | |
37 self.size = self.max_size = self.min_size | |
38 | |
39 def _getImage(self): | |
40 if self._source is not None: | |
41 return self._source | |
42 return self._image | |
43 image = property(_getImage,_setImage) |