From 03622462d2168a6b2c0af2774e592b35484bf85e Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 12:36:23 -0300 Subject: [PATCH 01/16] Added newly created ui.py --- ui.py | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 ui.py diff --git a/ui.py b/ui.py new file mode 100644 index 0000000..5319a19 --- /dev/null +++ b/ui.py @@ -0,0 +1,145 @@ +import curses +from functools import reduce + +def debug(): + curses.nocbreak() + #self.screen.keypad(0) + curses.echo() + curses.endwin() + breakpoint() + +class UI(object): + + GENRE_SEPARATE = 2 + + def __init__(self, screen): + self.screen = screen + self.y_limit, self.x_limit = screen.getmaxyx() + self.x_center = self.x_limit // 2 + + def generate_genres(self): + old_lst = self.max_albums(Get.genre_list, self.x_limit) + lst = list() + + i, j, b = 0, 0, False + while i < len(old_lst) - 1: + b = not b + + if b: + lst.append(old_lst[j]) + j += 1 + else: + lst.insert(0, old_lst[-j]) + + i += 1 + + return lst + + def max_albums(self, lst, max): + stop = 0 + + for i, item in enumerate(lst): + if i < len(lst) - 1 and \ + stop + len(lst[i + 1]) >= max: + return lst[:i + 1] + else: + stop += len(item) + self.GENRE_SEPARATE + + return lst + + def center_str(self, str): + return self.x_center - (len(str) // 2) + + def genres_x(self): + lst = self.max_albums(Get.genre_list, self.x_limit) + + center = self.center_str(lst[0]) + left = center + right = center #+ len(lst[0]) + + lst_width = [center] + new_genre_list = [lst[0]] + lst.pop(0) + + #left, right, center = 0, 0, 0 + + #for i, item in enumerate(lst): + + i, j, b = 0, 0, True + while i < len(lst) - 1: + b = not b + i += 1 + + if b: + right = right + len(lst[j]) + self.GENRE_SEPARATE + + if right >= self.x_limit: + j += 1 + continue + + lst_width.append(right) + new_genre_list.append(lst[j]) + j += 1 + + else: + left = left - len(lst[-j]) - self.GENRE_SEPARATE + if left <= 0: + continue + + lst_width.append(left) + new_genre_list.append(lst[-j]) + + + return zip(lst_width, new_genre_list) + + + + + + + + + def display_genres(self): + #len_genre = 0 + lst_genres = self.genres_x() + #lst_genres = self.generate_genres() + + #debug() + for i, item in lst_genres: + self.screen.addstr(0, i, item, + curses.A_ITALIC) + #len_genre += len(item) + 2 + + def display_albums(self): + max = self.max_albums(Get.album_list, self.y_limit) + + for i, item in enumerate(max): + self.screen.addstr(1 + i, 20, item, curses.A_BLINK) + + #reduce(lambda i, x: x[1] + i if x[1] + i < 30 else x[0], kk, 0) + +class Get: + + #genre_list = ["fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self"] + genre_list = [str(x) for x in range(100, 201)] + album_list = ["fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self"] + + def __init__(self): + pass + + def get_albums(self, url): + pass + +def main(screen): + + menu = UI(screen) + screen.clear() + + menu.display_genres() + menu.display_albums() + + screen.refresh() + screen.getch() + +if __name__ == "__main__": + curses.wrapper(main) \ No newline at end of file From fad358e3cae0f9f1a6e252b25e93efeb7fb26c89 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 14:43:38 -0300 Subject: [PATCH 02/16] Adjust genres list Create max_genres() and alter generate_genres() to adjust genres x axis On branch master Changes to be committed: (use "git restore --staged ..." to unstage) modified: ui.py Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: ui.py Untracked files: (use "git add ..." to include in what will be committed) .swp diff --git a/ui.py b/ui.py index 5319a19..c623eb0 100644 --- a/ui.py +++ b/ui.py @@ -18,23 +18,35 @@ class UI(object): self.x_center = self.x_limit // 2 def generate_genres(self): - old_lst = self.max_albums(Get.genre_list, self.x_limit) - lst = list() + old_lst = self.max_genres(Get.genre_list, self.x_limit) + lst = [(len(old_lst[0]), old_lst[0])] - i, j, b = 0, 0, False - while i < len(old_lst) - 1: - b = not b + for i in range(1, len(old_lst) - 1): + lst.append((len(old_lst[i]) + lst[i - 1][0] + self.GENRE_SEPARATE, + old_lst[i])) - if b: - lst.append(old_lst[j]) - j += 1 - else: - lst.insert(0, old_lst[-j]) - - i += 1 - return lst + """ + Returns a list with all elements that can fit at max x.length of terminal + with index[0] at the middle of the list + """ + def max_genres(self, lst, max): + stop = 0 + index = 0 + + for i, item in enumerate(lst): + if i < len(lst) - 1 and \ + stop + len(lst[i + 1]) + self.GENRE_SEPARATE >= max: + # return lst[:i + 1] + index = i + break + else: + stop += len(item) + self.GENRE_SEPARATE + + #return map(lambda x: (len(x) + self.GENRE_SEPARATE, x), + return lst[-index // 2:] + lst[:index // 2] + def max_albums(self, lst, max): stop = 0 --- ui.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/ui.py b/ui.py index 5319a19..c623eb0 100644 --- a/ui.py +++ b/ui.py @@ -18,23 +18,35 @@ def __init__(self, screen): self.x_center = self.x_limit // 2 def generate_genres(self): - old_lst = self.max_albums(Get.genre_list, self.x_limit) - lst = list() + old_lst = self.max_genres(Get.genre_list, self.x_limit) + lst = [(len(old_lst[0]), old_lst[0])] - i, j, b = 0, 0, False - while i < len(old_lst) - 1: - b = not b + for i in range(1, len(old_lst) - 1): + lst.append((len(old_lst[i]) + lst[i - 1][0] + self.GENRE_SEPARATE, + old_lst[i])) - if b: - lst.append(old_lst[j]) - j += 1 - else: - lst.insert(0, old_lst[-j]) - - i += 1 - return lst + """ + Returns a list with all elements that can fit at max x.length of terminal + with index[0] at the middle of the list + """ + def max_genres(self, lst, max): + stop = 0 + index = 0 + + for i, item in enumerate(lst): + if i < len(lst) - 1 and \ + stop + len(lst[i + 1]) + self.GENRE_SEPARATE >= max: + # return lst[:i + 1] + index = i + break + else: + stop += len(item) + self.GENRE_SEPARATE + + #return map(lambda x: (len(x) + self.GENRE_SEPARATE, x), + return lst[-index // 2:] + lst[:index // 2] + def max_albums(self, lst, max): stop = 0 From ade5f494b954022e8ddd75b04c6af647f18510b9 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 15:26:57 -0300 Subject: [PATCH 03/16] Lint and clean code Also remove unnecessary method --- ui.py | 66 ++++++----------------------------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/ui.py b/ui.py index c623eb0..49b6b16 100644 --- a/ui.py +++ b/ui.py @@ -1,5 +1,6 @@ import curses -from functools import reduce +#from functools import reduce + def debug(): curses.nocbreak() @@ -8,8 +9,8 @@ def debug(): curses.endwin() breakpoint() -class UI(object): +class UI(object): GENRE_SEPARATE = 2 def __init__(self, screen): @@ -62,65 +63,12 @@ def max_albums(self, lst, max): def center_str(self, str): return self.x_center - (len(str) // 2) - def genres_x(self): - lst = self.max_albums(Get.genre_list, self.x_limit) - - center = self.center_str(lst[0]) - left = center - right = center #+ len(lst[0]) - - lst_width = [center] - new_genre_list = [lst[0]] - lst.pop(0) - - #left, right, center = 0, 0, 0 - - #for i, item in enumerate(lst): - - i, j, b = 0, 0, True - while i < len(lst) - 1: - b = not b - i += 1 - - if b: - right = right + len(lst[j]) + self.GENRE_SEPARATE - - if right >= self.x_limit: - j += 1 - continue - - lst_width.append(right) - new_genre_list.append(lst[j]) - j += 1 - - else: - left = left - len(lst[-j]) - self.GENRE_SEPARATE - if left <= 0: - continue - - lst_width.append(left) - new_genre_list.append(lst[-j]) - - - return zip(lst_width, new_genre_list) - - - - - - - - def display_genres(self): - #len_genre = 0 - lst_genres = self.genres_x() - #lst_genres = self.generate_genres() + lst_genres = self.generate_genres() - #debug() for i, item in lst_genres: self.screen.addstr(0, i, item, - curses.A_ITALIC) - #len_genre += len(item) + 2 + curses.A_ITALIC) def display_albums(self): max = self.max_albums(Get.album_list, self.y_limit) @@ -128,8 +76,6 @@ def display_albums(self): for i, item in enumerate(max): self.screen.addstr(1 + i, 20, item, curses.A_BLINK) - #reduce(lambda i, x: x[1] + i if x[1] + i < 30 else x[0], kk, 0) - class Get: #genre_list = ["fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self"] @@ -154,4 +100,4 @@ def main(screen): screen.getch() if __name__ == "__main__": - curses.wrapper(main) \ No newline at end of file + curses.wrapper(main) From d4146d5d00300f308f69f25e26ccb7b96f438a12 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 16:57:37 -0300 Subject: [PATCH 04/16] Change genre list creation Join 2 methods to change creation of list from negative index to 0 --- ui.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/ui.py b/ui.py index 49b6b16..68c43c9 100644 --- a/ui.py +++ b/ui.py @@ -28,6 +28,43 @@ def generate_genres(self): return lst + def create_genres_list(self, lst): + center = self.center_str(lst[0]) + left = center + right = center # + len(lst[0]) + + lst_genres = [(center, lst[0])] + lst.pop(0) + + i, j, stop, b = 0, 0, 0, False + while i < len(lst) - 1: + b = not b + i += 1 + + if b: + right = right + len(lst[j]) + self.GENRE_SEPARATE + + if right >= self.x_limit: + j += 1 + continue + + lst_genres.append((right, lst[j])) + stop += len(lst[j]) + self.GENRE_SEPARATE + j += 1 + + else: + left = left - len(lst[-j]) - self.GENRE_SEPARATE + if left <= 0: + continue + + lst_genres.append((left, lst[-j])) + stop += len(lst[-j]) + self.GENRE_SEPARATE + + if stop >= self.x_limit: + break + + return lst_genres + """ Returns a list with all elements that can fit at max x.length of terminal with index[0] at the middle of the list @@ -64,7 +101,8 @@ def center_str(self, str): return self.x_center - (len(str) // 2) def display_genres(self): - lst_genres = self.generate_genres() + # lst_genres = self.generate_genres() + lst_genres = self.create_genres_list(Get.genre_list) for i, item in lst_genres: self.screen.addstr(0, i, item, @@ -76,18 +114,25 @@ def display_albums(self): for i, item in enumerate(max): self.screen.addstr(1 + i, 20, item, curses.A_BLINK) + def navigate(self, b): + self.position += 1 if b else -1 + + + class Get: - #genre_list = ["fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self"] genre_list = [str(x) for x in range(100, 201)] - album_list = ["fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self", "fuck", "your", "self"] + album_list = ["fuck", "your", "selfffff", "fuck", "your", "self", "fuck", + "your", "self", "fuck", "your", "self", "fuck", "your", + "self"] def __init__(self): pass - + def get_albums(self, url): pass - + + def main(screen): menu = UI(screen) From 58a0a38dcbbba83289bed41bdfd891d94edb3b02 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 17:09:58 -0300 Subject: [PATCH 05/16] Lint and clean code Also remove unnecessary code --- ui.py | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/ui.py b/ui.py index 68c43c9..e5f013c 100644 --- a/ui.py +++ b/ui.py @@ -1,10 +1,10 @@ import curses -#from functools import reduce +# from functools import reduce def debug(): curses.nocbreak() - #self.screen.keypad(0) + # self.screen.keypad(0) curses.echo() curses.endwin() breakpoint() @@ -17,17 +17,12 @@ def __init__(self, screen): self.screen = screen self.y_limit, self.x_limit = screen.getmaxyx() self.x_center = self.x_limit // 2 + self.position = 0 - def generate_genres(self): - old_lst = self.max_genres(Get.genre_list, self.x_limit) - lst = [(len(old_lst[0]), old_lst[0])] - - for i in range(1, len(old_lst) - 1): - lst.append((len(old_lst[i]) + lst[i - 1][0] + self.GENRE_SEPARATE, - old_lst[i])) - - return lst - + """ + Returns a list of tuples with all elements and their lengths that can fit + at max x.length of terminal with index[0] at the middle of the list + """ def create_genres_list(self, lst): center = self.center_str(lst[0]) left = center @@ -65,32 +60,12 @@ def create_genres_list(self, lst): return lst_genres - """ - Returns a list with all elements that can fit at max x.length of terminal - with index[0] at the middle of the list - """ - def max_genres(self, lst, max): - stop = 0 - index = 0 - - for i, item in enumerate(lst): - if i < len(lst) - 1 and \ - stop + len(lst[i + 1]) + self.GENRE_SEPARATE >= max: - # return lst[:i + 1] - index = i - break - else: - stop += len(item) + self.GENRE_SEPARATE - - #return map(lambda x: (len(x) + self.GENRE_SEPARATE, x), - return lst[-index // 2:] + lst[:index // 2] - def max_albums(self, lst, max): stop = 0 for i, item in enumerate(lst): if i < len(lst) - 1 and \ - stop + len(lst[i + 1]) >= max: + stop + len(lst[i + 1]) >= max: return lst[:i + 1] else: stop += len(item) + self.GENRE_SEPARATE @@ -118,7 +93,6 @@ def navigate(self, b): self.position += 1 if b else -1 - class Get: genre_list = [str(x) for x in range(100, 201)] From 5ccdebb3bf1661dec1787724a05a38dde3f0f9f4 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Fri, 5 Jan 2024 19:06:45 -0300 Subject: [PATCH 06/16] Fix genres list rotation order in the UI Fixed problem that would mess the list order when navigating it --- ui.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ui.py b/ui.py index e5f013c..0e3d8de 100644 --- a/ui.py +++ b/ui.py @@ -17,47 +17,50 @@ def __init__(self, screen): self.screen = screen self.y_limit, self.x_limit = screen.getmaxyx() self.x_center = self.x_limit // 2 - self.position = 0 + self.positionx = 0 """ Returns a list of tuples with all elements and their lengths that can fit at max x.length of terminal with index[0] at the middle of the list """ + # TODO: fix list out of range when more than 90 movements in the same direction def create_genres_list(self, lst): - center = self.center_str(lst[0]) + center = self.center_str(lst[self.positionx]) left = center right = center # + len(lst[0]) + left_go = self.positionx - lst_genres = [(center, lst[0])] - lst.pop(0) + lst_genres = [(center, lst[self.positionx])] - i, j, stop, b = 0, 0, 0, False + i, j, stop, b = 0, self.positionx, 0, False while i < len(lst) - 1: b = not b - i += 1 if b: right = right + len(lst[j]) + self.GENRE_SEPARATE if right >= self.x_limit: - j += 1 - continue + break lst_genres.append((right, lst[j])) stop += len(lst[j]) + self.GENRE_SEPARATE j += 1 else: - left = left - len(lst[-j]) - self.GENRE_SEPARATE + left_go -= 1 + left = left - len(lst[left_go]) - self.GENRE_SEPARATE + if left <= 0: - continue + break - lst_genres.append((left, lst[-j])) - stop += len(lst[-j]) + self.GENRE_SEPARATE + lst_genres.append((left, lst[left_go])) + stop += len(lst[left_go]) + self.GENRE_SEPARATE if stop >= self.x_limit: break + i += 1 + return lst_genres def max_albums(self, lst, max): @@ -76,8 +79,10 @@ def center_str(self, str): return self.x_center - (len(str) // 2) def display_genres(self): - # lst_genres = self.generate_genres() lst_genres = self.create_genres_list(Get.genre_list) + self.screen.addstr(0, lst_genres[0][0], lst_genres[0][1], + curses.A_REVERSE) + lst_genres.pop(0) for i, item in lst_genres: self.screen.addstr(0, i, item, From 4a2107de8633d55b16e833995690e141bae0970b Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Mon, 8 Jan 2024 14:50:34 -0300 Subject: [PATCH 07/16] Create simple navigation for albums in y axis Change album_list and create navigation in y axis for albums --- ui.py | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/ui.py b/ui.py index 0e3d8de..b9c44d4 100644 --- a/ui.py +++ b/ui.py @@ -1,4 +1,6 @@ import curses +import string +import random as rd # from functools import reduce @@ -18,12 +20,16 @@ def __init__(self, screen): self.y_limit, self.x_limit = screen.getmaxyx() self.x_center = self.x_limit // 2 self.positionx = 0 + self.positiony = 0 + self.genres_height = 0 + self.albums_height = 2 """ Returns a list of tuples with all elements and their lengths that can fit at max x.length of terminal with index[0] at the middle of the list """ - # TODO: fix list out of range when more than 90 movements in the same direction + # TODO: fix list out of range when more than 90 movements in the same + # direction def create_genres_list(self, lst): center = self.center_str(lst[self.positionx]) left = center @@ -94,16 +100,24 @@ def display_albums(self): for i, item in enumerate(max): self.screen.addstr(1 + i, 20, item, curses.A_BLINK) - def navigate(self, b): - self.position += 1 if b else -1 + def navigatey(self, b): + self.positionx += 1 if b else -1 + self.display_ui() + + def display_ui(self): + self.screen.refresh() + self.display_genres() + self.display_albums() class Get: genre_list = [str(x) for x in range(100, 201)] - album_list = ["fuck", "your", "selfffff", "fuck", "your", "self", "fuck", - "your", "self", "fuck", "your", "self", "fuck", "your", - "self"] + #album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] + # for x in range(0, rd.randint(15, 30))] + album_list = [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] + for x in range(0, rd.randint(15, 30))]) + for x in range(30)] def __init__(self): pass @@ -120,8 +134,23 @@ def main(screen): menu.display_genres() menu.display_albums() + while True: + screen.refresh() + key = screen.getch() + + if key == curses.KEY_ENTER: + break + elif key == curses.KEY_RIGHT: + menu.navigatey(True) + elif key == curses.KEY_LEFT: + menu.navigatey(False) + elif key == curses.KEY_UP: + menu.navigatey(False) + elif key == curses.KEY_DOWN: + menu.navigatey(True) + screen.refresh() - screen.getch() + if __name__ == "__main__": curses.wrapper(main) From 72bacf63e16e06ee2012bdd2fe3e20171f4d2e2d Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Thu, 11 Jan 2024 23:36:02 -0300 Subject: [PATCH 08/16] Cycle album list on y axis create_albums_list() created to cycle the list, but needs more work on it --- ui.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/ui.py b/ui.py index b9c44d4..402b659 100644 --- a/ui.py +++ b/ui.py @@ -21,9 +21,12 @@ def __init__(self, screen): self.x_center = self.x_limit // 2 self.positionx = 0 self.positiony = 0 + self.old_positiony = 0 self.genres_height = 0 self.albums_height = 2 + self.last_lst = Get.album_list + """ Returns a list of tuples with all elements and their lengths that can fit at max x.length of terminal with index[0] at the middle of the list @@ -69,6 +72,28 @@ def create_genres_list(self, lst): return lst_genres + def create_albums_list(self, lst): + limit = self.y_limit - self.albums_height - 1 + test = self.positiony - self.old_positiony + 1 + + if test > limit: + self.old_positiony = self.positiony + + if self.old_positiony < 0 and self.positiony < 0: + self.last_lst = lst[self.old_positiony - 1:] + lst[:self.old_positiony] + + elif self.positiony < 0: + self.last_lst = lst[self.positiony:] + lst[:self.positiony] + + elif self.positiony < self.old_positiony: + self.last_lst + + elif self.positiony > limit: + self.old_positiony = self.positiony + self.last_lst = lst[self.positiony - limit:] + lst[:self.positiony - limit] + + return self.last_lst + def max_albums(self, lst, max): stop = 0 @@ -95,17 +120,59 @@ def display_genres(self): curses.A_ITALIC) def display_albums(self): - max = self.max_albums(Get.album_list, self.y_limit) + lst_albums = self.create_albums_list(Get.album_list) + self.screen.addstr(0, 0, str(self.positiony)) + self.screen.addstr(1, 0, str(self.old_positiony)) + self.screen.addstr(2, 0, str(self.positiony - self.old_positiony + 1)) + self.screen.addstr(3, 0, str(self.y_limit)) + self.screen.addstr(4, 0, str(self.albums_height)) + k = False + test = self.positiony - self.old_positiony + 1 + + for i, item in enumerate(lst_albums): + if i == self.y_limit - self.albums_height: + break - for i, item in enumerate(max): - self.screen.addstr(1 + i, 20, item, curses.A_BLINK) + if not k and \ + ((i == self.positiony and (self.positiony >= 0 + and self.old_positiony >= 0)) or + (i == ((self.y_limit - self.albums_height) - + (self.old_positiony - self.positiony)) and + self.old_positiony > self.positiony > 0) or + + (i == test and self.old_positiony < 0) or + #i == (self.old_positiony + self.old_positiony < 0 + #(i == ) + + (self.positiony < 0 and i == 0 and test < 0)): + + self.screen.addstr(self.albums_height + i, + self.center_str(item), item, + curses.A_BLINK | curses.A_REVERSE) + k = True + continue + + self.screen.addstr(self.albums_height + i, + self.center_str(item), item, curses.A_BOLD) + + def navigatex(self, b): + self.positionx += 1 if b else -1 + self.display_ui() def navigatey(self, b): - self.positionx += 1 if b else -1 + if not b and self.positiony < 0 and self.positiony < self.old_positiony: + self.old_positiony = self.positiony + #elif b and self.positiony > 0 + self.positiony += 1 if b else -1 + + #if self.positiony >= 0: + # self.old_positiony = 0 + self.display_ui() def display_ui(self): self.screen.refresh() + self.screen.clear() self.display_genres() self.display_albums() @@ -115,9 +182,10 @@ class Get: genre_list = [str(x) for x in range(100, 201)] #album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] # for x in range(0, rd.randint(15, 30))] - album_list = [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] + album_list = [str(i) + " " + x for i, x in enumerate( + [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] for x in range(0, rd.randint(15, 30))]) - for x in range(30)] + for x in range(30)])] def __init__(self): pass From bfbc515668dbfb200879ab13f7d79ce626c2e634 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Mon, 29 Jan 2024 15:54:54 -0300 Subject: [PATCH 09/16] Create navigation with keyboard characters --- ui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui.py b/ui.py index 402b659..d4bc569 100644 --- a/ui.py +++ b/ui.py @@ -206,15 +206,15 @@ def main(screen): screen.refresh() key = screen.getch() - if key == curses.KEY_ENTER: + if key == ord('q'): break elif key == curses.KEY_RIGHT: menu.navigatey(True) elif key == curses.KEY_LEFT: menu.navigatey(False) - elif key == curses.KEY_UP: + elif key in [curses.KEY_UP, ord('k')]: menu.navigatey(False) - elif key == curses.KEY_DOWN: + elif key in [curses.KEY_DOWN, ord('j')]: menu.navigatey(True) screen.refresh() From 286a66a2c77432e99cb48160c656556abb7e0bc6 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Mon, 29 Jan 2024 16:30:02 -0300 Subject: [PATCH 10/16] Be smart and change y movement to a deque --- ui.py | 80 ++++++++++++++--------------------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/ui.py b/ui.py index d4bc569..8723150 100644 --- a/ui.py +++ b/ui.py @@ -1,6 +1,7 @@ import curses import string import random as rd +from collections import deque # from functools import reduce @@ -20,12 +21,12 @@ def __init__(self, screen): self.y_limit, self.x_limit = screen.getmaxyx() self.x_center = self.x_limit // 2 self.positionx = 0 - self.positiony = 0 - self.old_positiony = 0 self.genres_height = 0 self.albums_height = 2 + self.last_movement = None + self.y_index = 0 - self.last_lst = Get.album_list + self.dq = deque(Get.album_list) """ Returns a list of tuples with all elements and their lengths that can fit @@ -72,39 +73,20 @@ def create_genres_list(self, lst): return lst_genres - def create_albums_list(self, lst): + def move_albums_list(self): limit = self.y_limit - self.albums_height - 1 - test = self.positiony - self.old_positiony + 1 - if test > limit: - self.old_positiony = self.positiony - - if self.old_positiony < 0 and self.positiony < 0: - self.last_lst = lst[self.old_positiony - 1:] + lst[:self.old_positiony] - - elif self.positiony < 0: - self.last_lst = lst[self.positiony:] + lst[:self.positiony] - - elif self.positiony < self.old_positiony: - self.last_lst - - elif self.positiony > limit: - self.old_positiony = self.positiony - self.last_lst = lst[self.positiony - limit:] + lst[:self.positiony - limit] - - return self.last_lst - - def max_albums(self, lst, max): - stop = 0 - - for i, item in enumerate(lst): - if i < len(lst) - 1 and \ - stop + len(lst[i + 1]) >= max: - return lst[:i + 1] + if self.last_movement is True: + if self.y_index == limit: + self.dq.rotate(-1) else: - stop += len(item) + self.GENRE_SEPARATE + self.y_index += 1 - return lst + elif self.last_movement is False: + if self.y_index == 0: + self.dq.rotate(1) + elif self.y_index != 0: + self.y_index -= 1 def center_str(self, str): return self.x_center - (len(str) // 2) @@ -120,36 +102,17 @@ def display_genres(self): curses.A_ITALIC) def display_albums(self): - lst_albums = self.create_albums_list(Get.album_list) - self.screen.addstr(0, 0, str(self.positiony)) - self.screen.addstr(1, 0, str(self.old_positiony)) - self.screen.addstr(2, 0, str(self.positiony - self.old_positiony + 1)) - self.screen.addstr(3, 0, str(self.y_limit)) - self.screen.addstr(4, 0, str(self.albums_height)) - k = False - test = self.positiony - self.old_positiony + 1 + self.move_albums_list() + lst_albums = self.dq for i, item in enumerate(lst_albums): if i == self.y_limit - self.albums_height: break - if not k and \ - ((i == self.positiony and (self.positiony >= 0 - and self.old_positiony >= 0)) or - (i == ((self.y_limit - self.albums_height) - - (self.old_positiony - self.positiony)) and - self.old_positiony > self.positiony > 0) or - - (i == test and self.old_positiony < 0) or - #i == (self.old_positiony + self.old_positiony < 0 - #(i == ) - - (self.positiony < 0 and i == 0 and test < 0)): - + if self.y_index == i: self.screen.addstr(self.albums_height + i, self.center_str(item), item, curses.A_BLINK | curses.A_REVERSE) - k = True continue self.screen.addstr(self.albums_height + i, @@ -160,14 +123,7 @@ def navigatex(self, b): self.display_ui() def navigatey(self, b): - if not b and self.positiony < 0 and self.positiony < self.old_positiony: - self.old_positiony = self.positiony - #elif b and self.positiony > 0 - self.positiony += 1 if b else -1 - - #if self.positiony >= 0: - # self.old_positiony = 0 - + self.last_movement = True if b else False self.display_ui() def display_ui(self): From 0d0a13024bd7aecc244fd35f4957e00968d477f8 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Mon, 29 Jan 2024 17:07:13 -0300 Subject: [PATCH 11/16] Improve axis movement and display_ui() management Integrated both axis movement, and display_ui() is now responsible for displaying, lol --- ui.py | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/ui.py b/ui.py index 8723150..30dc644 100644 --- a/ui.py +++ b/ui.py @@ -25,8 +25,9 @@ def __init__(self, screen): self.albums_height = 2 self.last_movement = None self.y_index = 0 + self.last_axis = '' - self.dq = deque(Get.album_list) + self.dq = deque(Get.get_albums()) """ Returns a list of tuples with all elements and their lengths that can fit @@ -101,8 +102,9 @@ def display_genres(self): self.screen.addstr(0, i, item, curses.A_ITALIC) - def display_albums(self): - self.move_albums_list() + def display_albums(self, move=False): + if move: + self.move_albums_list() lst_albums = self.dq for i, item in enumerate(lst_albums): @@ -118,36 +120,46 @@ def display_albums(self): self.screen.addstr(self.albums_height + i, self.center_str(item), item, curses.A_BOLD) - def navigatex(self, b): + def x_navigate(self, b): + self.last_axis = 'x' self.positionx += 1 if b else -1 self.display_ui() - def navigatey(self, b): + def y_navigate(self, b): + self.last_axis = 'y' self.last_movement = True if b else False self.display_ui() def display_ui(self): self.screen.refresh() self.screen.clear() + + if self.last_axis == 'y': + self.display_albums(True) + + elif self.last_axis == 'x': + self.dq = deque(Get.get_albums()) + self.y_index = 0 + self.display_albums() + self.display_genres() - self.display_albums() class Get: genre_list = [str(x) for x in range(100, 201)] - #album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] - # for x in range(0, rd.randint(15, 30))] - album_list = [str(i) + " " + x for i, x in enumerate( - [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] - for x in range(0, rd.randint(15, 30))]) - for x in range(30)])] + # album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] + # for x in range(0, rd.randint(15, 30))] def __init__(self): pass - def get_albums(self, url): - pass + @staticmethod + def get_albums(): + return [str(i) + " " + x for i, x in enumerate( + [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] + for x in range(0, rd.randint(15, 30))]) + for x in range(30)])] def main(screen): @@ -164,14 +176,14 @@ def main(screen): if key == ord('q'): break - elif key == curses.KEY_RIGHT: - menu.navigatey(True) - elif key == curses.KEY_LEFT: - menu.navigatey(False) + elif key in [curses.KEY_RIGHT, ord('h')]: + menu.x_navigate(True) + elif key in [curses.KEY_LEFT, ord('l')]: + menu.x_navigate(False) elif key in [curses.KEY_UP, ord('k')]: - menu.navigatey(False) + menu.y_navigate(False) elif key in [curses.KEY_DOWN, ord('j')]: - menu.navigatey(True) + menu.y_navigate(True) screen.refresh() From 279bab4095d3ceb4a557ad89e4f41198246f987d Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Mon, 29 Jan 2024 21:05:24 -0300 Subject: [PATCH 12/16] Improve x axis moves, changing to dequeue too Using dequeue to cycle genres and changed how display() works --- ui.py | 107 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 48 insertions(+), 59 deletions(-) diff --git a/ui.py b/ui.py index 30dc644..3ea258e 100644 --- a/ui.py +++ b/ui.py @@ -2,7 +2,7 @@ import string import random as rd from collections import deque -# from functools import reduce +from itertools import islice def debug(): @@ -20,14 +20,14 @@ def __init__(self, screen): self.screen = screen self.y_limit, self.x_limit = screen.getmaxyx() self.x_center = self.x_limit // 2 - self.positionx = 0 self.genres_height = 0 self.albums_height = 2 self.last_movement = None self.y_index = 0 self.last_axis = '' - self.dq = deque(Get.get_albums()) + self.dq_album = deque(Get.get_albums()) + self.dq_genre = deque(Get.genre_list) """ Returns a list of tuples with all elements and their lengths that can fit @@ -35,77 +35,67 @@ def __init__(self, screen): """ # TODO: fix list out of range when more than 90 movements in the same # direction - def create_genres_list(self, lst): - center = self.center_str(lst[self.positionx]) - left = center - right = center # + len(lst[0]) - left_go = self.positionx - - lst_genres = [(center, lst[self.positionx])] - - i, j, stop, b = 0, self.positionx, 0, False - while i < len(lst) - 1: - b = not b - - if b: - right = right + len(lst[j]) + self.GENRE_SEPARATE - - if right >= self.x_limit: - break - - lst_genres.append((right, lst[j])) - stop += len(lst[j]) + self.GENRE_SEPARATE - j += 1 + def move_genres_list(self, move=False): + if move: + if self.last_movement: + self.dq_genre.rotate(-1) else: - left_go -= 1 - left = left - len(lst[left_go]) - self.GENRE_SEPARATE + self.dq_genre.rotate(1) - if left <= 0: - break + count = 0 + i, j = 0, 0 + dq_middle = int(len(self.dq_genre) / 2) - lst_genres.append((left, lst[left_go])) - stop += len(lst[left_go]) + self.GENRE_SEPARATE + for i, j in enumerate(range(dq_middle, len(self.dq_genre)), 1): + count += self.GENRE_SEPARATE * 2 - if stop >= self.x_limit: + if (count + len(self.dq_genre[dq_middle - i]) + + len(self.dq_genre[j])) < self.x_limit: + count += len(self.dq_genre[dq_middle - i]) + \ + len(self.dq_genre[j]) + else: break - i += 1 - - return lst_genres + return deque(islice(self.dq_genre, dq_middle - i, j)) def move_albums_list(self): limit = self.y_limit - self.albums_height - 1 - if self.last_movement is True: + if self.last_movement: if self.y_index == limit: - self.dq.rotate(-1) + self.dq_album.rotate(-1) else: self.y_index += 1 - elif self.last_movement is False: + elif not self.last_movement: if self.y_index == 0: - self.dq.rotate(1) + self.dq_album.rotate(1) elif self.y_index != 0: self.y_index -= 1 def center_str(self, str): return self.x_center - (len(str) // 2) - def display_genres(self): - lst_genres = self.create_genres_list(Get.genre_list) - self.screen.addstr(0, lst_genres[0][0], lst_genres[0][1], - curses.A_REVERSE) - lst_genres.pop(0) + def display_genres(self, move=False): + lst_genres = self.move_genres_list(move) - for i, item in lst_genres: - self.screen.addstr(0, i, item, - curses.A_ITALIC) + # TODO: padding around the dq_genres + len_total = 0 # max(self.x_limit - sum(map(len, lst_genres)), 0) // 2 + for i, item in enumerate(lst_genres): + if i == len(lst_genres) // 2 + 1: + self.screen.addstr(0, len_total, item, + curses.A_REVERSE) + else: + self.screen.addstr(0, len_total, item, + curses.A_ITALIC) + + len_total += len(item) + 2 def display_albums(self, move=False): if move: self.move_albums_list() - lst_albums = self.dq + lst_albums = self.dq_album for i, item in enumerate(lst_albums): if i == self.y_limit - self.albums_height: @@ -115,14 +105,13 @@ def display_albums(self, move=False): self.screen.addstr(self.albums_height + i, self.center_str(item), item, curses.A_BLINK | curses.A_REVERSE) - continue - - self.screen.addstr(self.albums_height + i, - self.center_str(item), item, curses.A_BOLD) + else: + self.screen.addstr(self.albums_height + i, + self.center_str(item), item, curses.A_BOLD) def x_navigate(self, b): self.last_axis = 'x' - self.positionx += 1 if b else -1 + self.last_movement = True if b else False self.display_ui() def y_navigate(self, b): @@ -136,18 +125,18 @@ def display_ui(self): if self.last_axis == 'y': self.display_albums(True) + self.display_genres() elif self.last_axis == 'x': - self.dq = deque(Get.get_albums()) + self.dq_album = deque(Get.get_albums()) self.y_index = 0 self.display_albums() - - self.display_genres() + self.display_genres(True) class Get: - genre_list = [str(x) for x in range(100, 201)] + genre_list = [str(x) for x in range(1000, 1050)] # album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] # for x in range(0, rd.randint(15, 30))] @@ -157,9 +146,9 @@ def __init__(self): @staticmethod def get_albums(): return [str(i) + " " + x for i, x in enumerate( - [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] - for x in range(0, rd.randint(15, 30))]) - for x in range(30)])] + [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] + for x in range(0, rd.randint(15, 30))]) + for x in range(30)])] def main(screen): From bd777dcea6d144d490fd51fa341c5ffbccdec70b Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Tue, 30 Jan 2024 08:47:35 -0300 Subject: [PATCH 13/16] Fix centering of genres list --- ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui.py b/ui.py index 3ea258e..228e224 100644 --- a/ui.py +++ b/ui.py @@ -83,7 +83,7 @@ def display_genres(self, move=False): # TODO: padding around the dq_genres len_total = 0 # max(self.x_limit - sum(map(len, lst_genres)), 0) // 2 for i, item in enumerate(lst_genres): - if i == len(lst_genres) // 2 + 1: + if i == int(len(lst_genres) / 2): self.screen.addstr(0, len_total, item, curses.A_REVERSE) else: From 27195acf89c1c0804e2abb8f83b42d677949b467 Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Tue, 30 Jan 2024 09:46:52 -0300 Subject: [PATCH 14/16] Document UI class and its methods --- ui.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/ui.py b/ui.py index 228e224..c99e896 100644 --- a/ui.py +++ b/ui.py @@ -14,6 +14,26 @@ def debug(): class UI(object): + """ + Used to interact and manage the UI elements of the curses library + + Attr: + y_limit, x_limit : int + the limits of the terminal in each axis + x_center : int + the center position of the x axis of the terminal in session + genres_height : int + position where genres will be written over the x axis + albums_height : int + position where albums will start being written over the y axis + last_movement : bool + True if last movement was down or right, and False if left or up + y_index : int + current position of the album displayed in screen, never going + below 0, or above x_limit + last_axis : str + 'x' or 'y', to indicate the last axis moved + """ GENRE_SEPARATE = 2 def __init__(self, screen): @@ -29,14 +49,17 @@ def __init__(self, screen): self.dq_album = deque(Get.get_albums()) self.dq_genre = deque(Get.genre_list) - """ - Returns a list of tuples with all elements and their lengths that can fit - at max x.length of terminal with index[0] at the middle of the list - """ - # TODO: fix list out of range when more than 90 movements in the same - # direction def move_genres_list(self, move=False): + """ + Return a deque with less numbers of elements than x_limit + Get the middle index of the deque, and looking ahead and behind it, + get the length of the maximum range of elements, (i, j), that can + fit inside x_limit. Then return a isliced deque with odd number of + elements + + move -- True if x axis movement was executed + """ if move: if self.last_movement: self.dq_genre.rotate(-1) @@ -60,6 +83,9 @@ def move_genres_list(self, move=False): return deque(islice(self.dq_genre, dq_middle - i, j)) def move_albums_list(self): + """Rotate deque if y_index is equal to 0 or limit, otherwise + increment y_index + """ limit = self.y_limit - self.albums_height - 1 if self.last_movement: @@ -74,25 +100,47 @@ def move_albums_list(self): elif self.y_index != 0: self.y_index -= 1 + # TODO: create center_deque method? def center_str(self, str): + """Center the string in the x axis center""" return self.x_center - (len(str) // 2) def display_genres(self, move=False): + """ + Write the elements of lst_genres on the screen + + Write the elements of lst_genres on the screen height = genres_height, + and as lst_genres has an odd number of elements, write the middle one + differently + + move --True if the last user movement was on the x axis, to rotate + the deque in move_genres_list(), otherwise just generate the list + """ + lst_genres = self.move_genres_list(move) # TODO: padding around the dq_genres len_total = 0 # max(self.x_limit - sum(map(len, lst_genres)), 0) // 2 for i, item in enumerate(lst_genres): if i == int(len(lst_genres) / 2): - self.screen.addstr(0, len_total, item, + self.screen.addstr(self.genres_height, len_total, item, curses.A_REVERSE) else: - self.screen.addstr(0, len_total, item, + self.screen.addstr(self.genres_height, len_total, item, curses.A_ITALIC) len_total += len(item) + 2 def display_albums(self, move=False): + """ + Write the elements of lst_albums along the y axis + + Write the elements of lst_albums along the y axis starting from + albums_height, and making the index == y_index one blinking + + move -- True if the last user movement was on the y axis, otherwise + it will change the list of albums being presented + """ if move: self.move_albums_list() lst_albums = self.dq_album From 3bbcdb6b7a3c460f730065bb4c3ddba60aa22c8e Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Tue, 30 Jan 2024 09:55:28 -0300 Subject: [PATCH 15/16] Slightly change movement structure Makes display_ui() sole responsible for handling movement --- ui.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/ui.py b/ui.py index c99e896..ac71a8b 100644 --- a/ui.py +++ b/ui.py @@ -31,8 +31,6 @@ class UI(object): y_index : int current position of the album displayed in screen, never going below 0, or above x_limit - last_axis : str - 'x' or 'y', to indicate the last axis moved """ GENRE_SEPARATE = 2 @@ -44,7 +42,6 @@ def __init__(self, screen): self.albums_height = 2 self.last_movement = None self.y_index = 0 - self.last_axis = '' self.dq_album = deque(Get.get_albums()) self.dq_genre = deque(Get.genre_list) @@ -157,25 +154,23 @@ def display_albums(self, move=False): self.screen.addstr(self.albums_height + i, self.center_str(item), item, curses.A_BOLD) - def x_navigate(self, b): - self.last_axis = 'x' - self.last_movement = True if b else False - self.display_ui() - - def y_navigate(self, b): - self.last_axis = 'y' - self.last_movement = True if b else False - self.display_ui() + def display_ui(self, axis, movement): + """ + Set movement attributes and display albums based on which axis moved - def display_ui(self): + axis -- which axis was moved + movement -- True if down, right and False if up, left + """ self.screen.refresh() self.screen.clear() - if self.last_axis == 'y': + self.last_movement = True if movement else False + + if axis == 'y': self.display_albums(True) self.display_genres() - elif self.last_axis == 'x': + elif axis == 'x': self.dq_album = deque(Get.get_albums()) self.y_index = 0 self.display_albums() @@ -214,13 +209,13 @@ def main(screen): if key == ord('q'): break elif key in [curses.KEY_RIGHT, ord('h')]: - menu.x_navigate(True) + menu.display_ui('x', True) elif key in [curses.KEY_LEFT, ord('l')]: - menu.x_navigate(False) + menu.display_ui('x', False) elif key in [curses.KEY_UP, ord('k')]: - menu.y_navigate(False) + menu.display_ui('y', False) elif key in [curses.KEY_DOWN, ord('j')]: - menu.y_navigate(True) + menu.display_ui('y', True) screen.refresh() From 70232422daff2b281664e4d8ebe193bb5ca79f1e Mon Sep 17 00:00:00 2001 From: vill4lobos Date: Tue, 30 Jan 2024 16:36:49 -0300 Subject: [PATCH 16/16] Get infos by request and sync x and y with dicts Now we call local api, get dict genre:[album] and sync them --- ui.py | 64 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/ui.py b/ui.py index ac71a8b..8a3d2e4 100644 --- a/ui.py +++ b/ui.py @@ -1,8 +1,7 @@ import curses -import string -import random as rd from collections import deque from itertools import islice +import requests def debug(): @@ -42,9 +41,10 @@ def __init__(self, screen): self.albums_height = 2 self.last_movement = None self.y_index = 0 + self.current_genre = '' - self.dq_album = deque(Get.get_albums()) - self.dq_genre = deque(Get.genre_list) + self.dq_genre = deque(Get.get_genres()) + self.dq_album = deque() def move_genres_list(self, move=False): """ @@ -66,19 +66,29 @@ def move_genres_list(self, move=False): count = 0 i, j = 0, 0 dq_middle = int(len(self.dq_genre) / 2) + self.current_genre = self.dq_genre[dq_middle] for i, j in enumerate(range(dq_middle, len(self.dq_genre)), 1): count += self.GENRE_SEPARATE * 2 if (count + len(self.dq_genre[dq_middle - i]) + len(self.dq_genre[j])) < self.x_limit: + count += len(self.dq_genre[dq_middle - i]) + \ len(self.dq_genre[j]) else: break + # TODO: makes any difference which genre comes first? + if dq_middle - i < 0: + return self.dq_genre + # return list(self.dq_genre)[dq_middle + 1:] + \ + # list(self.dq_genre)[:dq_middle + 1] + return deque(islice(self.dq_genre, dq_middle - i, j)) + # TODO: fix movement till x_limit instead of dq_album size, when size + # is less than x_limit def move_albums_list(self): """Rotate deque if y_index is equal to 0 or limit, otherwise increment y_index @@ -97,6 +107,9 @@ def move_albums_list(self): elif self.y_index != 0: self.y_index -= 1 + def change_albums_list(self): + self.dq_album = deque(Get.genres_dct[self.current_genre]) + # TODO: create center_deque method? def center_str(self, str): """Center the string in the x axis center""" @@ -131,7 +144,7 @@ def display_genres(self, move=False): def display_albums(self, move=False): """ Write the elements of lst_albums along the y axis - + Write the elements of lst_albums along the y axis starting from albums_height, and making the index == y_index one blinking @@ -140,9 +153,8 @@ def display_albums(self, move=False): """ if move: self.move_albums_list() - lst_albums = self.dq_album - for i, item in enumerate(lst_albums): + for i, item in enumerate(self.dq_album): if i == self.y_limit - self.albums_height: break @@ -154,7 +166,7 @@ def display_albums(self, move=False): self.screen.addstr(self.albums_height + i, self.center_str(item), item, curses.A_BOLD) - def display_ui(self, axis, movement): + def display_ui(self, axis='', movement=None): """ Set movement attributes and display albums based on which axis moved @@ -164,34 +176,38 @@ def display_ui(self, axis, movement): self.screen.refresh() self.screen.clear() - self.last_movement = True if movement else False + if movement is not None: + self.last_movement = True if movement else False - if axis == 'y': - self.display_albums(True) - self.display_genres() + self.display_genres(True if axis == 'x' else False) - elif axis == 'x': - self.dq_album = deque(Get.get_albums()) + if axis in ['x', '']: + self.change_albums_list() self.y_index = 0 - self.display_albums() - self.display_genres(True) + + self.display_albums(True if axis == 'y' else False) class Get: - genre_list = [str(x) for x in range(1000, 1050)] + genres_dct = {} # album_list = [list(string.ascii_lowercase)[rd.randint(0, 26)] # for x in range(0, rd.randint(15, 30))] def __init__(self): pass + # @staticmethod + # def get_albums(genre): + # return Get.genres_dct[] + @staticmethod - def get_albums(): - return [str(i) + " " + x for i, x in enumerate( - [''.join([list(string.ascii_lowercase)[rd.randint(0, 25)] - for x in range(0, rd.randint(15, 30))]) - for x in range(30)])] + def get_genres(): + + r = requests.get("http://127.0.0.1:5000/all").json() + + Get.genres_dct = r + return r.keys() def main(screen): @@ -199,9 +215,7 @@ def main(screen): menu = UI(screen) screen.clear() - menu.display_genres() - menu.display_albums() - + menu.display_ui() while True: screen.refresh() key = screen.getch()