Python pygame.MOUSEMOTION Examples

The following are 30 code examples of pygame.MOUSEMOTION(). 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: rigeditor.py    From renpy-shader with MIT License 8 votes vote down vote up
def handleEvents(self):
        self.mouse = self.get(MOUSE)

        for event, pos in self.context.events:
            self.mouse = pos

            handled = self.mode.handleEvent((event, pos))
            if not handled:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.handleMouseDown(event, pos)
                elif event.type == pygame.MOUSEMOTION:
                    self.handleMouseMotion(pos)
                elif event.type == pygame.MOUSEBUTTONUP:
                    self.handleMouseUp(pos)

        if self.mouse:
            self.set(MOUSE, self.mouse) 
Example #2
Source File: startinterface.py    From Games with MIT License 7 votes vote down vote up
def startInterface(screen, begin_image_paths):
    begin_images = [pygame.image.load(begin_image_paths[0]), pygame.image.load(begin_image_paths[1])]
    begin_image = begin_images[0]
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEMOTION:
                mouse_pos = pygame.mouse.get_pos()
                if mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)):
                    begin_image = begin_images[1]
                else:
                    begin_image = begin_images[0]
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                if event.button == 1 and mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)):
                    return True
        screen.blit(begin_image, (0, 0))
        pygame.display.update() 
Example #3
Source File: game004.py    From eduActiv8 with GNU General Public License v3.0 7 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            found = False
            for each in self.units:
                if (each.rect.left < pos[0] < each.rect.right and each.rect.top < pos[1] < each.rect.bottom):
                    if each != self.unit_mouse_over:
                        if self.unit_mouse_over is not None:
                            self.unit_mouse_over.mouse_out()
                        self.unit_mouse_over = each
                    found = True
                    each.handle(event)
                    break
            if not found:
                if self.unit_mouse_over is not None:
                    self.unit_mouse_over.mouse_out()
                self.unit_mouse_over = None
        self.board.mainloop.redraw_needed[0] = True 
Example #4
Source File: sprite.py    From pi-tracking-telescope with MIT License 6 votes vote down vote up
def handleEvent(self, event, clock):
        if not self.visible:
            self.focussed = False
            return
        
        if self.groups()[0].UI_PLACEMENT_MODE:
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.pressed_time = pygame.time.get_ticks()
                self.focussed = True
                    
            if event.type == pygame.MOUSEMOTION:
                if (self.focussed and pygame.time.get_ticks() - self.pressed_time > 1000):
                    self.long_pressed = True
                    self.rect.top = event.pos[1]
                    self.rect.left = event.pos[0]
                    self.dirty = 1            
    
            if event.type == pygame.MOUSEBUTTONUP:
                if self.focussed and self.long_pressed:
                    print event.pos[1], event.pos[0]
                    
                self.pressed_time = 0
                self.long_pressed = False
                self.focussed = False 
Example #5
Source File: example-9.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):

        if event.type == pygame.MOUSEMOTION:
            #if self.rect.collidepoint(event.pos)
            #    self.hovered = True
            #else:
            #    self.hovered = False
        
            self.hovered = self.rect.collidepoint(event.pos)

# === FUNCTIONS === (lower_case names)


    # empty

# === MAIN === (lower_case names) 
Example #6
Source File: example-1.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):

        if event.type == pygame.MOUSEMOTION:
            self.hovered = self.rect.collidepoint(event.pos)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if self.hovered:
                print('Clicked:', self.text)
                if self.command:
                    self.command()
                

# === FUNCTIONS === (lower_case names)

    # empty

