def handle_input(self):
        """Get and handle events from event queue."""
        ### iterate over the events from the event queue,
        ### processing the relevant ones accoding to their
        ### settings

        for event in SERVICES_NS.get_events():

            ### quit the application
            if event.type == QUIT:
                self.quit()

            ### perform the corresponding action if the user
            ### presses the left mouse button, passing the
            ### event object as an argument of the operation

            elif event.type == KEYUP:

                if event.key == K_ESCAPE:

                    self.cancel()
                    break

                elif event.key in (K_RETURN, K_KP_ENTER):
                    self.exit_loop()

            elif event.type == MOUSEBUTTONDOWN:

                if event.button == 1:
                    self.on_mouse_click(event)

            ### act according to the release of the
            ### mouse left and right buttons

            elif event.type == MOUSEBUTTONUP:

                ## if button isn't the left or right mouse
                ## button, skip this event by using the
                ## 'continue' statement, since we are
                ## not interested in the other buttons
                ## here
                if event.button not in (1, 3):
                    continue

                ## if the left or right mouse buttons are
                ## released outside the colors editor
                ## boundaries, trigger the cancellation
                ## of the editing session and exit this
                ## method earlier by breaking out of the
                ## "for loop"

                if not self.rect.collidepoint(event.pos):

                    self.cancel()
                    break

                ## if we are inside boundaries, though
                ## (the "if block" above fails), and the
                ## mouse button is the left one,
                ## perform the corresponding mouse action
                ## using the event as an argument
                elif event.button == 1:
                    self.on_mouse_release(event)

            ### perform actions when specific keys were
            ### pressed

            elif event.type == KEYDOWN:

                if event.key in (K_LEFT, K_a):
                    self.colors_panel.go_left()

                elif event.key in (K_RIGHT, K_d):
                    self.colors_panel.go_right()

                elif event.key == K_HOME:
                    self.colors_panel.go_to_start()

                elif event.key == K_END:
                    self.colors_panel.go_to_end()

                elif event.key == K_DELETE:
                    self.colors_panel.remove_color_widgets()
Get and handle events from event queue.
nodezator/colorsman/editor/loopop.py