1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from fife import fife
17 from fife.extensions import pychan
18
19 from scripts.gui import drag_drop_data as data_drag
20 from scripts.objects.action import ACTIONS
21 from copy import deepcopy
22
24 """
25 Base class for windows that show the content of a container
26 """
27
28
29 - def __init__(self, controller, gui_file):
30 self.controller = controller
31 self.gui = pychan.loadXML(gui_file)
32
34 """Decide whether to drag or drop the image.
35 @type obj: string
36 @param obj: The name of the object within
37 the dictionary 'self.buttons'
38 @return: None"""
39 if(data_drag.dragging == True):
40 self.dropObject(obj)
41 elif(data_drag.dragging == False):
42 self.dragObject(obj)
43
45 """Drag the selected object.
46 @type obj: string
47 @param obj: The name of the object within
48 the dictionary 'self.buttons'
49 @return: None"""
50 pass
51
53 """Drops the object being dropped
54 @type obj: string
55 @param obj: The name of the object within
56 the dictionary 'self.buttons'
57 @return: None"""
58 pass
59
60
62 """Creates context menu items for all classes based on ContainerGUI"""
63 menu_actions = []
64 for action_name in actions:
65 display_name = action_name
66 if action_name in ACTIONS:
67 param_dict = {}
68 param_dict["controller"] = self.controller
69 param_dict["commands"] = {}
70 if action_name == "Look":
71 param_dict["examine_name"] = item.name
72 param_dict["examine_desc"] = actions[action_name].\
73 pop("text")
74 if action_name == "Read":
75 param_dict["text_name"] = item.name
76 param_dict["text"] = ""
77 if action_name == "Use":
78 param_dict["item"] = item
79 display_name = actions[action_name].pop("text")
80 if action_name == "Open":
81 param_dict["container"] = item
82 if action_name == "BrewBeer":
83 param_dict["pot"] = item
84 display_name = "Brew beer"
85 if actions[action_name]:
86 param_dict.update(actions[action_name])
87 menu_actions.append([action_name,
88 display_name,
89 self.executeMenuItem,
90 ACTIONS[action_name]\
91 (**param_dict)])
92 return menu_actions
93
95 """Decide whether to drag or drop the image.
96 @type obj: string
97 @param obj: The name of the object within
98 the dictionary 'self.buttons'
99 @return: None"""
100 if event.getButton() == event.RIGHT:
101 item = widget.item
102 if item and item.trueAttr("usable"):
103 actions = deepcopy(item.actions)
104 if not actions:
105 return
106 x_pos, y_pos = widget.getAbsolutePos()
107 x_pos += event.getX()
108 y_pos += event.getY()
109 menu_actions = self.createMenuItems(item, actions)
110 self.controller.view.hud.hideContextMenu()
111 self.controller.view.hud.showContextMenu(menu_actions,
112 (x_pos,
113 y_pos)
114 )
115
117 """Executes the items action
118 @param action: The action to run
119 @type action: Class derived from scripts.objects.action.Action
120 """
121 action.execute()
122
125