comparison gui/containergui_base.py @ 130:aea5a9229b4c

Context menus in container guis now work with components.
author KarstenBock@gmx.net
date Fri, 07 Oct 2011 15:37:44 +0200
parents 4826c8cbd7d8
children 9e86c37f5506
comparison
equal deleted inserted replaced
129:055a14d72184 130:aea5a9229b4c
17 from fife.extensions import pychan 17 from fife.extensions import pychan
18 18
19 from parpg import vfs 19 from parpg import vfs
20 from parpg.gui import drag_drop_data as data_drag 20 from parpg.gui import drag_drop_data as data_drag
21 from parpg.objects.action import ACTIONS 21 from parpg.objects.action import ACTIONS
22 from parpg.entities import General
22 23
23 class ContainerGUIBase(object): 24 class ContainerGUIBase(object):
24 """ 25 """
25 Base class for windows that show the content of a container 26 Base class for windows that show the content of a container
26 """ 27 """
73 data_drag.dragging = True 74 data_drag.dragging = True
74 data_drag.source_container = container 75 data_drag.source_container = container
75 76
76 def createMenuItems(self, item, actions): 77 def createMenuItems(self, item, actions):
77 """Creates context menu items for all classes based on ContainerGUI""" 78 """Creates context menu items for all classes based on ContainerGUI"""
79 assert(isinstance(actions, dict))
80 assert(isinstance(item, General))
78 menu_actions = [] 81 menu_actions = []
82 item_name = item.description.view_name
83 if not actions.has_key("Look"):
84 look_action = actions["Look"] = {}
85 look_action["text"] = item.description.desc
86 if item.container and not actions.has_key("ExamineContents"):
87 actions["ExamineContents"] = {}
79 for action_name in actions: 88 for action_name in actions:
80 display_name = action_name 89 display_name = action_name
81 if action_name in ACTIONS: 90 if action_name in ACTIONS:
82 param_dict = {} 91 param_dict = {}
83 param_dict["controller"] = self.controller 92 param_dict["controller"] = self.controller
84 param_dict["commands"] = {} 93 param_dict["commands"] = {}
85 if action_name == "Look": 94 if action_name == "Look":
86 param_dict["examine_name"] = item.name 95 param_dict["examine_name"] = item_name
87 param_dict["examine_desc"] = actions[action_name].\ 96 param_dict["examine_desc"] = actions[action_name].\
88 pop("text") 97 pop("text")
89 if action_name == "Read": 98 if action_name == "Read":
90 param_dict["text_name"] = item.name 99 param_dict["text_name"] = item_name
91 param_dict["text"] = "" 100 param_dict["text"] = ""
92 if action_name == "Use": 101 if action_name == "Use":
93 param_dict["item"] = item 102 param_dict["item"] = item
94 display_name = actions[action_name].pop("text") 103 display_name = actions[action_name].pop("text")
95 if action_name == "Open": 104 if action_name == "ExamineContents":
96 param_dict["container"] = item 105 param_dict["container"] = item
106 display_name = "Examine Contents"
97 if action_name == "BrewBeer": 107 if action_name == "BrewBeer":
98 param_dict["pot"] = item 108 param_dict["pot"] = item
99 display_name = "Brew beer" 109 display_name = "Brew beer"
100 if actions[action_name]: 110 if actions[action_name]:
101 param_dict.update(actions[action_name]) 111 param_dict.update(actions[action_name])
112 @param obj: The name of the object within 122 @param obj: The name of the object within
113 the dictionary 'self.buttons' 123 the dictionary 'self.buttons'
114 @return: None""" 124 @return: None"""
115 if event.getButton() == event.RIGHT: 125 if event.getButton() == event.RIGHT:
116 item = widget.item 126 item = widget.item
117 if item and item.trueAttr("usable"): 127 if item:
118 actions = deepcopy(item.actions) 128 item = item.entity
119 if not actions: 129 actions = {}
120 return 130 if item.usable:
131 actions = deepcopy(item.usable.actions)
121 x_pos, y_pos = widget.getAbsolutePos() 132 x_pos, y_pos = widget.getAbsolutePos()
122 x_pos += event.getX() 133 x_pos += event.getX()
123 y_pos += event.getY() 134 y_pos += event.getY()
124 menu_actions = self.createMenuItems(item, actions) 135 menu_actions = self.createMenuItems(item, actions)
125 self.controller.view.hud.hideContextMenu() 136 self.controller.view.hud.hideContextMenu()