source: branches/active/character_customization/game/parpg/gui/tabwidget.py @ 833

Revision 785, 3.4 KB checked in by technomage, 9 years ago (diff)

Patch by Technomage

  • Mostly finished the character creation GUI in gui/character_screen.xml - still needs a few cosmetic touch-ups and it hasn't been tested with stats, traits, and skills lists yet;
  • Added a new CharacterCreationView? class in parpg/gui/charactercreationview.py which should be used by the CharacterCreationController? to display the character creation GUI. It is mostly a skeleton at this point, however, and it hasn't been integrated with the controller yet;
  • Fixed a few graphical glitches in the Spinner widget in parpg/gui/spinners.py that caused the text field to be positioned incorrectly;
  • Added a few new properties to the Spinner widget, including background_color, min_size and max_size, which override the inherited properties. Spinner widgets that uses these properties should now behave in a much more intuitive way;
  • Re-sized the gui/notebook/notebook_background.png background image to 800x600 to accommodate tab-buttons on the edges of the notebook;
  • Added a new widget, TabWidget?, which consists of a view that has tabs which can switch between the various views. Views in a TabWidget? can be added in XML as child tags whose name attribute ends up as the tab text;
  • Added two new size fonts to fonts/oldtypewriter.fontdef, 9 pt and 10 pt;
Line 
1from fife.extensions.pychan.widgets import VBox, HBox, ScrollArea, Button
2from fife.extensions.pychan.tools import callbackWithArguments
3
4class 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()
Note: See TracBrowser for help on using the repository browser.