class Pause(ControlState):
    def __init__(self):
        ControlState.__init__(self)
        self.keymap = {"toggle": "p"}
        self.functionmap = {"toggle": self.togglePause}
        self.paused_states = []
        self.paused = False

    def pauseOn(self):
        for state in list(ControlState.active_states):
            if state.paused:
                state.deactivate()
                self.paused_states.append(state)
        taskMgr.setupTaskChain("world", frameBudget=0)
        from gui import PauseMenu
        self.menu = PauseMenu()

    def pauseOff(self):
        for state in self.paused_states:
            state.activate()
        self.paused_states = []
        taskMgr.setupTaskChain("world", frameBudget=-1)
        self.menu.destroy()

    def togglePause(self):
        self.pauseOff() if self.paused_states else self.pauseOn()

    def status(self):
        """Returns True if paused."""
        return self.paused_states != []
 def pauseOn(self):
     for state in list(ControlState.active_states):
         if state.paused:
             state.deactivate()
             self.paused_states.append(state)
     taskMgr.setupTaskChain("world", frameBudget=0)
     from gui import PauseMenu
     self.menu = PauseMenu()