source: trunk/PARPG/scripts/gui_container.py @ 168

Revision 168, 3.4 KB checked in by bretzel_parpg, 10 years ago (diff)

When you select open on a crate, it now will pop up a window displaying the contents of the crate
(which right now are just a bunch of backpack images)

Line 
1#/usr/bin/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
18import fife
19import pychan
20from pychan.tools import callbackWithArguments as cbwa
21
22class ContainerGUI():
23    def __init__(self, engine, title, data):
24        """
25        A class to create a window showing the contents of a container.
26       
27        @type engine: fife.Engine
28        @param engine: an instance of the fife engine
29        @type title: string
30        @param title: The title of the window
31        @type data: list or string
32        @param data: A list of 9 images to use for the slots 1 - 9 OR a string for one image that will be used on all the slots
33        @return: None
34        """
35        pychan.init(engine, debug=True)
36       
37        self.container_gui = pychan.loadXML("gui/container_base.xml")
38        self.container_gui.findChild(name="topWindow").title = title
39
40   
41        if type(data) == list:
42            self.setContainerImage("Slot1", data[1])
43            self.setContainerImage("Slot2", data[2])
44            self.setContainerImage("Slot3", data[3])
45            self.setContainerImage("Slot4", data[4])
46            self.setContainerImage("Slot5", data[5])
47            self.setContainerImage("Slot6", data[6])
48            self.setContainerImage("Slot7", data[7])
49            self.setContainerImage("Slot8", data[8])
50            self.setContainerImage("Slot9", data[9])
51            print "Setting slots to list: " + data
52
53        else:
54            self.setContainerImage("Slot1", data)
55            self.setContainerImage("Slot2", data)
56            self.setContainerImage("Slot3", data)
57            self.setContainerImage("Slot4", data)
58            self.setContainerImage("Slot5", data)
59            self.setContainerImage("Slot6", data)
60            self.setContainerImage("Slot7", data)
61            self.setContainerImage("Slot8", data)
62            self.setContainerImage("Slot9", data)
63            print "Setting slots to string: " + data
64           
65        container_events = {'takeAllButton':self.nullFunc,
66                            'closeButton':self.hideContainer}
67
68        self.container_gui.mapEvents(container_events)
69
70    def nullFunc(self):
71        pass
72
73    def setContainerImage(self, widget_name, image):
74        """
75        Sets the up, down, and hover images of an image button to image
76
77        @type widget_name: string
78        @param widget_name: the name of the widget
79        @type image: string
80        @param image: the path to the image
81        @return None
82        """
83        widget = self.container_gui.findChild(name=widget_name)
84        widget.up_image = image
85        widget.down_image = image
86        widget.hover_image = image
87        print 'Set all images on %s using %s' % (widget, image)
88       
89    def showContainer(self):
90        self.container_gui.show()
91
92    def hideContainer(self):
93        self.container_gui.hide()
94       
Note: See TracBrowser for help on using the repository browser.