adding an index shift to the paginator allows correct selection of menu
items.

also, while i'm at it, removed a bug that was displaying rainbowmenu
incorrectly, and also added pagination to neighbor view.
master
endorphant 2016-11-08 18:38:15 -05:00
parent 90b8828ba5
commit 07a995afae
3 changed files with 48 additions and 24 deletions

View File

@ -107,8 +107,8 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
total = total - 1 total = total - 1
if total < 2: if total < 2:
print_menu(options, rainbow) util.print_menu(options, rainbow)
return list_select(options, prompt) return util.list_select(options, prompt)
else: else:
return page_helper(options, prompt, pagify, rainbow, page, total, top) return page_helper(options, prompt, pagify, rainbow, page, total, top)
@ -117,6 +117,11 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
def page_helper(options, prompt, pagify, rainbow, page, total, top): def page_helper(options, prompt, pagify, rainbow, page, total, top):
''' '''
A helper to process pagination. 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 ## make short list
@ -144,6 +149,13 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top):
redraw(error+top) redraw(error+top)
return page_helper(options, prompt, pagify, rainbow, page, total, 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 return ans
def redraw(leftover=""): def redraw(leftover=""):
@ -454,8 +466,9 @@ def main_menu():
view_feels(USER) view_feels(USER)
elif choice == '2': elif choice == '2':
users = core.find_ttbps() users = core.find_ttbps()
redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:") prompt = "the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:"
view_neighbors(users) redraw(prompt)
view_neighbors(users, prompt)
elif choice == '3': elif choice == '3':
redraw("most recent global entries") redraw("most recent global entries")
view_feed() view_feed()
@ -539,7 +552,7 @@ def review_menu(intro=""):
redraw(intro) redraw(intro)
return review_menu() return review_menu()
def view_neighbors(users): def view_neighbors(users, prompt):
''' '''
generates list of all users on ttbp, sorted by most recent post generates list of all users on ttbp, sorted by most recent post
@ -594,15 +607,12 @@ def view_neighbors(users):
sortedUsers.append(user[0]) sortedUsers.append(user[0])
userIndex.append(user[2]) userIndex.append(user[2])
util.print_menu(sortedUsers, RAINBOW) choice = menu_handler(sortedUsers, "pick a townie to browse their feels, or type 'back' or 'q' to go home: ", 15, RAINBOW, prompt)
#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' or 'q' to go home: ")
if choice is not False: if choice is not False:
redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n") redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n")
view_feels(userIndex[choice]) view_feels(userIndex[choice])
view_neighbors(users) view_neighbors(users, prompt)
else: else:
redraw() redraw()
return return
@ -1121,6 +1131,8 @@ ver 0.9.1 features:
print(""" print("""
ver 0.9.2 features: ver 0.9.2 features:
* paginated entry view * paginated entry view
* improved entry listing performance so it should
be less sluggish (for now)
* expanded menu for viewing your own feels (further * expanded menu for viewing your own feels (further
features to be implemented) features to be implemented)
""") """)

View File

@ -107,8 +107,8 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
total = total - 1 total = total - 1
if total < 2: if total < 2:
print_menu(options, rainbow) util.print_menu(options, RAINBOW)
return list_select(options, prompt) return util.list_select(options, prompt)
else: else:
return page_helper(options, prompt, pagify, rainbow, page, total, top) return page_helper(options, prompt, pagify, rainbow, page, total, top)
@ -117,6 +117,11 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
def page_helper(options, prompt, pagify, rainbow, page, total, top): def page_helper(options, prompt, pagify, rainbow, page, total, top):
''' '''
A helper to process pagination. 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 ## make short list
@ -124,7 +129,7 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top):
y = x + pagify y = x + pagify
optPage = options[x:y] optPage = options[x:y]
util.print_menu(optPage, prompt) util.print_menu(optPage, RAINBOW)
print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )").format(page=page+1, total=total+1) 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) ans = util.list_select(optPage, prompt)
@ -144,6 +149,13 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top):
redraw(error+top) redraw(error+top)
return page_helper(options, prompt, pagify, rainbow, page, total, 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 return ans
def redraw(leftover=""): def redraw(leftover=""):
@ -453,8 +465,9 @@ def main_menu():
view_feels(USER) view_feels(USER)
elif choice == '2': elif choice == '2':
users = core.find_ttbps() users = core.find_ttbps()
redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:") prompt = "the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:"
view_neighbors(users) redraw(prompt)
view_neighbors(users, prompt)
elif choice == '3': elif choice == '3':
redraw("most recent global entries") redraw("most recent global entries")
view_feed() view_feed()
@ -538,7 +551,7 @@ def review_menu(intro=""):
redraw(intro) redraw(intro)
return review_menu() return review_menu()
def view_neighbors(users): def view_neighbors(users, prompt):
''' '''
generates list of all users on ttbp, sorted by most recent post generates list of all users on ttbp, sorted by most recent post
@ -593,15 +606,12 @@ def view_neighbors(users):
sortedUsers.append(user[0]) sortedUsers.append(user[0])
userIndex.append(user[2]) userIndex.append(user[2])
util.print_menu(sortedUsers, RAINBOW) choice = menu_handler(sortedUsers, "pick a townie to browse their feels, or type 'back' or 'q' to go home: ", 15, RAINBOW, prompt)
#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' or 'q' to go home: ")
if choice is not False: if choice is not False:
redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n") redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n")
view_feels(userIndex[choice]) view_feels(userIndex[choice])
view_neighbors(users) view_neighbors(users, prompt)
else: else:
redraw() redraw()
return return
@ -1120,6 +1130,8 @@ ver 0.9.1 features:
print(""" print("""
ver 0.9.2 features: ver 0.9.2 features:
* paginated entry view * paginated entry view
* improved entry listing performance so it should
be less sluggish (for now)
* expanded menu for viewing your own feels (further * expanded menu for viewing your own feels (further
features to be implemented) features to be implemented)
""") """)

View File

@ -158,7 +158,7 @@ def print_menu(menu, rainbow=False):
i = 0 i = 0
for x in menu: for x in menu:
line = [] line = []
if rainbow: if rainbow is not False:
line.append(attach_rainbow()) line.append(attach_rainbow())
line.append("\t[ ") line.append("\t[ ")
if i < 10: if i < 10: