Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Quinteti.activity/gui/button.py
blob: d2efbc24a4d076503db625a710a409b05117afce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
#
# Copyright 2008, 2009 Pablo Moleri, ceibalJAM
# This file is part of Quinteti.
#
# Quinteti is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Quinteti is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Quinteti.  If not, see <http://www.gnu.org/licenses/>.

import pygame

"""Button is a PyGame Sprite with a callback function."""

class Button(pygame.sprite.Sprite):
    def __init__(self, initial_position, nomImage, callback):

        pygame.sprite.Sprite.__init__(self)
        
        self.setImage(nomImage)
        self.rect = self.image.get_rect()
        self.rect.topleft = initial_position     # Moves the recteangle to its predetermined center
        
        self.callback = callback
    
    def coordsIn(self, x, y):
        if self.rect.collidepoint(x, y):
            return True
        return False
    
    def setImage(self, nomImage):
        if nomImage:
            self.image = pygame.image.load(nomImage)
        else:
            self.image = None