def test_post__clear(self): """Ensure posted events can be cleared.""" for _ in range(10): fastevent.post(event.Event(pygame.USEREVENT)) event.clear() self.assertListEqual(fastevent.get(), []) self.assertListEqual(event.get(), [])
def gpiobut(channel): if channel == 17: # check for button 1 fastevent.post(pygame.event.Event(pygame.USEREVENT + 3, button=1)) elif channel == 22: # check for button 2 fastevent.post(pygame.event.Event(pygame.USEREVENT + 3, button=2)) elif channel == 23: # check for button 3 fastevent.post(pygame.event.Event(pygame.USEREVENT + 3, button=3)) elif channel == 27: # check for button 4 fastevent.post(pygame.event.Event(pygame.USEREVENT + 3, button=4))
def get_default_midi_val(prompt, decks): print prompt key_entered, midi_entered = False, False while not key_entered or not midi_entered: events = pyfastevent.get() for e in events: if e.type == pygame.KEYDOWN: if (e.key == pygame.K_RETURN) and (midi_entered == True): key_entered = True if e.type == pymidi.MIDIIN: val = e.data2 midi_entered = True if decks.poll(): midi_events = decks.read(1) events = pymidi.midis2events(midi_events, decks.device_id) for e in events: pyfastevent.post(e) return val
def run(self): self.done = [] self.stop = [] for x in range(NUM_EVENTS_TO_POST): ee = event.Event(USEREVENT) try_post = 1 # the pygame.event.post raises an exception if the event # queue is full. so wait a little bit, and try again. while try_post: try: eventmodule.post(ee) try_post = 0 except: pytime.sleep(0.001) try_post = 1 if self.stop: return self.done.append(1)
def test_post(self): # __doc__ (as of 2008-08-02) for pygame.fastevent.post: # pygame.fastevent.post(Event) -> None # place an event on the queue # # This will post your own event objects onto the event queue. # You can past any event type you want, but some care must be # taken. For example, if you post a MOUSEBUTTONDOWN event to the # queue, it is likely any code receiving the event will expect # the standard MOUSEBUTTONDOWN attributes to be available, like # 'pos' and 'button'. # # Because pygame.fastevent.post() may have to wait for the queue # to empty, you can get into a dead lock if you try to append an # event on to a full queue from the thread that processes events. # For that reason I do not recommend using this function in the # main thread of an SDL program. for _ in range(1, 11): fastevent.post(event.Event(pygame.USEREVENT)) self.assertListEqual( [e.type for e in event.get()], [pygame.USEREVENT] * 10, race_condition_notification, ) try: # Special case for post: METH_O. fastevent.post(1) except TypeError: e = geterror() msg = "argument 1 must be %s, not %s" % ( fastevent.Event.__name__, type(1).__name__, ) self.assertEqual(str(e), msg) else: self.fail()
def test_post(self): # __doc__ (as of 2008-08-02) for pygame.fastevent.post: # pygame.fastevent.post(Event) -> None # place an event on the queue # # This will post your own event objects onto the event queue. # You can past any event type you want, but some care must be # taken. For example, if you post a MOUSEBUTTONDOWN event to the # queue, it is likely any code receiving the event will expect # the standard MOUSEBUTTONDOWN attributes to be available, like # 'pos' and 'button'. # # Because pygame.fastevent.post() may have to wait for the queue # to empty, you can get into a dead lock if you try to append an # event on to a full queue from the thread that processes events. # For that reason I do not recommend using this function in the # main thread of an SDL program. for _ in range(1, 11): fastevent.post(event.Event(pygame.USEREVENT)) self.assertEquals ( [e.type for e in event.get()], [pygame.USEREVENT] * 10, race_condition_notification ) try: # Special case for post: METH_O. fastevent.post(1) except TypeError: e = geterror() msg = ("argument 1 must be %s, not %s" % (fastevent.Event.__name__, type(1).__name__)) self.failUnlessEqual(str(e), msg) else: self.fail()
def trigger_event(self, event_channel): EventModule.post(EventModule.Event(pygame.USEREVENT, channel=event_channel))
def postTwistedEvent(func): # if not using pygame.fastevent, this can explode if the queue # fills up.. so that's bad. Use pygame.fastevent, in pygame CVS # as of 2005-04-18. eventmodule.post(eventmodule.Event(TWISTEDEVENT, iterateTwisted=func))
def __pygame_thread(self): from pygame import fastevent while self.__run: while self.__events: fastevent.post(self.__events.pop())