def handleEvent(self, eventObj):
        """This method should be called every time through the main loop.

        It handles showing the up, over, and down states of the button.

        Parameters:
            | eventObj - the event object obtained by calling pygame.event.get()

        Returns:
            | False most of the time
            | True when the user clicks down and later up on the button.

        """

        if self.enterToActivate:
            if eventObj.type == pygame.KEYDOWN:

                # Return or Enter key
                if eventObj.key == pygame.K_RETURN:
                    return True

        if (eventObj.type not in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN)) or (not self.visible):
            # The button only cares bout mouse-related events (or no events, if it is invisible)
            return False

        if not self.isEnabled:
            return False

        clicked = False

        eventPointInButtonRect = self.rect.collidepoint(eventObj.pos)
        if (not self.mouseOverButton) and eventPointInButtonRect:
            # if mouse has entered the button:
            self.mouseOverButton = True

        elif self.mouseOverButton and (not eventPointInButtonRect):
            # if mouse has exited the button:
            self.mouseOverButton = False

        if eventPointInButtonRect:

            if eventObj.type == MOUSEBUTTONDOWN:
                self.buttonDown = True
                self.lastMouseDownOverButton = True

        else:
            if eventObj.type in (MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                # if an up/down happens off the button, then the next up won't cause mouseClick()
                self.lastMouseDownOverButton = False

        if eventObj.type == MOUSEBUTTONDOWN:
            self.mouseIsDown = True
            
        # mouse up is handled whether or not it was over the button
        doMouseClick = False
        if eventObj.type == MOUSEBUTTONUP:
            self.mouseIsDown = False
            if self.lastMouseDownOverButton:
                doMouseClick = True
            self.lastMouseDownOverButton = False

            if self.buttonDown:
                self.buttonDown = False

            if doMouseClick:
                self.buttonDown = False
                clicked = True
                self.mouseOverButton = False  # forces redraw of up state after click
                
                if self.playSoundOnClick:
                    self.soundOnClick.play()

        if clicked:
            if self.callBack is not None:
                self.callBack(self.nickname)

        return clicked
def handleEvent ( self , eventObj ) : if self . enterToActivate : if eventObj . type == pygame . KEYDOWN : if eventObj . key == pygame . K_RETURN : return True if ( eventObj . type not in ( MOUSEMOTION , MOUSEBUTTONUP , MOUSEBUTTONDOWN ) ) or ( not self . visible ) : return False if not self . isEnabled : return False clicked = False eventPointInButtonRect = self . rect . collidepoint ( eventObj . pos ) if ( not self . mouseOverButton ) and eventPointInButtonRect : self . mouseOverButton = True elif self . mouseOverButton and ( not eventPointInButtonRect ) : self . mouseOverButton = False if eventPointInButtonRect : if eventObj . type == MOUSEBUTTONDOWN : self . buttonDown = True self . lastMouseDownOverButton = True else : if eventObj . type in ( MOUSEBUTTONUP , MOUSEBUTTONDOWN ) : self . lastMouseDownOverButton = False if eventObj . type == MOUSEBUTTONDOWN : self . mouseIsDown = True doMouseClick = False if eventObj . type == MOUSEBUTTONUP : self . mouseIsDown = False if self . lastMouseDownOverButton : doMouseClick = True self . lastMouseDownOverButton = False if self . buttonDown : self . buttonDown = False if doMouseClick : self . buttonDown = False clicked = True self . mouseOverButton = False if self . playSoundOnClick : self . soundOnClick . play ( ) if clicked : if self . callBack is not None : self . callBack ( self . nickname ) return clicked
This method should be called every time through the main loop.

        It handles showing the up, over, and down states of the button.

        Parameters:
            | eventObj - the event object obtained by calling pygame.event.get()

        Returns:
            | False most of the time
            | True when the user clicks down and later up on the button.