Esempio n. 1
0
def __onConfigChange(conf):
    global __gameDir
    parole.info("Resource package suffix: %s", conf.resource.packsuffix)
    if not __inInit:
        parole.warn("New package suffix will take effect on restart.")
    parole.info("Allowdirs: %s", conf.resource.allowdirs)
    if not __inInit:
        parole.warn("New resource.allowdirs will take effect on restart.")
    __gameDir = conf.resource.gamedir
    parole.info("Game directory: %s", __gameDir)
Esempio n. 2
0
def __onConfigChange(conf):
    global __gameDir
    parole.info('Resource package suffix: %s', conf.resource.packsuffix)
    if not __inInit:
        parole.warn('New package suffix will take effect on restart.')
    parole.info('Allowdirs: %s', conf.resource.allowdirs)
    if not __inInit:
        parole.warn('New resource.allowdirs will take effect on restart.')
    __gameDir = conf.resource.gamedir
    parole.info('Game directory: %s', __gameDir)
Esempio n. 3
0
    def raw_input(self, prompt):
        """
        Currently the C{raw_input} function is not supported within the Parole
        console; this always returns the empty string.

        @return: "" (empty string)
        """
        # not supported!
        parole.warn('Parole Interactive Console: raw_input() not supported!')
        return ''
Esempio n. 4
0
    def raw_input(self, prompt):
        """
        Currently the C{raw_input} function is not supported within the Parole
        console; this always returns the empty string.

        @return: "" (empty string)
        """
        # not supported!
        parole.warn('Parole Interactive Console: raw_input() not supported!')
        return ''
Esempio n. 5
0
    def __init__(self, height, font, ps1, ps2):
        borders = (None, None, None,
                   shader.HorizontalBevel((200, 200, 0), (128, 128, 0),
                                          (64, 64, 0), 1, 3,
                                          1), None, None, None, None)

        shader.Frame.__init__(self, borders, alpha=255, name="ConsoleFrame")

        try:
            self.log = open(logFile, 'w')
        except:
            parole.warn('Unable to open console log file "%s" for writing.',
                        logFile)
            self.log = cStringIO.StringIO()

        try:
            self.histf = open(historyFile, 'a')
        except:
            parole.warn(
                'Unable to open console history file "%s" for writing.',
                logFile)
            self.histf = cStringIO.StringIO()

        self.ps1, self.ps2 = ps1, ps2
        self.__font = font

        screenWidth = display.getSurface().get_width()
        self.readLineBox = shader.ReadLineBox(font,
                                              screenWidth - 5,
                                              prompt=self.ps1)
        self.scroll = shader.ScrollView((screenWidth, height - \
            self.readLineBox.height),
            vbar=shader.VerticalScrollbar((128,128,0), (64,64,0), 10),
            followY=True)
        self.textblock = shader.TextBlockPass(font, (255, 255, 255),
                                              wrap_width=screenWidth - 20,
                                              ignoreMarkup=True)
        self.background = shader.ColorField((0, 0, 128, 220),
                                            (screenWidth, height))

        self.addPass(self.background)
        self.scroll.addPass(self.textblock, pos=(5, 0))
        self.addPass(self.scroll)

        self.addPass(self.readLineBox,
                     pos=(5, height - self.readLineBox.height))

        self.active = False

        self.cmdMap = input.CommandMap(parole.conf.console.commands,
                                       self.handleCommand,
                                       peek=True)
        self.readLine = input.ReadLine(self.onNewline,
                                       self.readLineBox.onInput)
Esempio n. 6
0
    def __init__(self, height, font, ps1, ps2):
        borders = (None,None,None, shader.HorizontalBevel((200,200,0),
            (128,128,0), (64,64,0), 1, 3, 1), None, None, None, None)

        shader.Frame.__init__(self, borders, alpha=255, name="ConsoleFrame")

        try:
            self.log = open(logFile, 'w')
        except:
            parole.warn('Unable to open console log file "%s" for writing.',
                    logFile)
            self.log = cStringIO.StringIO()

        try:
            self.histf = open(historyFile, 'a')
        except:
            parole.warn('Unable to open console history file "%s" for writing.',
                    logFile)
            self.histf = cStringIO.StringIO()

        self.ps1, self.ps2 = ps1, ps2
        self.__font = font

        screenWidth = display.getSurface().get_width()
        self.readLineBox = shader.ReadLineBox(font, screenWidth-5,
                prompt=self.ps1)
        self.scroll = shader.ScrollView((screenWidth, height - \
            self.readLineBox.height),
            vbar=shader.VerticalScrollbar((128,128,0), (64,64,0), 10),
            followY=True)
        self.textblock = shader.TextBlockPass(font, (255,255,255),
                wrap_width=screenWidth-20, ignoreMarkup=True)
        self.background = shader.ColorField((0,0,128,220), (screenWidth,
            height))

        self.addPass(self.background)
        self.scroll.addPass(self.textblock, pos=(5,0))
        self.addPass(self.scroll)

        self.addPass(self.readLineBox, pos=(5, height -
            self.readLineBox.height))

        self.active = False

        self.cmdMap = input.CommandMap(parole.conf.console.commands,
                self.handleCommand, peek=True)
        self.readLine = input.ReadLine(self.onNewline, 
                self.readLineBox.onInput)
