annotate engine/extensions/pychan/widgets/containers.py @ 354:dfd48d49c044

* Removed shebang and svn:executable for python files which are not meant to be executed directly * Made sure all executable files with shebang has svn:executable
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 21 Sep 2009 19:48:00 +0000
parents 48c99636453e
children
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
331
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
3 # ####################################################################
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
5 # http://www.fifengine.de
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
6 # This file is part of FIFE.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
7 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
8 # FIFE is free software; you can redistribute it and/or
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
10 # License as published by the Free Software Foundation; either
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
12 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
13 # This library is distributed in the hope that it will be useful,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
16 # Lesser General Public License for more details.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
17 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
19 # License along with this library; if not, write to the
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
20 # Free Software Foundation, Inc.,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
22 # ####################################################################
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
23
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 from common import *
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 from widget import Widget
249
1cc51d145af9 Further split up the containers.py; bugfix.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 248
diff changeset
26 from layout import VBoxLayoutMixin, HBoxLayoutMixin
248
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 class Container(Widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 This is the basic container class. It provides space in which child widgets can
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 be position via the position attribute. If you want to use the layout engine,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 you have to use derived containers with vertical or horizontal orientation
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 (L{VBox} or L{HBox})
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 New Attributes
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 ==============
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 - padding - Integer: Not used in the Container class istelf, distance between child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 - background_image - Set this to a GuiImage or a resource location (simply a filename).
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 The image will be tiled over the background area.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 - opaque - Boolean: Whether the background should be drawn at all. Set this to False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 to make the widget transparent.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 - children - Just contains the list of contained child widgets. Do NOT modify.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 ATTRIBUTES = Widget.ATTRIBUTES + [ IntAttr('padding'), Attr('background_image'), BoolAttr('opaque'),PointAttr('margins') ]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 def __init__(self,padding=5,margins=(5,5),_real_widget=None, **kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 self.real_widget = _real_widget or fife.Container()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 self.children = []
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 self.margins = margins
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self.padding = padding
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self._background = []
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 self._background_image = None
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 super(Container,self).__init__(**kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 def addChild(self, widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 widget.parent = self
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 self.children.append(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self.real_widget.add(widget.real_widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
62 def insertChild(self, widget, position):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
63 if position > len(self.children) or 0-position > len(self.children):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
64 print "insertChild: Warning: Index overflow.",
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
65 if position >= 0:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
66 self.addChild(widget)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
67 else:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
68 self.insertChild(widget, 0)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
69 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
70
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
71 children = self.children[0:position]+[widget]+self.children[position:]
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
72 #assert len(children) == len(self.children) + 1
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
73 self.removeAllChildren()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
74 for child in children:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
75 self.addChild(child)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
76
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
77 def insertChildBefore(self, widget, before):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
78 if before not in self.children:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
79 raise RuntimeError("Couldn't find widget %s as child of %s - in insertChildBefore" % (str(widget),str(before)))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
80 self.insertChild(widget, self.children.index(before))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
81
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 def removeChild(self,widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 if not widget in self.children:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 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
85 self.children.remove(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self.real_widget.remove(widget.real_widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 widget.parent = None
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 def add(self,*widgets):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 print "PyChan: Deprecation warning: Please use 'addChild' or 'addChildren' instead."
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 self.addChildren(*widgets)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 def getMaxChildrenWidth(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 if not self.children: return 0
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 return max(widget.width for widget in self.children)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 def getMaxChildrenHeight(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 if not self.children: return 0
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 return max(widget.height for widget in self.children)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
101 def deepApply(self,visitorFunc, leaves_first = True):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
102 if leaves_first:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
103 for child in self.children:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
104 child.deepApply(visitorFunc, leaves_first = leaves_first)
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 visitorFunc(self)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
106 if not leaves_first:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
107 for child in self.children:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
108 child.deepApply(visitorFunc, leaves_first = leaves_first)
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 def beforeShow(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 self._resetTiling()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 def _resetTiling(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 image = self._background_image
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 if image is None:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 return
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 back_w,back_h = self.width, self.height
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 image_w, image_h = image.getWidth(), image.getHeight()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 map(self.real_widget.remove,self._background)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 # Now tile the background over the widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 self._background = []
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 icon = fife.Icon(image)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 x, w = 0, image_w
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 while x < back_w:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 y, h = 0, image_h
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 while y < self.height:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 icon = fife.Icon(image)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 icon.setPosition(x,y)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 self._background.append(icon)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 y += h
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 x += w
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 map(self.real_widget.add,self._background)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 for tile in self._background:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 tile.requestMoveToBottom()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 def setBackgroundImage(self,image):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 self._background = getattr(self,'_background',None)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 if image is None:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 self._background_image = image
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 map(self.real_widget.remove,self._background)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 self._background = []
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
145 return
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 # Background generation is done in _resetTiling
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 if not isinstance(image, fife.GuiImage):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 image = get_manager().loadImage(image)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 self._background_image = image
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 def getBackgroundImage(self): return self._background_image
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 background_image = property(getBackgroundImage,setBackgroundImage)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 def _setOpaque(self,opaque): self.real_widget.setOpaque(opaque)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 def _getOpaque(self): return self.real_widget.isOpaque()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 opaque = property(_getOpaque,_setOpaque)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 class VBox(VBoxLayoutMixin,Container):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 A vertically aligned box - for containement of child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 Widgets added to this container widget, will layout on top of each other.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 Also the minimal width of the container will be the maximum of the minimal
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 widths of the contained widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 The default alignment is to the top. This can be changed by adding a Spacer
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 to the widget at any point (but only one!). The spacer will expand, so that
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 widgets above the spacer are aligned to the top, while widgets below the spacer
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 are aligned to the bottom.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
172 DEFAULT_HEXPAND = 0
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
173 DEFAULT_VEXPAND = 1
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
174
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 def __init__(self,padding=5,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 super(VBox,self).__init__(**kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 self.padding = padding
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 class HBox(HBoxLayoutMixin,Container):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 A horizontally aligned box - for containement of child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 Please see L{VBox} for details - just change the directions :-).
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
186 DEFAULT_HEXPAND = 1
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
187 DEFAULT_VEXPAND = 0
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
188
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 def __init__(self,padding=5,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 super(HBox,self).__init__(**kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 self.padding = padding
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 class Window(VBoxLayoutMixin,Container):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 A L{VBox} with a draggable title bar aka a window
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 New Attributes
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 ==============
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 - title: The Caption of the window
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 - titlebar_height: The height of the window title bar
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 ATTRIBUTES = Container.ATTRIBUTES + [ UnicodeAttr('title'), IntAttr('titlebar_height') ]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 def __init__(self,title=u"title",titlebar_height=0,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 super(Window,self).__init__(_real_widget = fife.Window(), **kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 if titlebar_height == 0:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 titlebar_height = self.real_font.getHeight() + 4
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 self.titlebar_height = titlebar_height
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 self.title = title
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 # Override explicit positioning
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 self.position_technique = "automatic"
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 def _getTitle(self): return gui2text(self.real_widget.getCaption())
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 def _setTitle(self,text): self.real_widget.setCaption(text2gui(text))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 title = property(_getTitle,_setTitle)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 def _getTitleBarHeight(self): return self.real_widget.getTitleBarHeight()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 def _setTitleBarHeight(self,h): self.real_widget.setTitleBarHeight(h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 titlebar_height = property(_getTitleBarHeight,_setTitleBarHeight)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 # Hackish way of hiding that title bar height in the perceived height.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 # Fixes VBox calculation
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227 def _setHeight(self,h):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228 h = max(self.min_size[1],h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 h = min(self.max_size[1],h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 self.real_widget.setHeight(h + self.titlebar_height)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231 def _getHeight(self): return self.real_widget.getHeight() - self.titlebar_height
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
232 height = property(_getHeight,_setHeight)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233