Пример #1
0
def main(file=None, invert=False, Showart=True):
    """ Main procedure. """
    if file != None:
        displayfile(file)
        return
    session = getsession()
    term = getterminal()
    session.activity = 'Reading text files'
    currentfolder = []
    stored_lbar_pos = []
    filelist = getfilelist(STARTFOLDER)
    dirty = True
    inp = None
    lbar = Lightbar(height = 0, width = 0, xloc = 0, yloc = 0, colors={'highlight': term.bold_white_on_red})
    # sets up a lightbar. update_lightbar will give it it's actual values.

    echo(term.clear+banner()+term.hide_cursor)
    while 1:
        if dirty:
            update_lightbar(lbar,term,filelist)
            dirty = False
        while not inp:
            inp = getch(0.2)
            if session.poll_event('refresh'):
                echo(term.clear)
                if term.width > 79: echo(banner())
                update_lightbar(lbar,term,filelist)
                dirty = True
        lbar.process_keystroke(inp)
        if lbar.quit: 
            echo(term.normal_cursor)
            return
        echo(lbar.refresh_quick())
        if inp == term.KEY_ENTER:
            if lbar.selection[1] == '( .. ) GO BACK' or os.path.isdir(STARTFOLDER+u''.join(currentfolder)+lbar.selection[0]):
                if lbar.selection[1] == '( .. ) GO BACK':
                    del currentfolder[-1]
                    filelist = getfilelist(STARTFOLDER+u''.join(currentfolder))
                    lbar.update(filelist)
                    lbar.goto(stored_lbar_pos[-1])
                    del stored_lbar_pos[-1]
                else:
                    currentfolder.append(lbar.selection[0]+u'/')
                    stored_lbar_pos.append(lbar.index)
                    filelist = getfilelist(STARTFOLDER+u''.join(currentfolder))                        
                    lbar.goto(0)
                if len(currentfolder) > 0:
                    filelist.insert(0,['( .. ) GO BACK','( .. ) GO BACK'])
                lbar.update(filelist)
            else:
                displayfile(STARTFOLDER+u''.join(currentfolder)+lbar.selection[0])
                echo(term.clear+banner())
            dirty = True
        inp = None
Пример #2
0
    def get_sign(force=False):
        """
        Return the user's sign or let them choose one using a Lightbar.

        :param bool force: If True, does not retrive the user's sign from the db
        :rtype: :class:`str`
        """

        database = DBProxy('astrology', table='users')

        if not force and session.user.handle in database:
            return database[session.user.handle]

        lbar = Lightbar(width=15, height=14, xloc=max(term.width / 2 - 7, 0),
                        yloc=max(term.height / 2 - 7, 0),
                        colors={'border': lightbar_border,
                                'highlight': lightbar_highlight,
                                'lowlight': lightbar_lowlight},
                        glyphs={'top-left': u'+', 'top-right': u'+',
                                'top-horiz': u'-', 'bot-horiz': u'-',
                                'bot-left': u'+', 'bot-right': u'+',
                                'left-vert': u'|', 'right-vert': u'|'})

        def refresh():
            """ Refresh the lightbar. """
            echo(u''.join((term.normal, term.clear)))
            contents = ((key, key) for key in SIGNS)
            lbar.update(contents)
            echo(u''.join([lbar.border(), lbar.refresh()]))

        refresh()

        while not lbar.selected and not lbar.quit:
            event, data = session.read_events(['refresh', 'input'])

            if event == 'refresh':
                refresh()
            elif event == 'input':
                session.buffer_input(data, pushback=True)
                echo(lbar.process_keystroke(term.inkey()))

        if lbar.quit:
            return

        sign, _ = lbar.selection
        database[session.user.handle] = sign

        return sign