Source

Fat x Fast / FatxFast / scenes / basescene.py

Full commit

# This file is part of FatxFast.
#
#    FatxFast 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.
#
#    FatxFast 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 FatxFast.  If not, see <http://www.gnu.org/licenses/>.

# Versioning based on: 
# http://en.wikipedia.org/wiki/Versioning#Designating_development_stage
__author__ = "dryatu (c) 2013"
__version__ = "1.2.5"

import pygame
import FatxFast.events as events
from FatxFast.objects.entity import Observable
from FatxFast.gui.container import Container
from FatxFast.input import KeyListener, MouseListener

class Scene(Container, KeyListener, MouseListener):
    '''Base class for gui's scenes'''
    def __init__(self, manager, **kwargs):
        super(Scene, self).__init__()
        self.manager = manager
        self.name = kwargs.get("name", self.__class__.__name__.lower())
        manager.sceneparser.get_widgets(self, self.name, self.manager)

    def end(self):
        pass
    
    def _make_a_listener(self):
        self.manager.game.input.add_key_listener(self)
        self.manager.game.input.add_mouse_listener(self)
    
    def _make_not_listen(self): 
        self.manager.game.input.remove_key_listener(self)
        self.manager.game.input.remove_mouse_listener(self)

    def pause(self):
        self._make_not_listen()
    
    def resume(self):
        self._make_a_listener()
    
    def start(self):
        self._make_a_listener()