Python pygame.USEREVENT Examples
The following are 30
code examples of pygame.USEREVENT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: manual-control-pygame.py From DJITelloPy with MIT License | 6 votes |
def __init__(self): # Init pygame pygame.init() # Creat pygame window pygame.display.set_caption("Tello video stream") self.screen = pygame.display.set_mode([960, 720]) # Init Tello object that interacts with the Tello drone self.tello = Tello() # Drone velocities between -100~100 self.for_back_velocity = 0 self.left_right_velocity = 0 self.up_down_velocity = 0 self.yaw_velocity = 0 self.speed = 10 self.send_rc_control = False # create update timer pygame.time.set_timer(pygame.USEREVENT + 1, 1000 // FPS)
Example #2
Source File: time_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_timer(self): # __doc__ (as of 2008-08-02) for pygame.time.set_timer: # pygame.time.set_timer(eventid, milliseconds): return None # repeatedly create an event on the event queue # # Set an event type to appear on the event queue every given number of # milliseconds. The first event will not appear until the amount of # time has passed. # # Every event type can have a separate timer attached to it. It is # best to use the value between pygame.USEREVENT and pygame.NUMEVENTS. # # To disable the timer for an event, set the milliseconds argument to 0. self.fail()
Example #3
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_Event(self): """Ensure an Event object can be created.""" e = pygame.event.Event(pygame.USEREVENT, some_attr=1, other_attr='1') self.assertEqual(e.some_attr, 1) self.assertEqual(e.other_attr, "1") # Event now uses tp_dictoffset and tp_members: request 62 # on Motherhamster Bugzilla. self.assertEqual(e.type, pygame.USEREVENT) self.assertIs(e.dict, e.__dict__) e.some_attr = 12 self.assertEqual(e.some_attr, 12) e.new_attr = 15 self.assertEqual(e.new_attr, 15) # For Python 2.x a TypeError is raised for a readonly member; # for Python 3.x it is an AttributeError. self.assertRaises((TypeError, AttributeError), setattr, e, 'type', 0) self.assertRaises((TypeError, AttributeError), setattr, e, 'dict', None) # Ensure attributes are visible to dir(), part of the original # posted request. d = dir(e) attrs = ('type', 'dict', '__dict__', 'some_attr', 'other_attr', 'new_attr') for attr in attrs: self.assertIn(attr, d)
Example #4
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_Event(self): """Ensure an Event object can be created.""" e = pygame.event.Event(pygame.USEREVENT, some_attr=1, other_attr='1') self.assertEqual(e.some_attr, 1) self.assertEqual(e.other_attr, "1") # Event now uses tp_dictoffset and tp_members: request 62 # on Motherhamster Bugzilla. self.assertEqual(e.type, pygame.USEREVENT) self.assertIs(e.dict, e.__dict__) e.some_attr = 12 self.assertEqual(e.some_attr, 12) e.new_attr = 15 self.assertEqual(e.new_attr, 15) # For Python 2.x a TypeError is raised for a readonly member; # for Python 3.x it is an AttributeError. self.assertRaises((TypeError, AttributeError), setattr, e, 'type', 0) self.assertRaises((TypeError, AttributeError), setattr, e, 'dict', None) # Ensure attributes are visible to dir(), part of the original # posted request. d = dir(e) attrs = ('type', 'dict', '__dict__', 'some_attr', 'other_attr', 'new_attr') for attr in attrs: self.assertIn(attr, d)
Example #5
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_clear(self): pygame.event.clear() pygame.event.clear(None) pygame.event.clear(None, True) pygame.event.clear(pump=False) pygame.event.clear(pump=True) pygame.event.clear(eventtype=None) pygame.event.clear(eventtype=pygame.USEREVENT, pump=False)
Example #6
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_peek(self): pygame.event.peek() pygame.event.peek(None) pygame.event.peek(None, True) pygame.event.peek(pump=False) pygame.event.peek(pump=True) pygame.event.peek(eventtype=None) pygame.event.peek(eventtype=pygame.USEREVENT, pump=False)
Example #7
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_event_attribute(self): e1 = pygame.event.Event(pygame.USEREVENT, attr1='attr1') self.assertEqual(e1.attr1, 'attr1')
Example #8
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_post__and_poll(self): """Ensure events can be posted to the queue.""" e1 = pygame.event.Event(pygame.USEREVENT, attr1='attr1') pygame.event.post(e1) posted_event = pygame.event.poll() self.assertEqual(e1.attr1, posted_event.attr1, race_condition_notification) # fuzzing event types for i in range(1, 11): pygame.event.post(pygame.event.Event(events[i])) self.assertEqual(pygame.event.poll().type, events[i], race_condition_notification)
Example #9
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_post_large_user_event(self): pygame.event.post(pygame.event.Event(pygame.USEREVENT, {'a': "a" * 1024})) e = pygame.event.poll() self.assertEqual(e.type, pygame.USEREVENT) self.assertEqual(e.a, "a" * 1024)
Example #10
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get_type(self): ev = pygame.event.Event(pygame.USEREVENT) pygame.event.post(ev) queue = pygame.event.get(pygame.USEREVENT) self.assertEqual(len(queue), 1) self.assertEqual(queue[0].type, pygame.USEREVENT)
Example #11
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_event_name(self): """Ensure event_name() returns the correct event name.""" self.assertEqual(pygame.event.event_name(pygame.KEYDOWN), "KeyDown") self.assertEqual(pygame.event.event_name(pygame.USEREVENT), "UserEvent")
Example #12
Source File: time_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def todo_test_set_timer(self): # __doc__ (as of 2008-08-02) for pygame.time.set_timer: # pygame.time.set_timer(eventid, milliseconds): return None # repeatedly create an event on the event queue # # Set an event type to appear on the event queue every given number of # milliseconds. The first event will not appear until the amount of # time has passed. # # Every event type can have a separate timer attached to it. It is # best to use the value between pygame.USEREVENT and pygame.NUMEVENTS. # # To disable the timer for an event, set the milliseconds argument to 0. self.fail()
Example #13
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get(self): # __doc__ (as of 2008-08-02) for pygame.fastevent.get: # pygame.fastevent.get() -> list of Events # get all events from the queue for _ in range(1, 11): event.post(event.Event(pygame.USEREVENT)) self.assertListEqual([e.type for e in fastevent.get()], [pygame.USEREVENT] * 10, race_condition_notification)
Example #14
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #15
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #16
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get(self): pygame.event.get() pygame.event.get(None) pygame.event.get(None, True) pygame.event.get(pump=False) pygame.event.get(pump=True) pygame.event.get(eventtype=None) pygame.event.get(eventtype=pygame.USEREVENT, pump=False)
Example #17
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_clear(self): pygame.event.clear() pygame.event.clear(None) pygame.event.clear(None, True) pygame.event.clear(pump=False) pygame.event.clear(pump=True) pygame.event.clear(eventtype=None) pygame.event.clear(eventtype=pygame.USEREVENT, pump=False)
Example #18
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_peek(self): pygame.event.peek() pygame.event.peek(None) pygame.event.peek(None, True) pygame.event.peek(pump=False) pygame.event.peek(pump=True) pygame.event.peek(eventtype=None) pygame.event.peek(eventtype=pygame.USEREVENT, pump=False)
Example #19
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_event_attribute(self): e1 = pygame.event.Event(pygame.USEREVENT, attr1='attr1') self.assertEqual(e1.attr1, 'attr1')
Example #20
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_post_large_user_event(self): pygame.event.post(pygame.event.Event(pygame.USEREVENT, {'a': "a" * 1024})) e = pygame.event.poll() self.assertEqual(e.type, pygame.USEREVENT) self.assertEqual(e.a, "a" * 1024)
Example #21
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get(self): """Ensure get() retrieves all the events on the queue.""" event_cnt = 10 for _ in range(event_cnt): pygame.event.post(pygame.event.Event(pygame.USEREVENT)) queue = pygame.event.get() self.assertEqual(len(queue), event_cnt) self.assertTrue(all(e.type == pygame.USEREVENT for e in queue))
Example #22
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get_type(self): ev = pygame.event.Event(pygame.USEREVENT) pygame.event.post(ev) queue = pygame.event.get(pygame.USEREVENT) self.assertEqual(len(queue), 1) self.assertEqual(queue[0].type, pygame.USEREVENT)
Example #23
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_event_name(self): """Ensure event_name() returns the correct event name.""" self.assertEqual(pygame.event.event_name(pygame.KEYDOWN), "KeyDown") self.assertEqual(pygame.event.event_name(pygame.USEREVENT), "UserEvent")
Example #24
Source File: time_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def todo_test_set_timer(self): # __doc__ (as of 2008-08-02) for pygame.time.set_timer: # pygame.time.set_timer(eventid, milliseconds): return None # repeatedly create an event on the event queue # # Set an event type to appear on the event queue every given number of # milliseconds. The first event will not appear until the amount of # time has passed. # # Every event type can have a separate timer attached to it. It is # best to use the value between pygame.USEREVENT and pygame.NUMEVENTS. # # To disable the timer for an event, set the milliseconds argument to 0. self.fail()
Example #25
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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()
Example #26
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
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(), [])
Example #27
Source File: fastevent_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get(self): # __doc__ (as of 2008-08-02) for pygame.fastevent.get: # pygame.fastevent.get() -> list of Events # get all events from the queue for _ in range(1, 11): event.post(event.Event(pygame.USEREVENT)) self.assertListEqual([e.type for e in fastevent.get()], [pygame.USEREVENT] * 10, race_condition_notification)
Example #28
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_Event(self): """Ensure an Event object can be created.""" e = pygame.event.Event(pygame.USEREVENT, some_attr=1, other_attr='1') self.assertEqual(e.some_attr, 1) self.assertEqual(e.other_attr, "1") # Event now uses tp_dictoffset and tp_members: request 62 # on Motherhamster Bugzilla. self.assertEqual(e.type, pygame.USEREVENT) self.assertIs(e.dict, e.__dict__) e.some_attr = 12 self.assertEqual(e.some_attr, 12) e.new_attr = 15 self.assertEqual(e.new_attr, 15) # For Python 2.x a TypeError is raised for a readonly member; # for Python 3.x it is an AttributeError. self.assertRaises((TypeError, AttributeError), setattr, e, 'type', 0) self.assertRaises((TypeError, AttributeError), setattr, e, 'dict', None) # Ensure attributes are visible to dir(), part of the original # posted request. d = dir(e) attrs = ('type', 'dict', '__dict__', 'some_attr', 'other_attr', 'new_attr') for attr in attrs: self.assertIn(attr, d)
Example #29
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_get(self): pygame.event.get() pygame.event.get(None) pygame.event.get(None, True) pygame.event.get(pump=False) pygame.event.get(pump=True) pygame.event.get(eventtype=None) pygame.event.get(eventtype=pygame.USEREVENT, pump=False)
Example #30
Source File: event_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def test_event_attribute(self): e1 = pygame.event.Event(pygame.USEREVENT, attr1='attr1') self.assertEqual(e1.attr1, 'attr1')