root/src/statDescription.py @ 575

Revision 575, 2.3 KB (checked in by ecoughlan, 2 years ago)

DIM files and unused imports

Line 
1'''
2Created on April 5, 2012
3
4@author: TechTrek
5'''
6
7from specAnalysis import SpecAnalysis, specAnalysisLUT
8from window import Window
9from closeButton import CloseButton
10from text import Text
11from image import Image
12from lang import listToString
13from dim import statDescriptionDim as DIM
14from dim import closeButtonDim as CLOSE_DIM
15from globals import *
16
17
18class StatDescription(Window):
19    def __init__(self, pos, visible, category):
20        """
21            initializes the components of the StatDescription subclass
22
23            input type: int((x,y)), bool(visible), int(category)
24        """
25        Window.__init__(self, (DIM.LEFT, DIM.TOP), visible)
26        self.category = category
27        self.addImg(Image(self.pos, DIM.W, DIM.H, buttonDir + "bottombar_background"))
28        self.addWindow(CloseButton((self.pos[0] + DIM.CLOSE_X, self.pos[1] + DIM.CLOSE_Y), True, (self.close,)))
29        self.message = ""
30
31    def open(self):
32        """
33            custom open, which makes itself visible and then
34            opens all its subwindows
35           
36            input type: none
37            return type: none
38        """
39        self.visible = True
40        for window in self.subwindows:
41            window.open()
42
43    def update(self, state):
44        """
45            Updates message for the StatDescription based on the
46            current state
47           
48            input type: State(state)
49            return type: none
50        """
51        self.message = ""
52        self.message = self.category.capitalize()
53        self.message += ": " + str(state.specs.stringToValue(self.category)) + "\n"
54        analysis = specAnalysisLUT[self.category]
55        self.message += analysis.getDescription()
56        (toBuy, toDelete) = analysis.suggestions(state)
57        if len(toBuy) != 0:
58            self.message += "Consider buying a "
59            self.message += listToString(toBuy)
60            self.message += "."
61        if len(toDelete) != 0:
62            self.message += "Consider deleting your "
63            if (len(toDelete) > 1):
64                for i in range(len(toDelete) - 1):
65                    self.message += toDelete[i] + ", "
66                self.message += "or "
67            self.message += toDelete[len(toDelete) - 1]
68            self.message += ". "
69
70        self.text = []
71        self.addText(Text((self.pos[0] + 5, self.pos[1] + 5), self.message, MD_TEXT, WHITE, DIM.W - 10))
Note: See TracBrowser for help on using the browser.