changeset 160:ca699b402790

Context menus in container guis now work with components.
author KarstenBock@gmx.net
date Fri, 07 Oct 2011 15:37:44 +0200
parents 65f8b83493d8
children d1f9652d0651
files src/parpg/gui/containergui_base.py
diffstat 1 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/parpg/gui/containergui_base.py	Fri Oct 07 14:52:09 2011 +0200
+++ b/src/parpg/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()