comparison engine/extensions/pychan/widgets/scrollarea.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 51cc05d862f2
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 ScrollArea(Widget):
7 """
8 A wrapper around another (content) widget.
9
10 New Attributes
11 ==============
12
13 - content: The wrapped widget.
14 - vertical_scrollbar: Boolean: Set this to False to hide the Vertical scrollbar
15 - horizontal_scrollbar: Boolean: Set this to False to hide the Horizontal scrollbar
16
17 """
18
19 ATTRIBUTES = Widget.ATTRIBUTES + [ BoolAttr("vertical_scrollbar"),BoolAttr("horizontal_scrollbar") ]
20
21 def __init__(self,**kwargs):
22 self.real_widget = fife.ScrollArea()
23 self._content = None
24 super(ScrollArea,self).__init__(**kwargs)
25
26 def addChild(self,widget):
27 self.content = widget
28 widget.parent = self
29
30 def removeChild(self,widget):
31 if self._content != widget:
32 raise RuntimeError("%s does not have %s as direct child widget." % (str(self),str(widget)))
33 self.content = None
34 widget.parent = None
35
36 def _setContent(self,content):
37 if content is None:
38 self.real_widget.setContent(content)
39 else:
40 self.real_widget.setContent(content.real_widget)
41 self._content = content
42 def _getContent(self): return self._content
43 content = property(_getContent,_setContent)
44
45 def deepApply(self,visitorFunc):
46 if self._content: self._content.deepApply(visitorFunc)
47 visitorFunc(self)
48
49 def resizeToContent(self,recurse=True):
50 if self._content is None: return
51 if recurse:
52 self.content.resizeToContent(recurse=True)
53 self.content.width = max(self.content.width,self.width-5)
54 self.content.height = max(self.content.height,self.height-5)
55
56 def _visibilityToScrollPolicy(self,visibility):
57 if visibility:
58 return fife.ScrollArea.SHOW_AUTO
59 return fife.ScrollArea.SHOW_NEVER
60
61 def _scrollPolicyToVisibility(self,policy):
62 if policy == fife.ScrollArea.SHOW_NEVER:
63 return False
64 return True
65
66 def _setHorizontalScrollbar(self,visibility):
67 self.real_widget.setHorizontalScrollPolicy( self._visibilityToScrollPolicy(visibility) )
68
69 def _setVerticalScrollbar(self,visibility):
70 self.real_widget.setVerticalScrollPolicy( self._visibilityToScrollPolicy(visibility) )
71
72 def _getHorizontalScrollbar(self):
73 return self._scrollPolicyToVisibility( self.real_widget.getHorizontalScrollPolicy() )
74
75 def _getVerticalScrollbar(self):
76 return self._scrollPolicyToVisibility( self.real_widget.getVerticalScrollPolicy() )
77
78 vertical_scrollbar = property(_getVerticalScrollbar,_setVerticalScrollbar)
79 horizontal_scrollbar = property(_getHorizontalScrollbar,_setHorizontalScrollbar)