Package muntjac :: Package event :: Module action
[hide private]
[frames] | no frames]

Source Code for Module muntjac.event.action

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  """Implements the action framework.""" 
 17   
 18   
19 -class Action(object):
20 """Implements the action framework. This class contains subinterfaces for 21 action handling and listing, and for action handler registrations and 22 unregistration. 23 24 @author: Vaadin Ltd. 25 @author: Richard Lincoln 26 @version: 1.1.2 27 """ 28
29 - def __init__(self, caption, icon=None):
30 """Constructs a new action with the given caption string and icon. 31 32 @param caption: 33 the caption for the new action. 34 @param icon: 35 the icon for the new action. 36 """ 37 #: Action title. 38 self._caption = caption 39 40 #: Action icon. 41 self._icon = icon
42 43
44 - def __eq__(self, other):
45 return ((self._caption == other.getCaption()) 46 and (self._icon == other.getIcon()))
47 48
49 - def getCaption(self):
50 """Returns the action's caption. 51 52 @return: the action's caption as a string. 53 """ 54 return self._caption
55 56
57 - def getIcon(self):
58 """Returns the action's icon. 59 60 @return: the action's Icon. 61 """ 62 return self._icon
63 64
65 - def setCaption(self, caption):
66 """Sets the caption. 67 68 @param caption: 69 the caption to set. 70 """ 71 self._caption = caption
72 73
74 - def setIcon(self, icon):
75 """Sets the icon. 76 77 @param icon: 78 the icon to set. 79 """ 80 self._icon = icon
81 82
83 -class IContainer(object):
84 """Interface implemented by all components where actions can be registered. 85 This means that the components lets others to register as action handlers 86 to it. When the component receives an action targeting its contents it 87 should loop all action handlers registered to it and let them handle the 88 action. 89 90 @author: Vaadin Ltd. 91 @author: Richard Lincoln 92 @version: 1.1.2 93 """ 94
95 - def addActionHandler(self, actionHandler):
96 """Registers a new action handler for this container 97 98 @param actionHandler: 99 the new handler to be added. 100 """ 101 raise NotImplementedError
102 103
104 - def removeActionHandler(self, actionHandler):
105 """Removes a previously registered action handler for the contents of 106 this container. 107 108 @param actionHandler: 109 the handler to be removed. 110 """ 111 raise NotImplementedError
112 113
114 -class IListener(object):
115 """An Action that implements this interface can be added to an Notifier 116 (or NotifierProxy) via the C{addAction()}-method, which in many cases is 117 easier than implementing the IHandler interface. 118 """ 119
120 - def handleAction(self, sender, target):
121 raise NotImplementedError
122 123
124 -class INotifier(IContainer):
125 """Containers implementing this support an easier way of adding single 126 Actions than the more involved IHandler. The added actions must be 127 Listeners, thus handling the action themselves. 128 """ 129
130 - def addAction(self, action):
131 raise NotImplementedError
132 133
134 - def removeAction(self, action):
135 raise NotImplementedError
136 137
138 -class IShortcutNotifier(object):
139
140 - def addShortcutListener(self, shortcut):
141 raise NotImplementedError
142 143
144 - def removeShortcutListener(self, shortcut):
145 raise NotImplementedError
146 147
148 -class IHandler(object):
149 """Interface implemented by classes who wish to handle actions. 150 151 @author: Vaadin Ltd. 152 @author: Richard Lincoln 153 @version: 1.1.2 154 """ 155
156 - def getActions(self, target, sender):
157 """Gets the list of actions applicable to this handler. 158 159 @param target: 160 the target handler to list actions for. For item 161 containers this is the item id. 162 @param sender: 163 the party that would be sending the actions. Most of this 164 is the action container. 165 @return: the list of Action 166 """ 167 raise NotImplementedError
168 169
170 - def handleAction(self, a, sender, target):
171 """Handles an action for the given target. The handler method may just 172 discard the action if it's not suitable. 173 174 @param a: 175 the action to be handled. 176 @param sender: 177 the sender of the action. This is most often the action 178 container. 179 @param target: 180 the target of the action. For item containers this is the 181 item id. 182 """ 183 raise NotImplementedError
184