Package scripts :: Package gui :: Script containergui_base
[hide private]
[frames] | no frames]

Source Code for Script scripts.gui.containergui_base

  1  #!/usr/bin/env python 
  2   
  3  #   This program is free software: you can redistribute it and/or modify 
  4  #   it under the terms of the GNU General Public License as published by 
  5  #   the Free Software Foundation, either version 3 of the License, or 
  6  #   (at your option) any later version. 
  7   
  8  #   This program is distributed in the hope that it will be useful, 
  9  #   but WITHOUT ANY WARRANTY; without even the implied warranty of 
 10  #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 11  #   GNU General Public License for more details. 
 12   
 13  #   You should have received a copy of the GNU General Public License 
 14  #   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 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   
23 -class ContainerGUIBase(object):
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
33 - def dragDrop(self, obj):
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
44 - def dragObject(self, obj):
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
52 - def dropObject(self, obj):
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
61 - def createMenuItems(self, item, actions):
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
94 - def showContextMenu(self, event, widget):
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
116 - def executeMenuItem(self, action):
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
123 - def updateImages(self):
124 pass
125