Mercurial > fife-parpg
annotate engine/extensions/pychan/widgets/scrollarea.py @ 255:51cc05d862f2
Merged editor_rewrite branch to trunk.
This contains changes that may break compatibility against existing clients.
For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 16:00:02 +0000 |
parents | a2d5e2721489 |
children | 48c99636453e |
rev | line source |
---|---|
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 from common import * |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 from widget import Widget |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 class ScrollArea(Widget): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 A wrapper around another (content) widget. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 New Attributes |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 ============== |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 - content: The wrapped widget. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 - vertical_scrollbar: Boolean: Set this to False to hide the Vertical scrollbar |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 - horizontal_scrollbar: Boolean: Set this to False to hide the Horizontal scrollbar |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 ATTRIBUTES = Widget.ATTRIBUTES + [ BoolAttr("vertical_scrollbar"),BoolAttr("horizontal_scrollbar") ] |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
20 DEFAULT_HEXPAND = 1 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
21 DEFAULT_VEXPAND = 1 |
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 def __init__(self,**kwargs): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 self.real_widget = fife.ScrollArea() |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 self._content = None |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 super(ScrollArea,self).__init__(**kwargs) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 def addChild(self,widget): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 self.content = widget |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 widget.parent = self |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 def removeChild(self,widget): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 if self._content != widget: |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 raise RuntimeError("%s does not have %s as direct child widget." % (str(self),str(widget))) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self.content = None |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 widget.parent = None |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 def _setContent(self,content): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 if content is None: |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 self.real_widget.setContent(content) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 else: |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 self.real_widget.setContent(content.real_widget) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 self._content = content |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 def _getContent(self): return self._content |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 content = property(_getContent,_setContent) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
47 def deepApply(self,visitorFunc, leaves_first = True): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
48 if leaves_first: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
49 if self._content: self._content.deepApply(visitorFunc, leaves_first = leaves_first) |
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 visitorFunc(self) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
51 if not leaves_first: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
52 if self._content: self._content.deepApply(visitorFunc, leaves_first = leaves_first) |
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 def resizeToContent(self,recurse=True): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 if self._content is None: return |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 if recurse: |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
57 self.content.resizeToContent(recurse=recurse) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
58 self.size = self.min_size |
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 def _visibilityToScrollPolicy(self,visibility): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 if visibility: |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 return fife.ScrollArea.SHOW_AUTO |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 return fife.ScrollArea.SHOW_NEVER |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 def _scrollPolicyToVisibility(self,policy): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 if policy == fife.ScrollArea.SHOW_NEVER: |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 return False |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 return True |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 def _setHorizontalScrollbar(self,visibility): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 self.real_widget.setHorizontalScrollPolicy( self._visibilityToScrollPolicy(visibility) ) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 def _setVerticalScrollbar(self,visibility): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 self.real_widget.setVerticalScrollPolicy( self._visibilityToScrollPolicy(visibility) ) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 def _getHorizontalScrollbar(self): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 return self._scrollPolicyToVisibility( self.real_widget.getHorizontalScrollPolicy() ) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 def _getVerticalScrollbar(self): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 return self._scrollPolicyToVisibility( self.real_widget.getVerticalScrollPolicy() ) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
81 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
82 def sizeChanged(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
83 if self.content: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
84 self.content.width = max(self.content.width,self.width-5) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
248
diff
changeset
|
85 self.content.height = max(self.content.height,self.height-5) |
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 vertical_scrollbar = property(_getVerticalScrollbar,_setVerticalScrollbar) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 horizontal_scrollbar = property(_getHorizontalScrollbar,_setHorizontalScrollbar) |