Commits

Ginés Martínez Sánchez  committed e03e0f3

let change the original output event name in broadcast_event

  • Participants
  • Parent commits f539bd9

Comments (0)

Files changed (1)

File ginsfsm/gobj.py

             raise EventError('_event_factory() BAD TYPE event %s in (%s:%s)' %
                 (repr(event), self.__class__.__name__, self.name))
 
-        if destination is not None:
-            if not (isinstance(destination, string_types) or
-                    isinstance(destination, GObj)):
-                raise DestinationError(
-                    '_event_factory() BAD TYPE destination %s in (%s:%s)' %
-                    (repr(destination), self.__class__.__name__, self.name))
+        # if destination is not None:
+        if not (isinstance(destination, string_types) or
+                isinstance(destination, GObj)):
+            raise DestinationError(
+                '_event_factory() BAD TYPE destination %s in (%s:%s)' %
+                (repr(destination), self.__class__.__name__, self.name))
 
         if isinstance(event, Event):
             # duplicate the event
               'enqueue_event() no support in (%s:%s)' % (
               self.__class__.__name__, self.name))
 
-    def broadcast_event(self, event, **kw):
+    def broadcast_event(self, oevent, **kw):
         """ Broadcast the ``event`` to all subscribers.
 
         :param event: :term:`event` to send.
            the :term:`event-filter` cannot be applied.
         """
         if self._some_subscriptions:
-            event = self._event_factory(None, event, **kw)
             subscriptions = self._dl_subscriptions.copy()
             sended_gobj = set()  # don't repeat events
             for sub in subscriptions:
                 if sub.subscriber_gobj in sended_gobj:
                     continue
-                if None in sub.event_name or event.event_name in sub.event_name:
+
+                event = self._event_factory(sub.subscriber_gobj, oevent, **kw)
+                if None in sub.event_name or \
+                        event.event_name in sub.event_name:
+
+                    if hasattr(sub, 'change_original_event_name'):
+                        event.name = sub.change_original_event_name
+
                     if hasattr(sub, 'use_post_event'):
                         ret = self.post_event(sub.subscriber_gobj, event)
                     else:
               You must set it to `True` in order to broadcast the events
               using `post-event` instead of `send-event`.
 
+            * `change_original_event_name`:
+              You can change the output original event name..
+
         """
         if subscriber_gobj is None:
             subscriber_gobj = self.parent