Mercurial > fife-parpg
comparison engine/python/fife/extensions/pychan/widgets/buttons.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 basictextwidget import BasicTextWidget | |
26 from fife.extensions.pychan.properties import ImageProperty | |
27 | |
28 class Button(BasicTextWidget): | |
29 """ | |
30 A basic push button. | |
31 """ | |
32 def __init__(self,**kwargs): | |
33 self.real_widget = fife.Button("") | |
34 super(Button,self).__init__(**kwargs) | |
35 | |
36 class ImageButton(BasicTextWidget): | |
37 """ | |
38 A basic push button with three different images for the up, down and hover state. | |
39 | |
40 B{Work in progress.} | |
41 | |
42 New Attributes | |
43 ============== | |
44 | |
45 - up_image: String: The source location of the Image for the B{unpressed} state. | |
46 - down_image: String: The source location of the Image for the B{pressed} state. | |
47 - hover_image: String: The source location of the Image for the B{unpressed hovered} state. | |
48 """ | |
49 | |
50 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [Attr('up_image'),Attr('down_image'),PointAttr('offset'),Attr('hover_image')] | |
51 | |
52 def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),**kwargs): | |
53 self.real_widget = kwargs.get("real_widget", fife.TwoButton()) | |
54 super(ImageButton,self).__init__(**kwargs) | |
55 | |
56 self.up_image = up_image | |
57 self.down_image = down_image | |
58 self.hover_image = hover_image | |
59 self.offset = offset | |
60 | |
61 up_image = ImageProperty("UpImage") | |
62 down_image = ImageProperty("DownImage") | |
63 hover_image = ImageProperty("HoverImage") | |
64 | |
65 def _setOffset(self, offset): | |
66 self.real_widget.setDownOffset(offset[0], offset[1]) | |
67 def _getOffset(self): | |
68 return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset()) | |
69 offset = property(_getOffset,_setOffset) | |
70 | |
71 def resizeToContent(self, recurse=True): | |
72 th, tw = 0, 0 | |
73 if self.text: | |
74 th = self.real_font.getHeight()#+self.real_font.getSpacing() | |
75 tw = self.real_font.getWidth(text2gui(self.text))#+self.real_font.getSpacing() | |
76 self.height = max( | |
77 self._prop_upimage["image"].getHeight(), | |
78 self._prop_downimage["image"].getHeight(), | |
79 self._prop_hoverimage["image"].getHeight(), | |
80 th) + self.margins[1]*2 | |
81 self.width = max( | |
82 self._prop_upimage["image"].getWidth(), | |
83 self._prop_downimage["image"].getWidth(), | |
84 self._prop_hoverimage["image"].getWidth(), | |
85 tw) + self.margins[0]*2 | |
86 | |
87 class ToggleButton(ImageButton): | |
88 """ | |
89 A basic push button that can be toggled. | |
90 | |
91 Unfortunately a bit of code duplication from ImageButton. | |
92 | |
93 New Attributes | |
94 ============== | |
95 | |
96 - group: String: The group the button belongs to. Only one button in each group will be toggled at one time. | |
97 - toggled: Boolean: Whether the button is toggled or not. | |
98 """ | |
99 | |
100 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ | |
101 Attr('up_image'),Attr('down_image'),Attr('hover_image'), | |
102 PointAttr('offset'),Attr('group') | |
103 ] | |
104 | |
105 def __init__(self,group="",**kwargs): | |
106 | |
107 super(ToggleButton,self).__init__(real_widget = fife.ToggleButton(), **kwargs) | |
108 self.group = group | |
109 | |
110 def _setGroup(self,group): | |
111 self.real_widget.setGroup( group ) | |
112 | |
113 def _getGroup(self): | |
114 return self.real_widget.getGroup() | |
115 group = property(_getGroup,_setGroup) | |
116 | |
117 def _setToggled(self, toggled): | |
118 self.real_widget.setToggled( toggled ) | |
119 | |
120 def _isToggled(self): | |
121 return self.real_widget.isToggled() | |
122 toggled = property(_isToggled, _setToggled) | |
123 | |
124 def resizeToContent(self, recurse=True): | |
125 # NOTE: Figure out how the spacing comes into play | |
126 tw, th = 0, 0 | |
127 if self.text: | |
128 th = self.real_font.getHeight() + self.real_widget.getSpacing() | |
129 tw = self.real_font.getWidth(text2gui(self.text)) + self.real_widget.getSpacing() | |
130 self.height = max( | |
131 self._prop_upimage["image"].getHeight(), | |
132 self._prop_downimage["image"].getHeight(), | |
133 self._prop_hoverimage["image"].getHeight(), | |
134 th) + self.margins[1]*2 | |
135 self.width = max( | |
136 self._prop_upimage["image"].getWidth(), | |
137 self._prop_downimage["image"].getWidth(), | |
138 self._prop_hoverimage["image"].getWidth(), | |
139 tw) + self.margins[0]*2 |