# === MAIN === (lower_case names) 
Example #7
Source File: game017.py    From eduActiv8 with GNU General Public License v3.0 6 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN:
            self.active_item = self.board.ships[self.board.active_ship]
            if self.active_item.unit_id < self.abc_len:
                self.current_letter_index = self.active_item.unit_id
                self.activate_letter()
            else:
                pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
                if self.lt.rect.topleft[0] < pos[0] < self.lt.rect.topleft[0] + self.lt.rect.width and \
                                        self.lt.rect.topleft[1] < pos[1] < self.lt.rect.topleft[
                            1] + self.lt.rect.height:
                    self.next_slide(-1)
                elif self.rt.rect.topleft[0] < pos[0] < self.rt.rect.topleft[0] + self.rt.rect.width and \
                                        self.rt.rect.topleft[1] < pos[1] < self.rt.rect.topleft[
                            1] + self.rt.rect.height:
                    self.next_slide(1)
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #8
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def handle_event(self, event):
        global redrawing

        if event.type == pygame.MOUSEBUTTONDOWN:
            if self.hover:
                if event.button == 1:
                    if self.movable:
                        self.moving = True
                        redrawing = True
                        return True
                elif event.button == 3:
                    print(self.rect.topleft)
                    return True
                    
        if event.type == pygame.MOUSEBUTTONUP:
            
            if self.hover:
                if self.movable and self.moving:
                    self.moving = False
                    redrawing = True
                    return True

        if event.type == pygame.MOUSEMOTION:
            self.hover = self.rect.collidepoint(event.pos)
            
            if self.movable and self.moving:
                self.rect.move_ip(event.rel)
                self.border_rect.move_ip(event.rel)
                redrawing = True
                return True 
Example #9
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def button_check(info, event):

    text, text_rect, rect, inactive_color, active_color, action, hover = info

    if event.type == pygame.MOUSEMOTION:
        # hover = True/False   
        info[-1] = rect.collidepoint(event.pos)

    elif event.type == pygame.MOUSEBUTTONDOWN:
        if hover and action:      
            action() 
Example #10
Source File: sprite.py    From rpi_lcars with MIT License 5 votes vote down vote up
def handleEvent(self, event, clock):
        handled = False
        if not self.visible:
            self.focussed = False
            return handled
        
        if event.type == pygame.MOUSEBUTTONDOWN:
            self.pressed_time = pygame.time.get_ticks()
            self.focussed = True
                
        if event.type == pygame.MOUSEMOTION:
            if (self.focussed and pygame.time.get_ticks() - self.pressed_time > 1000):
                self.long_pressed = True
                if self.groups()[0].UI_PLACEMENT_MODE:
                    self.rect.top = event.pos[1]
                    self.rect.left = event.pos[0]
                    self.dirty = 1            

        if event.type == pygame.MOUSEBUTTONUP:
            if self.handler:
                self.handler(self, event, clock)
                handled = True
            
            if self.focussed and self.long_pressed and self.groups()[0].UI_PLACEMENT_MODE:
                print(event.pos[1], event.pos[0])
                
            self.pressed_time = 0
            self.long_pressed = False
            self.focussed = False
                
        return handled 
Example #11
Source File: game015.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
            self.auto_check_reset()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #12
Source File: leveleditor.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def postMouseMoved():
        evt = event.Event(MOUSEMOTION, rel=(0, 0), pos=mouse.get_pos(), buttons=mouse.get_pressed())
        event.post(evt) 
Example #13
Source File: event_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_peek(self):
        """Ensure queued events can be peeked at."""
        event_types = [pygame.KEYDOWN, pygame.KEYUP, pygame.MOUSEMOTION]

        for event_type in event_types:
            pygame.event.post(pygame.event.Event(event_type))

        for event_type in event_types:
            self.assertTrue(pygame.event.peek(event_type))

        self.assertTrue(pygame.event.peek(event_types)) 
Example #14
Source File: event_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_peek(self):
        """Ensure queued events can be peeked at."""
        event_types = [pygame.KEYDOWN, pygame.KEYUP, pygame.MOUSEMOTION]

        for event_type in event_types:
            pygame.event.post(pygame.event.Event(event_type))

        for event_type in event_types:
            self.assertTrue(pygame.event.peek(event_type))

        self.assertTrue(pygame.event.peek(event_types)) 
