示例#1
0
def review_menu(intro=""):
    '''
    submenu for reviewing feels.
    '''

    menuOptions = [
            "read over feels",
            "modify feels publishing"
            ]

    util.print_menu(menuOptions, RAINBOW)

    choice = util.list_select(menuOptions, "what would you like to do with your feels? (or 'back' to return home) ")

    if choice is not False:
        if choice == 0:
            redraw("your recorded feels, listed by date:")
            view_feels(USER)
        elif choice == 1:
            redraw("here's your current nopub status:")
            set_nopubs()
    else:
        redraw()
        return

    redraw(intro)
    return review_menu()
示例#2
0
def select_editor():
    '''
    setup helper for editor selection
    '''

    util.print_menu(EDITORS, RAINBOW)
    choice = util.list_select(EDITORS, "pick your favorite text editor: ")

    if choice is False:
        redraw("please pick a text editor!")
        select_editor()

    return EDITORS[int(choice)]
示例#3
0
def select_editor():
    '''
    setup helper for editor selection
    '''

    util.print_menu(EDITORS, RAINBOW)
    
    choice = util.list_select(EDITORS, "pick your favorite text editor: ")
    #choice = raw_input("\npick your favorite text editor: ")
    #while choice  not in ['0', '1', '2', '3', '4', '5']:
    #    choice = raw_input("\nplease pick a number from the list: ")

    if choice is False:
        redraw("please pick a text editor!")
        select_editor()

    return EDITORS[int(choice)]
示例#4
0
def page_helper(options, prompt, pagify, rainbow, page, total, top):
    '''
    A helper to process pagination.

    'pagify' is the number of entries per page of display
    'page' is the current page number
    'total' is the total number of pages
    'top' is displyed after the banner redraw
    '''

    ## make short list
    x = 0 + page * pagify
    y = x + pagify
    optPage = options[x:y]

    util.print_menu(optPage, prompt)
    print(
        "\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )"
    ).format(page=page + 1, total=total + 1)

    ans = util.list_select(optPage, prompt)

    if ans in util.NAVS:
        error = ""
        if ans == 'u':
            if page == 0:
                error = "can't scroll up anymore!\n\n> "
            else:
                page = page - 1
        else:
            if page == total:
                error = "can't scroll down anymore!\n\n> "
            else:
                page = page + 1
        redraw(error + top)
        return page_helper(options, prompt, pagify, rainbow, page, total, top)

    elif ans is False:
        return ans

    else:
        # shift answer to refer to index from original list
        ans = ans + page * pagify

        return ans
示例#5
0
def list_entries(metas, entries, prompt):
    '''
    displays a list of entries for reading selection
    '''

    util.print_menu(entries, RAINBOW)

    choice = util.list_select(entries, "pick an entry from the list, or type 'back' to go back: ")

    if choice is not False:

        redraw("now reading ~"+metas[choice][5]+"'s feels on "+metas[choice][4]+"\n> press <q> to return to feels list.\n\n")

        show_entry(metas[choice][0])
        redraw(prompt)

        return list_entries(metas, entries, prompt)

    else:
        redraw()
        return
示例#6
0
def list_entries(metas, entries, prompt):
    '''
    displays a list of entries for reading selection
    '''

    util.print_menu(entries, RAINBOW)

    choice = util.list_select(entries, "pick an entry from the list, or type 'back' to go back: ")

    if choice is not False:

        redraw("now reading ~"+metas[choice][5]+"'s feels on "+metas[choice][4]+"\n> press <q> to return to feels list.\n\n")

        show_entry(metas[choice][0])
        redraw(prompt)

        return list_entries(metas, entries, prompt)

    else:
        redraw()
        return
示例#7
0
def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
    '''
    This menu handler takes an incoming list of options, pagifies to a
    pre-set value, and queries via the prompt. Calls print_menu() and
    list_select() as helpers.

    'top' is an optional list topper, to be passed to redraw()
    '''

    optCount = len(options)
    page = 0
    total = optCount / pagify

    # don't display empty pages
    if optCount % pagify == 0:
        total = total - 1

    if total < 2:
        util.print_menu(options, rainbow)
        return util.list_select(options, prompt)

    else:
        return page_helper(options, prompt, pagify, rainbow, page, total, top)
示例#8
0
def view_neighbors(users):
    '''
    generates list of all users on ttbp, sorted by most recent post

    * if user is publishing, list publish directory
    '''

    userList = []

    ## assumes list of users passed in all have valid config files
    for user in users:
        userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))

        ## retrieve publishing url, if it exists
        url="\t\t\t"
        if userRC.get("publish dir"):
            url = LIVE+user+"/"+userRC.get("publish dir")

        ## find last entry
        files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
        files.sort()
        lastfile = ""
        for filename in files:
            if core.valid(filename):
                lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)

        ## generate human-friendly timestamp
        ago = "never"
        if lastfile:
            last = os.path.getctime(lastfile)
            since = time.time()-last
            ago = util.pretty_time(int(since)) + " ago"
        else:
            last = 0

        ## some formatting handwavin
        urlpad = ""
        if ago == "never":
            urlpad = "\t"

        userpad = ""
        if len(user) < 7:
            userpad = "\t"

        userList.append(["\t~"+user+userpad+"\t("+ago+")"+urlpad+"\t"+url, last, user])

    # sort user by most recent entry for display
    userList.sort(key = lambda userdata:userdata[1])
    userList.reverse()
    sortedUsers = []
    userIndex = []
    for user in userList:
        sortedUsers.append(user[0])
        userIndex.append(user[2])

    util.print_menu(sortedUsers, RAINBOW)

    #raw_input("\n\npress <enter> to go back home.\n\n")
    choice = util.list_select(sortedUsers, "pick a townie to browse their feels, or type 'back' to go home: ")

    if choice is not False:
        redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n")
        view_feels(userIndex[choice])
        view_neighbors(users)
    else:
        redraw()
        return
示例#9
0
def view_neighbors(users):
    '''
    generates list of all users on ttbp, sorted by most recent post

    * if user is publishing, list publish directory
    '''

    userList = []

    ## assumes list of users passed in all have valid config files
    for user in users:
        userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))

        ## retrieve publishing url, if it exists
        url="\t\t\t"
        if userRC.get("publish dir"):
            url = LIVE+user+"/"+userRC.get("publish dir")

        ## find last entry
        files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
        files.sort()
        lastfile = ""
        for filename in files:
            if core.valid(filename):
                lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)

        ## generate human-friendly timestamp
        ago = "never"
        if lastfile:
            last = os.path.getctime(lastfile)
            since = time.time()-last
            ago = util.pretty_time(int(since)) + " ago"
        else:
            last = 0

        ## some formatting handwavin
        urlpad = ""
        if ago == "never":
            urlpad = "\t"

        userpad = ""
        if len(user) < 7:
            userpad = "\t"

        userList.append(["\t~"+user+userpad+"\t("+ago+")"+urlpad+"\t"+url, last, user])

    # sort user by most recent entry for display
    userList.sort(key = lambda userdata:userdata[1])
    userList.reverse()
    sortedUsers = []
    userIndex = []
    for user in userList:
        sortedUsers.append(user[0])
        userIndex.append(user[2])

    util.print_menu(sortedUsers, RAINBOW)

    #raw_input("\n\npress <enter> to go back home.\n\n")
    choice = util.list_select(sortedUsers, "pick a townie to browse their feels, or type 'back' to go home: ")

    if choice is not False:
        redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n")
        view_feels(userIndex[choice])
        view_neighbors(users)
    else:
        redraw()
        return