source: branches/active/character_customization/game/parpg/gui/actionsbox.py @ 736

Revision 736, 2.9 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • renamed scripts package to parpg
  • renamed parpg module to application
  • removed packaging and other related files (kept locally for reference, will reintroduce similar scripts to resolve bug #275
  • updated all import statements to respect changes above
  • Property svn:eol-style set to native
Line 
1#!/usr/bin/env python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18"""Widget for displaying actions"""
19
20from fife.extensions import pychan
21from fife.extensions.pychan import ScrollArea
22from fife.extensions.pychan import VBox
23
24class ActionsBox(ScrollArea):
25    def __init__(self, **kwargs):
26        ScrollArea.__init__(self, **kwargs)
27        self.ContentBox = VBox(name = "ActionsContentBox", is_focusable=False)
28        self.addChild(self.ContentBox)
29   
30    def refresh(self):
31        """Refresh the actions box so that it displays the contents of
32        self.actions_text
33        @return: None"""
34        self.adaptLayout()
35        self.vertical_scroll_amount = self.getVerticalMaxScroll()
36
37    def addAction(self, action):
38        """Add an action to the actions box.
39        @type action: (unicode) string
40        @param action: The text that you want to display in the actions box
41        @return: None"""     
42     
43        if not type(action) is unicode:
44            action = unicode(action)
45        action_label = pychan.widgets.Label(text = action, wrap_text = True)
46        action_label.max_width = self.ContentBox.width
47        self.ContentBox.addChild(action_label)
48        self.refresh()
49   
50    def addDialog(self, name, text):
51        """Add a dialog text to the actions box. Prints first the name and then, indented to the right, the text.
52        @type name: (unicode) string
53        @param action: The name of the character that spoke
54        @type text:: (unicode) string
55        @param text: The text that was said
56        @return: None"""       
57        if not type(name) is unicode:
58            name = unicode(name)
59        if not type(text) is unicode:
60            text = unicode(text)
61       
62       
63        name_label = pychan.widgets.Label(text = name, wrap_text = True)
64        self.ContentBox.addChild(name_label)
65        text_box = pychan.widgets.HBox()
66        spacer = pychan.widgets.Label()
67        spacer.min_width = int(self.ContentBox.width * 0.05)
68        spacer.max_width = int(self.ContentBox.width * 0.05)
69        text_box.addChild(spacer)
70        text_label = pychan.widgets.Label(text = text, wrap_text = True)
71        text_label.max_width = int(self.ContentBox.width * 0.95)
72        text_box.addChild(text_label)
73        self.ContentBox.addChild(text_box)
74        self.refresh()
75       
Note: See TracBrowser for help on using the repository browser.