| 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 widget import Widget |
|---|
| 26 | from fife.extensions.pychan.properties import ImageProperty |
|---|
| 27 | |
|---|
| 28 | class Icon(Widget): |
|---|
| 29 | """ |
|---|
| 30 | An image icon. |
|---|
| 31 | |
|---|
| 32 | New Attributes |
|---|
| 33 | ============== |
|---|
| 34 | |
|---|
| 35 | - image: String or GuiImage: The source location of the Image or a direct GuiImage |
|---|
| 36 | """ |
|---|
| 37 | ATTRIBUTES = Widget.ATTRIBUTES + [ Attr('image') ] |
|---|
| 38 | |
|---|
| 39 | def __init__(self, |
|---|
| 40 | parent = None, |
|---|
| 41 | name = None, |
|---|
| 42 | size = None, |
|---|
| 43 | min_size = None, |
|---|
| 44 | max_size = None, |
|---|
| 45 | helptext = None, |
|---|
| 46 | position = None, |
|---|
| 47 | style = None, |
|---|
| 48 | hexpand = None, |
|---|
| 49 | vexpand = None, |
|---|
| 50 | font = None, |
|---|
| 51 | base_color = None, |
|---|
| 52 | background_color = None, |
|---|
| 53 | foreground_color = None, |
|---|
| 54 | selection_color = None, |
|---|
| 55 | border_size = None, |
|---|
| 56 | position_technique = None, |
|---|
| 57 | is_focusable = None, |
|---|
| 58 | comment = None, |
|---|
| 59 | image = None): |
|---|
| 60 | |
|---|
| 61 | self.real_widget = fife.Icon(None) |
|---|
| 62 | super(Icon,self).__init__(parent=parent, |
|---|
| 63 | name=name, |
|---|
| 64 | size=size, |
|---|
| 65 | min_size=min_size, |
|---|
| 66 | max_size=max_size, |
|---|
| 67 | helptext=helptext, |
|---|
| 68 | position=position, |
|---|
| 69 | style=style, |
|---|
| 70 | hexpand=hexpand, |
|---|
| 71 | vexpand=vexpand, |
|---|
| 72 | font=font, |
|---|
| 73 | base_color=base_color, |
|---|
| 74 | background_color=background_color, |
|---|
| 75 | foreground_color=foreground_color, |
|---|
| 76 | selection_color=selection_color, |
|---|
| 77 | border_size=border_size, |
|---|
| 78 | position_technique=position_technique, |
|---|
| 79 | is_focusable=is_focusable, |
|---|
| 80 | comment=comment) |
|---|
| 81 | self.image = image |
|---|
| 82 | |
|---|
| 83 | _image = ImageProperty("Image") |
|---|
| 84 | |
|---|
| 85 | def _setImage(self,source): |
|---|
| 86 | self._image = source |
|---|
| 87 | # This is a bit odd. |
|---|
| 88 | # ... not sure whether to leave the sizes alone, but that might |
|---|
| 89 | # break layouts. yikes. |
|---|
| 90 | self.min_size = self.real_widget.getWidth(),self.real_widget.getHeight() |
|---|
| 91 | self.max_size = self.min_size |
|---|
| 92 | self.size = self.min_size |
|---|
| 93 | #print self._image, self.min_size, self.max_size |
|---|
| 94 | |
|---|
| 95 | def _getImage(self): |
|---|
| 96 | return self._image |
|---|
| 97 | image = property(_getImage,_setImage) |
|---|