Esempio n. 7
0
def clearResource(name):
    """
    Clears the cache of the given resource. Any future retrieval of the 
    resource will result in an actual disk read. The resource may not actually
    be freed from memory if any user code still contains references to it.
    Furthermore, it won't actually be freed until the next sweep of Python's
    garbage collector.

    @param name: The path + filename of the resource to clear from the cache.
    @type name: C{str}
    """
    parole.info("Clearing resource: %s", name)
    if name in __resTable:
        del __resTable[name]
    else:
        parole.warn("Can't clear unknown resource: %s", name)
Esempio n. 8
0
def clearResource(name):
    """
    Clears the cache of the given resource. Any future retrieval of the 
    resource will result in an actual disk read. The resource may not actually
    be freed from memory if any user code still contains references to it.
    Furthermore, it won't actually be freed until the next sweep of Python's
    garbage collector.

    @param name: The path + filename of the resource to clear from the cache.
    @type name: C{str}
    """
    parole.info('Clearing resource: %s', name)
    if name in __resTable:
        del __resTable[name]
    else:
        parole.warn("Can't clear unknown resource: %s", name)
Esempio n. 9
0
def __init():
    """
    Initializes the console module. Automatically called during engine 
    startup - user code shouldn't need to use this function.
    """
    global frame, stdout, stderr, logHandler, interpreter, history, historyPos
    
    parole.conf.notify(__onConfigChange, True)

    # Initialize the console command history
    history = []
    historyPos = 0

    # Create the console frame shader. 
    frame = ConsoleFrame(parole.conf.console.height,
            resource.getFont('fonts/monaco.ttf', 10), parole.conf.console.ps1,
            parole.conf.console.ps2)

    # Write the intro banner to the console
    frame.write(banner)
    frame.flush()

    # Start logging to the console (INFO level)
    parole.info('Begin logging to console...')
    logHandler = logging.StreamHandler(frame)
    logHandler.setLevel(logging.INFO)
    logHandler.setFormatter(logging.Formatter(\
        '%(levelname)s: %(message)s'))
    logging.getLogger().addHandler(logHandler)

    # Create the actual interpreter
    #stderr = sys.stderr
    #sys.stderr = frame
    stdout = sys.stdout
    sys.stdout = frame
    parole.info('Setting up console Python interpreter...')
    interpreter = ConsoleInterpreter()

    parole.info('Loading console history file...')
    try:
        hf = open(historyFile, 'r')
        history = [l[:len(l)-1] for l in hf.readlines() if len(l) > 1]
        historyPos = len(history)
        hf.close()
    except:
        parole.warn('Unable to open/load history file "%s".', historyFile)
Esempio n. 10
0
def __init():
    """
    Initializes the console module. Automatically called during engine 
    startup - user code shouldn't need to use this function.
    """
    global frame, stdout, stderr, logHandler, interpreter, history, historyPos

    parole.conf.notify(__onConfigChange, True)

    # Initialize the console command history
    history = []
    historyPos = 0

    # Create the console frame shader.
    frame = ConsoleFrame(parole.conf.console.height,
                         resource.getFont('fonts/monaco.ttf', 10),
                         parole.conf.console.ps1, parole.conf.console.ps2)

    # Write the intro banner to the console
    frame.write(banner)
    frame.flush()

    # Start logging to the console (INFO level)
    parole.info('Begin logging to console...')
    logHandler = logging.StreamHandler(frame)
    logHandler.setLevel(logging.INFO)
    logHandler.setFormatter(logging.Formatter(\
        '%(levelname)s: %(message)s'))
    logging.getLogger().addHandler(logHandler)

    # Create the actual interpreter
    #stderr = sys.stderr
    #sys.stderr = frame
    stdout = sys.stdout
    sys.stdout = frame
    parole.info('Setting up console Python interpreter...')
    interpreter = ConsoleInterpreter()

    parole.info('Loading console history file...')
    try:
        hf = open(historyFile, 'r')
        history = [l[:len(l) - 1] for l in hf.readlines() if len(l) > 1]
        historyPos = len(history)
        hf.close()
    except:
        parole.warn('Unable to open/load history file "%s".', historyFile)