Example #15
Source File: event_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_peek(self):
        """Ensure queued events can be peeked at."""
        event_types = [pygame.KEYDOWN, pygame.KEYUP, pygame.MOUSEMOTION]

        for event_type in event_types:
            pygame.event.post(pygame.event.Event(event_type))

        for event_type in event_types:
            self.assertTrue(pygame.event.peek(event_type))

        self.assertTrue(pygame.event.peek(event_types)) 
Example #16
Source File: endinterface.py    From Games with MIT License 5 votes vote down vote up
def endInterface(screen, end_image_path, again_image_paths, score_info, font_path, font_colors, screensize):
    end_image = pygame.image.load(end_image_path)
    again_images = [pygame.image.load(again_image_paths[0]), pygame.image.load(again_image_paths[1])]
    again_image = again_images[0]
    font = pygame.font.Font(font_path, 50)
    your_score_text = font.render('Your Score: %s' % score_info['your_score'], True, font_colors[0])
    your_score_rect = your_score_text.get_rect()
    your_score_rect.left, your_score_rect.top = (screensize[0] - your_score_rect.width) / 2, 215
    best_score_text = font.render('Best Score: %s' % score_info['best_score'], True, font_colors[1])
    best_score_rect = best_score_text.get_rect()
    best_score_rect.left, best_score_rect.top = (screensize[0] - best_score_rect.width) / 2, 275
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEMOTION:
                mouse_pos = pygame.mouse.get_pos()
                if mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)):
                    again_image = again_images[1]
                else:
                    again_image = again_images[0]
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                if event.button == 1 and mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)):
                    return True
        screen.blit(end_image, (0, 0))
        screen.blit(again_image, (416, 370))
        screen.blit(your_score_text, your_score_rect)
        screen.blit(best_score_text, best_score_rect)
        pygame.display.update() 
Example #17
Source File: main-button-functions.py    From python-examples with MIT License 5 votes vote down vote up
def button_check(info, event):

    text, text_rect, rect, inactive_color, active_color, action, hover = info

    if event.type == pygame.MOUSEMOTION:
        # hover = True/False
        info[-1] = rect.collidepoint(event.pos)

    elif event.type == pygame.MOUSEBUTTONDOWN:
        if hover and action:
            action() 
Example #18
Source File: dialogwnd.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if event.type == pygame.MOUSEBUTTONUP:
            self.fsubmit(self.fargs)
            self.wnd.hide_dialog()
            self.mouse_out()
        elif event.type == pygame.MOUSEMOTION:
            self.mouse_over() 
Example #19
Source File: RUN_ME.py    From SciSlice with MIT License 5 votes vote down vote up
def run(self):
        ''' Create a pygame screen until it is closed. '''
        pygame.init()
        self.myfont = pygame.font.SysFont('monospace', 15)
        
        #automatically translates image to center of window
        x, y = self.screen.get_size()
        self.translateAll('x', (x/2-self.wireframes[c.MODEL].findcenter()[0]))
        self.translateAll('y', (y/2-self.wireframes[c.MODEL].findcenter()[1]))
        self.scaleAll(4)
        
        while True:
            self.r = 0
            self.b = 0
            self.g = 0
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    
                elif event.type == pygame.KEYDOWN:
                    if event.key in key_to_function:
                        key_to_function[event.key](self)
                        
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 4:
                        self.scaleAll(1.25)
                    elif event.button == 5:
                        self.scaleAll(0.8)
                elif event.type == pygame.MOUSEMOTION:
                    if event.buttons[0]:
                        shiftX, shiftY = event.rel
                        self.translateAll('x', shiftX)
                        self.translateAll('y', -shiftY)
                    elif event.buttons[2]:
                        rotY, rotX = event.rel
                        self.rotateAll('X', rotX/270)
                        self.rotateAll('Y', rotY/270)
                        
                elif event.type == pygame.VIDEORESIZE:
                    os.environ['SDL_VIDEO_WINDOW_POS'] = '' # Clears the default window location
                    self.width, self.height = event.dict['size']
                    self.screen = pygame.display.set_mode(event.dict['size'], pygame.RESIZABLE)
                    
            self.display()  
            pygame.display.flip() 
