def back(): if var.menu_type == "authors" or var.menu_type == "volume": main.start() elif var.menu_type == "issue": var.issue_y_pos = 0 var.articles_y_pos = 0 var.authors_y_pos = 0 var.author_articles_y_pos = 0 var.author_current_page = 0 var.author_name = "" var.volume_year = 0 var.volume_number = 0 var.issue_number = 0 var.menu_type = "volume" displays.start() elif var.menu_type == "articles": var.articles_y_pos = 0 var.authors_y_pos = 0 var.author_articles_y_pos = 0 var.author_current_page = 0 var.author_name = 0 var.menu_type = "issue" displays.start() elif var.menu_type == "author_articles": var.volume_y_pos = 0 var.issue_y_pos = 0 var.articles_y_pos = 0 var.author_articles_y_pos = 0 var.volume_number = 0 var.volume_year = 0 var.volume_current_page = 0 var.issue_number = 0 var.menu_type = "authors" displays.start()
def get_option(char): if char == ord('1'): root = tk.Tk() root.withdraw() new_path = filedialog.askdirectory() isOkay = files.change_path(new_path, var.download_folder) elif char == ord('2'): downloads.delete_all() elif char == ord('3'): main.start()
from display import main as main_menu #outside imports from utilities import variables as var if __name__ == '__main__': var.init() main_menu.start()
def menu(stdscr): current_location = var.download_folder global cursor_y cursor_y = 5 k = 0 curses.curs_set(0) stdscr.clear() stdscr.refresh() height, width = stdscr.getmaxyx() curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLUE) title_str = "Download Info" status_msg = " 'm' : Main Menu | 'q' : Quit" option_1 = "1. Change Directory" option_2 = "2. Delete All Files" option_3 = "3. Exit" while (True): info_1 = "Current Directory: {}".format(current_location) info_2 = "Downloaded Files: {}".format(downloads.get_files()) info_3 = "Directory Size: {}".format(downloads.get_size()) k = 0 stdscr.clear() m.title(stdscr, title_str) m.status_bar(stdscr, status_msg) stdscr.attron(curses.color_pair(1)) stdscr.addstr(1, 1, info_1) stdscr.addstr(2, 1, info_2) stdscr.addstr(3, 1, info_3) stdscr.attroff(curses.color_pair(1)) m.menu_option(stdscr, option_1, 5, 1, cursor_y) m.menu_option(stdscr, option_2, 6, 1, cursor_y) m.menu_option(stdscr, option_3, 7, 1, cursor_y) stdscr.move(cursor_y, 1) stdscr.refresh() k = stdscr.getch() if k == curses.KEY_UP: key_up() elif k == curses.KEY_DOWN: key_down() elif k == 10 or k == curses.KEY_RIGHT: char = int.from_bytes(stdscr.instr(cursor_y, 1, 1), byteorder='little') get_option(char) elif k == curses.KEY_LEFT or k == ord('m') or k == 27: main.start() elif k == ord('q'): sys.exit() elif k == ord('1'): cursor_y = 5 elif k == ord('2'): cursor_y = 6 elif k == ord('3'): cursor_y = 7
def menu(stdscr): x_start_pos = 1 cursor_y = 1 cursor_x = 1 k = 0 sort_int = 1 if var.menu_type == "authors": if not var.authors_y_pos == 0: cursor_y = var.authors_y_pos current_page = var.author_current_page elif var.menu_type == "volume": if not var.volume_y_pos == 0: cursor_y = var.volume_y_pos current_page = var.volume_current_page elif var.menu_type == "issue": if not var.issue_y_pos == 0: cursor_y = var.issue_y_pos current_page = 1 elif var.menu_type == "articles": if not var.articles_y_pos == 0: cursor_y = var.articles_y_pos current_page = 1 elif var.menu_type == "author_articles": if not var.author_articles_y_pos == 0: cursor_y = var.author_articles_y_pos current_page = 1 else: current_page = 1 curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] curses.curs_set(0) stdscr.clear() stdscr.refresh() while(True): stdscr.clear() title_str = mh.get_title(sort_int) m.title(stdscr, title_str) if var.menu_type == "volume": display_list = get_list.volume() elif var.menu_type == "issue": display_list = get_list.issue() elif var.menu_type == "articles": display_list = get_list.articles() elif var.menu_type == "authors": display_list = get_list.authors(sort_int) elif var.menu_type == "author_articles": display_list = get_list.author_articles() rows = len(display_list) max_rows = m.get_height(stdscr) - 5 if max_rows > rows: max_rows = rows num_pages = ceil(rows / max_rows) last_page_row = arith.get_last_row(rows, max_rows, num_pages) status_msg = mh.get_status_bar(current_page, num_pages, sort_int) m.status_bar(stdscr, status_msg) l_row = "Page {} of {}".format(current_page, num_pages) m.last_row(stdscr, l_row) for i in range(0, max_rows): y_position = i + 1 if not (current_page == num_pages and y_position >= last_page_row - 1): m.display_option(stdscr, y_position, x_start_pos, cursor_y, max_rows, num_pages, current_page, last_page_row, display_list) stdscr.move(cursor_y, cursor_x) stdscr.refresh() k = stdscr.getch() if k == curses.KEY_UP: cursor_y = calculate_y.up(cursor_y, current_page, num_pages, max_rows, rows, last_page_row) elif k == curses.KEY_DOWN: cursor_y = calculate_y.down(cursor_y, current_page, num_pages, max_rows, rows, last_page_row) elif k == curses.KEY_LEFT and not current_page == 1: cursor_y = 1 current_page -= 1 elif k == curses.KEY_LEFT and current_page == 1: mh.back() elif k == curses.KEY_RIGHT and not current_page == num_pages: cursor_y = 1 current_page += 1 elif var.menu_type == "authors": if k == 27: mh.back() elif k == ord('1'): sort_int = m.get_sort_1(sort_int) current_page = 1 elif k == ord('2'): sort_int = m.get_sort_2(sort_int) current_page = 1 elif k == 10: i = arith.get_index(max_rows, num_pages, current_page, cursor_y, last_page_row) pre_display = display_list[i] var.authors_y_pos = cursor_y var.author_name = pre_display["original"] var.author_current_page = current_page var.menu_type = "author_articles" menu(stdscr) else: letter = str(chr(k)) if letter in alpha: index = string_handler.get_index_of_letter(letter, display_list, sort_int) if not index == -1: page_cursor = arith.get_page_and_cursor(index, max_rows, num_pages) current_page = page_cursor[0] cursor_y = page_cursor[1] elif var.menu_type == "volume": if k == 27: mh.back() elif k == ord('n') and not current_page == num_pages: cursor_y - 1 current_page += 1 elif k == ord('p'): if current_page == 1: main.start() else: cursor_y = 1 current_page -= 1 elif k == 10: i = arith.get_index(max_rows, num_pages, current_page, cursor_y, last_page_row) volume_num = str(display_list[i]) year = get_numbers.year(volume_num) if(len(volume_num) == 1): volume_num = "0" + volume_num var.volume_y_pos = cursor_y var.volume_number = volume_num var.volume_year = year var.volume_current_page = current_page var.menu_type = "issue" menu(stdscr) elif var.menu_type == "issue": if k == 10: selected_issue = cursor_y - 1 if selected_issue == 0: selected_issue = "All" var.issue_number = selected_issue var.menu_type = "articles" var.issue_y_pos = cursor_y menu(stdscr) elif k == 27: mh.back() elif var.menu_type == "articles": i = arith.get_index(max_rows, num_pages, current_page, cursor_y, last_page_row) article_id = display_list[i] if k == 27: mh.back() elif k == 10 or k == ord('o'): get_url.by_article_id(article_id) elif k == ord('i'): article.start(article_id) elif k == ord('v'): var.issue_y_pos = 0 var.articles_y_pos = 0 var.menu_type = "volume" menu(stdscr) elif var.menu_type == "author_articles": i = arith.get_index(max_rows, num_pages, current_page, cursor_y, last_page_row) article_id = display_list[i] if k==27 or k == ord('a'): mh.back() elif k == 10 or k == ord('o'): get_url.by_article_id(article_id) elif k == ord('i'): var.author_articles_y_pos = cursor_y article.start(article_id) if var.menu_type == "volume" or var.menu_type == "issue" or var.menu_type == "articles": if k == ord('m'): main.start() if k == ord('q'): sys.exit()
def menu(stdscr, article_id): x_start_pos = 1 k = 0 full_number = get_numbers.full(article_id) stdscr.clear() stdscr.refresh() x_start_pos = 2 x_indent = 6 curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) #menu_type, main_pos, authors_current_page, volume_number, volume_year, volume_current_page, issue_number, author_name): while True: if var.menu_type == "articles" or var.menu_type == "author_articles": if k == ord('m'): main.start() elif k == ord('o'): get_url.by_article_id(article_id) elif k == ord('d'): pass ## TODO: Downloader if var.menu_type == "articles": status_bar = " 'o' : Open | 'b'/esc : Back | 'i' : Issue Selection | 'v' : Volume Selection | 'd' : Download | 'm' : Main Menu" if k == ord('i'): var.menu_type = "issue" var.articles_y_pos = 0 displays.start() elif k == ord('v'): var.menu_type = "volume" var.articles_y_pos = 0 var.issue_y_pos = 0 var.issue_number = 0 var.volume_number = 0 var.volume_year = 0 displays.start() elif k == 27 or k == curses.KEY_LEFT or k == ord('b'): displays.start() elif var.menu_type == "author_articles": status_bar = " 'o' : Open | 'b'/esc : Back | 'a' : Author Selection | 'd' : Download | 'm' : Main Menu" if k == 27 or k == ord('b') or k == curses.KEY_LEFT: displays.start() elif k == ord("a"): var.author_articles_y_pos = 0 var.menu_type = "authors" displays.start() stdscr.clear() height, width = stdscr.getmaxyx() title = get_title.by_article_id(article_id) authors = get_author.by_article_id(article_id) volume = full_number.split(".")[0] issue = full_number.split(".")[1] article = full_number.split('.')[2] stdscr.attron(curses.color_pair(1)) first_line = "Article {} from Volume {} Issue {}".format(article, volume, issue) stdscr.addstr(0, x_start_pos, first_line) stdscr.attroff(curses.color_pair(1)) second_line = "Title: " stdscr.attron(curses.color_pair(1)) stdscr.addstr(2, x_start_pos, second_line) stdscr.attroff(curses.color_pair(1)) stdscr.addstr(3, x_indent, title) third_line = "Authors:" stdscr.attron(curses.color_pair(1)) stdscr.addstr(5, x_start_pos, third_line) stdscr.attroff(curses.color_pair(1)) stdscr.attron(curses.color_pair(3)) stdscr.addstr(height-1, 0, status_bar) stdscr.addstr(height-1, len(status_bar), " " * (width - len(status_bar) - 1)) stdscr.attroff(curses.color_pair(3)) y_start = 6 for name in authors: stdscr.addstr(y_start, x_indent, name) y_start += 1 stdscr.move(0,0) stdscr.refresh() k = stdscr.getch()
def menu(stdscr, title_term, author_term): cursor_y = 2 stdscr.clear() stdscr.refresh() height, width = stdscr.getmaxyx() curses.curs_set(True) curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) title_str = "Search The JETS Archive" status_msg = " To search, enter a term and/or author and press enter | 'm'/esc : Back | 'q' : Quit" title_label = "Search By Title: " author_label = "Search By Author: " x_pos_title = len(title_label) + 2 x_pos_author = len(author_label) + 2 title_search = "" author_search = "" cursor_x = x_pos_title isError = False while (True): stdscr.clear() m.title(stdscr, title_str) m.status_bar(stdscr, status_msg) m.login_option(stdscr, title_label, 2, 2, cursor_y, False) m.login_option(stdscr, author_label, 3, 2, cursor_y, False) m.add_string(stdscr, title_search, 2, x_pos_title) m.add_string(stdscr, author_search, 3, x_pos_author) if isError: stdscr.attron(curses.color_pair(2)) stdscr.addstr(4, (width - len("Please Enter A Term")) // 2, "Please Enter A Term") stdscr.attroff(curses.color_pair(2)) stdscr.move(cursor_y, cursor_x) stdscr.refresh() k = stdscr.getch() if k == 27: main.start() elif k == 9: if cursor_y == 2: cursor_y = 3 cursor_x = x_pos_author + len(author_search) elif cursor_y == 3: cursor_y = 2 cursor_x = x_pos_title + len(title_search) elif k == 10: if cursor_y == 2: cursor_y = 3 cursor_x = x_pos_author elif cursor_y == 3: if len(title_search) == 0 and len(author_search) == 0: isError = True else: if len(title_search) == 0: searcher.by_author(author_search) elif len(author_search) == 0: searcher.by_title(title_search) elif len(title_search) > 0 and len(author_search) > 0: searcher.by_both(author_search, title_search) elif k == curses.KEY_UP or k == curses.KEY_DOWN: if cursor_y == 3: cursor_y = 2 cursor_x = x_pos_title + len(title_search) elif cursor_y == 2: cursor_y = 3 cursor_x = x_pos_author + len(author_search) elif k == curses.KEY_LEFT: if cursor_y == 2 and not cursor_x <= x_pos_title: cursor_x -= 1 elif cursor_y == 3 and not cursor_x == x_pos_author: cursor_x -= 1 elif k == curses.KEY_RIGHT: if cursor_y == 2 and not cursor_x >= x_pos_title + len( title_search): cursor_x += 1 elif cursor_y == 3 and not cursor_x >= x_pos_author + len( author_search): cursor_x += 1 elif cursor_y == 2: title_search = inputs.handler(title_search, k, x_pos_title, cursor_x) cursor_x = x_pos_title + len(title_search) elif cursor_y == 3: author_search = inputs.handler(author_search, k, x_pos_author, cursor_x) cursor_x = x_pos_author + len(author_search)
def menu(stdscr, main_pos): cursor_y = 2 k = 0 curses.curs_set(True) stdscr.clear() stdscr.refresh() valid_symbols = "!@#$%^&*()_-+={}[]" curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) title_str = "etsjets.org Login" user_label = "Username: "******"Password: "******"" password_display = "" password = "" success = "" isError = False height, width = stdscr.getmaxyx() cursor_x = x_pos_user while (True): stdscr.clear() password_display = "*" * len(password) if isError == True and success == "Please enter a username": m.login_option(stdscr, user_label, 2, 2, cursor_y, True) else: m.login_option(stdscr, user_label, 2, 2, cursor_y, False) if isError == True and success == "Please enter a password": m.login_option(stdscr, password_label, 3, 2, cursor_y, True) else: m.login_option(stdscr, password_label, 3, 2, cursor_y, False) m.add_string(stdscr, username, 2, x_pos_user) m.add_string(stdscr, password_display, 3, x_pos_pass) m.title(stdscr, title_str) m.login_status(stdscr, isError, success, 4, curses.color_pair(2), curses.color_pair(4)) stdscr.move(cursor_y, cursor_x) stdscr.refresh() if isError == False and success == "Successfully logged in! Returning to main menu...": time.sleep(5) main.start() k = stdscr.getch() if k == 27: main.start() elif k == 9: if cursor_y == 2: cursor_y = 3 cursor_x = x_pos_pass + len(password) elif cursor_y == 3: cursor_y = 2 cursor_x = x_pos_user + len(username) elif k == 10: if cursor_y == 2: cursor_y = 3 cursor_x = x_pos_pass elif cursor_y == 3: if len(username) == 0: success = "Please enter a username" cursor_y = 2 isError = True elif len(password) == 0: success = "Please enter a password" cursor_y = 3 isError = True else: isLogged = login.set_login(username, password) if isLogged: success = "Successfully logged in! Returning to main menu..." isError = False else: success = "Incorrect Login" isError = True elif k == curses.KEY_UP or k == curses.KEY_DOWN: if cursor_y == 3: cursor_y = 2 cursor_x = x_pos_user + len(username) elif cursor_y == 2: cursor_y = 3 cursor_x = x_pos_pass + len(password_display) elif k == curses.KEY_LEFT: if cursor_y == 2 and not cursor_x <= x_pos_user: cursor_x -= 1 elif cursor_y == 3 and not cursor_x == x_pos_pass: cursor_x -= 1 elif k == curses.KEY_RIGHT: if cursor_y == 2 and not cursor_x >= x_pos_user + len(username): cursor_x += 1 elif cursor_y == 3 and not cursor_x >= x_pos_pass + len( password_display): cursor_x += 1 elif cursor_y == 2: username = inputs.handler(username, k, x_pos_user, cursor_x) cursor_x = x_pos_user + len(username) elif cursor_y == 3: password = inputs.handler(password, k, x_pos_pass, cursor_x) cursor_x = x_pos_pass + len(password)