Mercurial > parpg-source
comparison gui/containergui_base.py @ 0:7a89ea5404b1
Initial commit of parpg-core.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 14 May 2011 01:12:35 -0700 |
parents | |
children | 06145a6ee387 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7a89ea5404b1 |
---|---|
1 # This program is free software: you can redistribute it and/or modify | |
2 # it under the terms of the GNU General Public License as published by | |
3 # the Free Software Foundation, either version 3 of the License, or | |
4 # (at your option) any later version. | |
5 | |
6 # This program is distributed in the hope that it will be useful, | |
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 # GNU General Public License for more details. | |
10 | |
11 # You should have received a copy of the GNU General Public License | |
12 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | |
14 from fife import fife | |
15 from fife.extensions import pychan | |
16 | |
17 from parpg.gui import drag_drop_data as data_drag | |
18 from parpg.objects.action import ACTIONS | |
19 from copy import deepcopy | |
20 | |
21 class ContainerGUIBase(object): | |
22 """ | |
23 Base class for windows that show the content of a container | |
24 """ | |
25 | |
26 | |
27 def __init__(self, controller, gui_file): | |
28 self.controller = controller | |
29 self.gui = pychan.loadXML(gui_file) | |
30 | |
31 def dragDrop(self, obj): | |
32 """Decide whether to drag or drop the image. | |
33 @type obj: string | |
34 @param obj: The name of the object within | |
35 the dictionary 'self.buttons' | |
36 @return: None""" | |
37 if(data_drag.dragging == True): | |
38 self.dropObject(obj) | |
39 elif(data_drag.dragging == False): | |
40 self.dragObject(obj) | |
41 | |
42 def dragObject(self, obj): | |
43 """Drag the selected object. | |
44 @type obj: string | |
45 @param obj: The name of the object within | |
46 the dictionary 'self.buttons' | |
47 @return: None""" | |
48 pass | |
49 | |
50 def dropObject(self, obj): | |
51 """Drops the object being dropped | |
52 @type obj: string | |
53 @param obj: The name of the object within | |
54 the dictionary 'self.buttons' | |
55 @return: None""" | |
56 pass | |
57 | |
58 | |
59 def createMenuItems(self, item, actions): | |
60 """Creates context menu items for all classes based on ContainerGUI""" | |
61 menu_actions = [] | |
62 for action_name in actions: | |
63 display_name = action_name | |
64 if action_name in ACTIONS: | |
65 param_dict = {} | |
66 param_dict["controller"] = self.controller | |
67 param_dict["commands"] = {} | |
68 if action_name == "Look": | |
69 param_dict["examine_name"] = item.name | |
70 param_dict["examine_desc"] = actions[action_name].\ | |
71 pop("text") | |
72 if action_name == "Read": | |
73 param_dict["text_name"] = item.name | |
74 param_dict["text"] = "" | |
75 if action_name == "Use": | |
76 param_dict["item"] = item | |
77 display_name = actions[action_name].pop("text") | |
78 if action_name == "Open": | |
79 param_dict["container"] = item | |
80 if action_name == "BrewBeer": | |
81 param_dict["pot"] = item | |
82 display_name = "Brew beer" | |
83 if actions[action_name]: | |
84 param_dict.update(actions[action_name]) | |
85 menu_actions.append([action_name, | |
86 display_name, | |
87 self.executeMenuItem, | |
88 ACTIONS[action_name]\ | |
89 (**param_dict)]) | |
90 return menu_actions | |
91 | |
92 def showContextMenu(self, event, widget): | |
93 """Decide whether to drag or drop the image. | |
94 @type obj: string | |
95 @param obj: The name of the object within | |
96 the dictionary 'self.buttons' | |
97 @return: None""" | |
98 if event.getButton() == event.RIGHT: | |
99 item = widget.item | |
100 if item and item.trueAttr("usable"): | |
101 actions = deepcopy(item.actions) | |
102 if not actions: | |
103 return | |
104 x_pos, y_pos = widget.getAbsolutePos() | |
105 x_pos += event.getX() | |
106 y_pos += event.getY() | |
107 menu_actions = self.createMenuItems(item, actions) | |
108 self.controller.view.hud.hideContextMenu() | |
109 self.controller.view.hud.showContextMenu(menu_actions, | |
110 (x_pos, | |
111 y_pos) | |
112 ) | |
113 | |
114 def executeMenuItem(self, action): | |
115 """Executes the items action | |
116 @param action: The action to run | |
117 @type action: Class derived from parpg.objects.action.Action | |
118 """ | |
119 action.execute() | |
120 | |
121 def updateImages(self): | |
122 pass |