Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net> 2 # 3 # This file is part of pytilities. 4 # 5 # pytilities is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # pytilities is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with pytilities. If not, see <http://www.gnu.org/licenses/>. 17 # 18 19 __docformat__ = 'reStructuredText' 20 21 from pytilities.delegation import ( 22 delegator_factory, delegated) 23 from . import UnsupportedEventError27 28 """ 29 Provides a single interface to multiple event dispatchers. 30 31 Events are switched to the the first event dispatcher in a list of 32 dispatchers that supports the event, the other dispatchers are ignored for 33 that particular event. 34 35 This is also how remove_handlers will look for 36 handlers, it will only remove the handlers of each event's first found 37 dispatcher; the other ones are 'hidden' by this one, for this event. 38 39 Check `Dispatcher` for the documentation of the methods that are left 40 undocumented here. 41 42 Instance methods: 43 44 - `append_dispatchers`: Add dispatchers to the list of dispatchers 45 - ... 46 """ 47 # TODO: find a way to copy those bits of doc to our methods here, but 48 # first, wait for that reST python reader 49 50 # I wonder, it's really more of a router, isn't it 51 52 @staticmethod 55 58110 111 @delegated("public")60 """ 61 Add dispatchers to the end of the list of dispatchers. 62 63 Parameters: 64 65 dispatchers :: (Dispatcher...) 66 sequence of dispatchers to append 67 """ 68 self.__dispatchers.extend(dispatchers)6971 """ 72 Get the dispatcher for the given event according to our switching 73 rules 74 """ 75 for dispatcher in self.__dispatchers: 76 if dispatcher.has_event(event_name): 77 return dispatcher 78 else: 79 raise UnsupportedEventError(event_name)80 81 @delegated("public")83 dispatcher = self.__get_dispatcher_for_event(event_name) 84 dispatcher.add_handler(event_name, handler, owner)85 86 @delegated("public")88 # Run through our supported events, remove all handlers for each 89 # supported event on the first dispatcher that supports it 90 if event_name: 91 dispatcher = self.__get_dispatcher_for_event(event_name) 92 dispatcher.remove_handlers(event_name, owner) 93 else: 94 for event in self.events: 95 dispatcher = self.__get_dispatcher_for_event(event) 96 dispatcher.remove_handlers(event, owner)97 98 @delegated("public")100 dispatcher = self.__get_dispatcher_for_event(event_name) 101 dispatcher.remove_handler(event_name, handler, owner)102 103 @delegated("public") 108 109 return decorator113 for dispatcher in self.__dispatchers: 114 if dispatcher.has_event(event_name): 115 return True 116 else: 117 return False118 119 @delegated("public") 120 @property 125127 dispatcher = self.__get_dispatcher_for_event(event_name) 128 dispatcher.dispatch(event_name, *args, **keyword_args)129
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0 on Mon Jul 19 11:49:31 2010 | http://epydoc.sourceforge.net |