comparison gui/tabwidget.py @ 0:7a89ea5404b1

Initial commit of parpg-core.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 14 May 2011 01:12:35 -0700
parents
children 5b880b8cff6d
comparison
equal deleted inserted replaced
-1:000000000000 0:7a89ea5404b1
1 from fife.extensions.pychan.widgets import VBox, HBox, ScrollArea, Button
2 from fife.extensions.pychan.tools import callbackWithArguments
3
4 class TabWidget(VBox):
5 def min_size():
6 def fget(self):
7 return self._min_size
8
9 def fset(self, min_size):
10 self._min_size = min_size
11 self.view.min_size = min_size
12 self.adaptLayout()
13
14 return locals()
15 min_size = property(**min_size())
16
17 def max_size():
18 def fget(self):
19 return self._max_size
20
21 def fset(self, max_size):
22 self._max_size = max_size
23 self.view.max_size = max_size
24 self.adaptLayout()
25
26 return locals()
27 max_size = property(**max_size())
28
29 def opaque():
30 def fget(self):
31 return self._getOpaque()
32
33 def fset(self, opaque):
34 self._setOpaque(opaque)
35 self.view.opaque = opaque
36 base_color = self.view.base_color
37 base_red = base_color.r
38 base_green = base_color.g
39 base_blue = base_color.b
40 background_color = self.view.background_color
41 background_red = background_color.r
42 background_green = background_color.g
43 background_blue = background_color.b
44 alpha = 255 if opaque else 0
45 self.view.base_color = (base_red, base_green, base_blue, alpha)
46 self.view.background_color = (background_red, background_green,
47 background_blue, alpha)
48
49 return locals()
50 opaque = property(**opaque())
51
52 def border_size():
53 def fget(self):
54 frame = self.findChild(name='frame')
55 return frame.border_size
56
57 def fset(self, border_size):
58 frame = self.findChild(name='frame')
59 frame.border_size = border_size
60
61 return locals()
62 border_color = property(**border_size())
63
64 def __init__(self, min_size=(0, 0), max_size=(9999, 9999), border_size=1,
65 **kwargs):
66 self._min_size = min_size
67 self._max_size = max_size
68 self.views = {}
69 tab_bar = HBox(name='tabBar')
70 tab_bar.min_size = (0, 20)
71 tab_bar.max_size = (9999, 20)
72 self.view = ScrollArea(name='view')
73 self.view.min_size = self._min_size
74 self.view.max_size = self._max_size
75 self.view.border_size = border_size
76 frame = VBox(name='frame')
77 frame.border_size = border_size
78 frame.opaque = 0
79 frame.addChild(self.view)
80 VBox.__init__(self, **kwargs)
81 self.padding = 0
82 VBox.addChild(self, tab_bar)
83 VBox.addChild(self, frame)
84 self.adaptLayout()
85
86 def addTab(self, text):
87 text = unicode(text)
88 tab = Button(text=text)
89 tab_bar = self.findChild(name='tabBar')
90 tab_bar.addChild(tab)
91 tab.capture(callbackWithArguments(self.showView, text))
92 self.adaptLayout()
93
94 def addChild(self, child):
95 name = child.name or unicode(str(child))
96 self.addTab(name)
97 self.views[name] = child
98 if len(self.views) == 1:
99 # Show the first view by default.
100 self.showView(name)
101
102 def showView(self, name):
103 view = self.views[name]
104 self.view.content = view
105 self.adaptLayout()