示例#1
0
 def userProcess(self):
     """
     Extract which body is which, send off 
     """
     # Determin which body is the trigger, and which is the contacting object
     me = self.m_body0.getUserData();
     contactor = self.m_body1.getUserData();
     
     # Our guess was wrong
     if ITrigger.providedBy(contactor):
         me, contactor = contactor, me # swap values
     
     # Store the contact information for latter event firing
     contact_material = contactor.material
     contact_info = (contactor, contact_material)
     
     # If this is the first time we are contacting post the event
     if not self._contactors.has_key(contact_info):
         enter_event = self._contact_events[contact_material][0]
         if enter_event is not None:
             event.post(enter_event, contactor) 
     self._contactors[contact_info] = True
          
     # Ignore all contacts
     return 0
示例#2
0
 def post_update(self):
     new_contactors = {}
     for contact_info, contacting in self._contactors.iteritems():
         if contacting:
             new_contactors[contact_info] = False
         else:
             contactor, material = contact_info
             leave_event = self._contact_events[material][1]
             if leave_event is not None:
                 event.post(leave_event, contactor)
           
     self._contactors.clear()
     self._contactors.update(new_contactors)
示例#3
0
    def post_key_event(self, key, down, ctrl_down, alt_down, shift_down, 
                        meta_down):
        mod_keys = pack_mod_keys(ctrl_down, alt_down, shift_down, meta_down)

        # Find all events that are mapped to this key combination
        key_event = (key, mod_keys)
        event_types = self._action_map.get(key_event, set())
        # Does yet work ...
#        print 'EVENT:',key_event, down, event_types
#        
#        # If we have a key combination mapped to CTRL+A, when it is pressed all
#        # the events will got out for that combination being pressed down. This
#        # code resolves the issue of what happens when releases just one of the
#        # keys at a time instead of both.
#        
#        # Someone has released a key
#        if not down:
#            print "UP",key_event
#            # Two possibilities, normal key up, mod_key up
#            # Retrieve all down combination which contain this key and release them
#            if self._down_keys.has_key(key):
#                key_events = self._down_keys.pop(key)             
#                for key_evt in key_events:
#                    event_types.update(self._action_map.get(key_evt, set()))
#                    
#        elif len(event_types) != 0:
#            print "DOWN",key_event
#            
#            # Add it to the set of pressed keys
#            key_events = self._down_keys.get(key, set())
#            key_events.add(key_event)
#            self._down_keys[key] = key_events
#            
#            if mod_keys != 0:
#                # Add all releated mod key maps
#                mods = unpack_mod_keys(mod_keys)
#                for mod_key in mods:
#                    key_events = self._down_keys.get(mod_key, set())
#                    key_events.add(key_event)
#                    self._down_keys[mod_key] = key_events
#        print 'STATE',self._down_keys,'\n'

        # Post all the events we need to post
        for event_type in event_types:
            event.post(event_type, key, down, mod_keys)                         
示例#4
0
    def post_key_event(self, key, down, ctrl_down, alt_down, shift_down,
                       meta_down):
        mod_keys = pack_mod_keys(ctrl_down, alt_down, shift_down, meta_down)

        # Find all events that are mapped to this key combination
        key_event = (key, mod_keys)
        event_types = self._action_map.get(key_event, set())
        # Does yet work ...
        #        print 'EVENT:',key_event, down, event_types
        #
        #        # If we have a key combination mapped to CTRL+A, when it is pressed all
        #        # the events will got out for that combination being pressed down. This
        #        # code resolves the issue of what happens when releases just one of the
        #        # keys at a time instead of both.
        #
        #        # Someone has released a key
        #        if not down:
        #            print "UP",key_event
        #            # Two possibilities, normal key up, mod_key up
        #            # Retrieve all down combination which contain this key and release them
        #            if self._down_keys.has_key(key):
        #                key_events = self._down_keys.pop(key)
        #                for key_evt in key_events:
        #                    event_types.update(self._action_map.get(key_evt, set()))
        #
        #        elif len(event_types) != 0:
        #            print "DOWN",key_event
        #
        #            # Add it to the set of pressed keys
        #            key_events = self._down_keys.get(key, set())
        #            key_events.add(key_event)
        #            self._down_keys[key] = key_events
        #
        #            if mod_keys != 0:
        #                # Add all releated mod key maps
        #                mods = unpack_mod_keys(mod_keys)
        #                for mod_key in mods:
        #                    key_events = self._down_keys.get(mod_key, set())
        #                    key_events.add(key_event)
        #                    self._down_keys[mod_key] = key_events
        #        print 'STATE',self._down_keys,'\n'

        # Post all the events we need to post
        for event_type in event_types:
            event.post(event_type, key, down, mod_keys)