comparison src/parpg/gui/actionsbox.py @ 0:1fd2201f5c36

Initial commit of parpg-core.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 14 May 2011 01:12:35 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1fd2201f5c36
1 # This file is part of PARPG.
2
3 # PARPG is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7
8 # PARPG is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
15
16 """Widget for displaying actions"""
17
18 from fife.extensions import pychan
19 from fife.extensions.pychan import ScrollArea
20 from fife.extensions.pychan import VBox
21
22 class ActionsBox(ScrollArea):
23 def __init__(self, **kwargs):
24 ScrollArea.__init__(self, **kwargs)
25 self.ContentBox = VBox(name = "ActionsContentBox", is_focusable=False)
26 self.addChild(self.ContentBox)
27
28 def refresh(self):
29 """Refresh the actions box so that it displays the contents of
30 self.actions_text
31 @return: None"""
32 self.adaptLayout()
33 self.vertical_scroll_amount = self.getVerticalMaxScroll()
34
35 def addAction(self, action):
36 """Add an action to the actions box.
37 @type action: (unicode) string
38 @param action: The text that you want to display in the actions box
39 @return: None"""
40
41 if not type(action) is unicode:
42 action = unicode(action)
43 action_label = pychan.widgets.Label(text = action, wrap_text = True)
44 action_label.max_width = self.ContentBox.width
45 self.ContentBox.addChild(action_label)
46 self.refresh()
47
48 def addDialog(self, name, text):
49 """Add a dialog text to the actions box. Prints first the name and then, indented to the right, the text.
50 @type name: (unicode) string
51 @param action: The name of the character that spoke
52 @type text:: (unicode) string
53 @param text: The text that was said
54 @return: None"""
55 if not type(name) is unicode:
56 name = unicode(name)
57 if not type(text) is unicode:
58 text = unicode(text)
59
60
61 name_label = pychan.widgets.Label(text = name, wrap_text = True)
62 self.ContentBox.addChild(name_label)
63 text_box = pychan.widgets.HBox()
64 spacer = pychan.widgets.Label()
65 spacer.min_width = int(self.ContentBox.width * 0.05)
66 spacer.max_width = int(self.ContentBox.width * 0.05)
67 text_box.addChild(spacer)
68 text_label = pychan.widgets.Label(text = text, wrap_text = True)
69 text_label.max_width = int(self.ContentBox.width * 0.95)
70 text_box.addChild(text_label)
71 self.ContentBox.addChild(text_box)
72 self.refresh()
73