Mercurial > parpg-source
diff 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 |
line wrap: on
line diff
--- a/gui/containergui_base.py Fri Oct 07 14:52:09 2011 +0200 +++ b/gui/containergui_base.py Fri Oct 07 15:37:44 2011 +0200 @@ -19,6 +19,7 @@ from parpg import vfs from parpg.gui import drag_drop_data as data_drag from parpg.objects.action import ACTIONS +from parpg.entities import General class ContainerGUIBase(object): """ @@ -75,7 +76,15 @@ def createMenuItems(self, item, actions): """Creates context menu items for all classes based on ContainerGUI""" + assert(isinstance(actions, dict)) + assert(isinstance(item, General)) menu_actions = [] + item_name = item.description.view_name + if not actions.has_key("Look"): + look_action = actions["Look"] = {} + look_action["text"] = item.description.desc + if item.container and not actions.has_key("ExamineContents"): + actions["ExamineContents"] = {} for action_name in actions: display_name = action_name if action_name in ACTIONS: @@ -83,17 +92,18 @@ param_dict["controller"] = self.controller param_dict["commands"] = {} if action_name == "Look": - param_dict["examine_name"] = item.name + param_dict["examine_name"] = item_name param_dict["examine_desc"] = actions[action_name].\ pop("text") if action_name == "Read": - param_dict["text_name"] = item.name + param_dict["text_name"] = item_name param_dict["text"] = "" if action_name == "Use": param_dict["item"] = item display_name = actions[action_name].pop("text") - if action_name == "Open": + if action_name == "ExamineContents": param_dict["container"] = item + display_name = "Examine Contents" if action_name == "BrewBeer": param_dict["pot"] = item display_name = "Brew beer" @@ -114,10 +124,11 @@ @return: None""" if event.getButton() == event.RIGHT: item = widget.item - if item and item.trueAttr("usable"): - actions = deepcopy(item.actions) - if not actions: - return + if item: + item = item.entity + actions = {} + if item.usable: + actions = deepcopy(item.usable.actions) x_pos, y_pos = widget.getAbsolutePos() x_pos += event.getX() y_pos += event.getY()