Mercurial > fife-parpg
comparison engine/python/fife/extensions/pychan/widgets/scrollarea.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 | 637384c8de04 |
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 widget import Widget | |
26 | |
27 class ScrollArea(Widget): | |
28 """ | |
29 A wrapper around another (content) widget. | |
30 | |
31 New Attributes | |
32 ============== | |
33 | |
34 - content: The wrapped widget. | |
35 - vertical_scrollbar: Boolean: Set this to False to hide the Vertical scrollbar | |
36 - horizontal_scrollbar: Boolean: Set this to False to hide the Horizontal scrollbar | |
37 | |
38 """ | |
39 | |
40 ATTRIBUTES = Widget.ATTRIBUTES + [ BoolAttr("vertical_scrollbar"),BoolAttr("horizontal_scrollbar") ] | |
41 DEFAULT_HEXPAND = 1 | |
42 DEFAULT_VEXPAND = 1 | |
43 | |
44 def __init__(self,**kwargs): | |
45 self.real_widget = fife.ScrollArea() | |
46 self._content = None | |
47 super(ScrollArea,self).__init__(**kwargs) | |
48 | |
49 def addChild(self,widget): | |
50 self.content = widget | |
51 widget.parent = self | |
52 | |
53 def removeChild(self,widget): | |
54 if self._content != widget: | |
55 raise RuntimeError("%s does not have %s as direct child widget." % (str(self),str(widget))) | |
56 self.content = None | |
57 widget.parent = None | |
58 | |
59 def _setContent(self,content): | |
60 if content is None: | |
61 self.real_widget.setContent(content) | |
62 else: | |
63 self.real_widget.setContent(content.real_widget) | |
64 self._content = content | |
65 def _getContent(self): return self._content | |
66 content = property(_getContent,_setContent) | |
67 | |
68 def deepApply(self,visitorFunc, leaves_first = True): | |
69 if leaves_first: | |
70 if self._content: self._content.deepApply(visitorFunc, leaves_first = leaves_first) | |
71 visitorFunc(self) | |
72 if not leaves_first: | |
73 if self._content: self._content.deepApply(visitorFunc, leaves_first = leaves_first) | |
74 | |
75 def resizeToContent(self,recurse=True): | |
76 if self._content is None: return | |
77 if recurse: | |
78 self.content.resizeToContent(recurse=recurse) | |
79 self.size = self.min_size | |
80 | |
81 def _visibilityToScrollPolicy(self,visibility): | |
82 if visibility: | |
83 return fife.ScrollArea.SHOW_AUTO | |
84 return fife.ScrollArea.SHOW_NEVER | |
85 | |
86 def _scrollPolicyToVisibility(self,policy): | |
87 if policy == fife.ScrollArea.SHOW_NEVER: | |
88 return False | |
89 return True | |
90 | |
91 def _setHorizontalScrollbar(self,visibility): | |
92 self.real_widget.setHorizontalScrollPolicy( self._visibilityToScrollPolicy(visibility) ) | |
93 | |
94 def _setVerticalScrollbar(self,visibility): | |
95 self.real_widget.setVerticalScrollPolicy( self._visibilityToScrollPolicy(visibility) ) | |
96 | |
97 def _getHorizontalScrollbar(self): | |
98 return self._scrollPolicyToVisibility( self.real_widget.getHorizontalScrollPolicy() ) | |
99 | |
100 def _getVerticalScrollbar(self): | |
101 return self._scrollPolicyToVisibility( self.real_widget.getVerticalScrollPolicy() ) | |
102 | |
103 def sizeChanged(self): | |
104 if self.content: | |
105 self.content.width = max(self.content.width,self.width-5) | |
106 self.content.height = max(self.content.height,self.height-5) | |
107 | |
108 vertical_scrollbar = property(_getVerticalScrollbar,_setVerticalScrollbar) | |
109 horizontal_scrollbar = property(_getHorizontalScrollbar,_setHorizontalScrollbar) |