Example #20
Source File: menu_items.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            if not self.hover:
                self.hover = True
                if self.show_titles_on_hover:
                    self.board.mainloop.redraw_needed[1] = True
                    self.board.mainloop.info.title = self.game_obj.title
                    self.board.mainloop.info.subtitle = self.game_obj.subtitle
                    self.board.mainloop.info.game_id = "#%s/%03i" % (self.game_obj.game_constructor[4:7], self.game_obj.dbgameid)
                self.update_me = True
                self.update()
        elif event.type == pygame.MOUSEBUTTONUP:
            self.mouse_click() 
Example #21
Source File: menu_items.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            if not self.hover:
                if self.show_titles_on_hover:
                    self.board.mainloop.redraw_needed[1] = True
                    self.board.mainloop.info.title = self.cat_obj.title
                    self.board.mainloop.info.subtitle = self.cat_obj.subtitle
                    self.board.mainloop.info.game_id = "#%03i" % self.cat_obj.cat_id
                self.hover = True
                self.update_me = True
                self.update()
        elif event.type == pygame.MOUSEBUTTONUP:
            self.mouse_click() 
Example #22
Source File: menu_items.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            if not self.hover:
                self.board.mainloop.redraw_needed[1] = True
                self.hover = True
                self.update_me = True
                self.update()
        elif event.type == pygame.MOUSEBUTTONUP:
            self.mouse_click() 
Example #23
Source File: loginscreen.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if self.visible:
            if event.type == pygame.MOUSEMOTION:
                self.onMouseMotion(event)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.onMouseButtonDown()
            elif event.type == pygame.MOUSEBUTTONUP:
                self.onMouseButtonUp()
            elif event.type == pygame.KEYDOWN:
                self.onKeyDown(event) 
Example #24
Source File: loginscreen.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if event.type == pygame.MOUSEMOTION:
            self.onMouseEnter()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            self.onMouseButtonDown(event)
        elif event.type == pygame.MOUSEBUTTONUP:
            self.onMouseButtonUp()
        elif event.type == pygame.KEYDOWN:
            self.onKeyDown(event) 
Example #25
Source File: loginscreen.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if self.visible:
            if event.type == pygame.MOUSEMOTION:
                self.onMouseEnter()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.onMouseButtonDown()
            elif event.type == pygame.MOUSEBUTTONUP:
                self.onMouseButtonUp()
            elif event.type == pygame.KEYDOWN:
                self.onKeyDown(event) 
Example #26
Source File: loginscreen.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        if self.visible:
            if event.type == pygame.MOUSEMOTION:
                self.onMouseEnter()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.onMouseButtonDown()
            if event.type == pygame.MOUSEBUTTONUP:
                self.onMouseButtonUp()
            if event.type == pygame.KEYDOWN:
                self.onKeyDown(event) 
Example #27
Source File: game025.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)
            self.check_result()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #28
Source File: game034.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][16]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
                    self.check_result()
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #29
Source File: game027.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)

        elif event.type == pygame.MOUSEBUTTONDOWN:
            self.auto_check_reset()

        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #30
Source File: event_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
def test_peek(self):
        """Ensure queued events can be peeked at."""
        event_types = [pygame.KEYDOWN, pygame.KEYUP, pygame.MOUSEMOTION]

        for event_type in event_types:
            pygame.event.post(pygame.event.Event(event_type))

        for event_type in event_types:
            self.assertTrue(pygame.event.peek(event_type))

        self.assertTrue(pygame.event.peek(event_types))