added properly displaying no projects

This commit is contained in:
Sem van der Hoeven
2020-08-30 17:24:22 +02:00
parent 0be3814fc6
commit 136c493de1

View File

@@ -31,8 +31,6 @@ statuses = [STATUS_WORKING, STATUS_IDLE, STATUS_DONE, 0]
# TODO add controls for adding projects, tasks and deleting # TODO add controls for adding projects, tasks and deleting
# TODO add deleting of projects
# TODO add deleting of tasks
""" """
COLOR_BLACK COLOR_BLACK
@@ -242,9 +240,7 @@ def create_project(projects: list, stdscr):
if k == 10: if k == 10:
if si == 1: if si == 1:
# selected yes # selected yes
temp = Project(project_name) projects.append(Project(project_name))
temp.addTask(Task("New task", ""))
projects.append(temp)
window.clear() window.clear()
scr2.clear() scr2.clear()
@@ -345,48 +341,58 @@ def draw_instructions(stdscr):
def draw_projects(stdscr, projects: list, idx: int, selected_window): def draw_projects(stdscr, projects: list, idx: int, selected_window):
# draw projects if len(projects) != 0:
y = 1 # draw projects
for project_index, project in enumerate(projects): y = 1
if project_index == idx: for project_index, project in enumerate(projects):
if SelectedWindow(selected_window) == SelectedWindow.PROJECTS: if project_index == idx:
stdscr.addstr(y, 0, project.title, curses.A_REVERSE) if SelectedWindow(selected_window) == SelectedWindow.PROJECTS:
stdscr.addstr(y, 0, project.title, curses.A_REVERSE)
else:
stdscr.addstr(y, 0, "-- " + project.title)
else: else:
stdscr.addstr(y, 0, "-- " + project.title) stdscr.addstr(y, 0, project.title)
y = y + 1
else:
stdscr.addstr(1, menu_width//2 - len("NO PROJECTS")//2, "NO PROJECTS", curses.color_pair(WHITE_MAGENTA))
text = "Press 'p' to add a new project"
if len(text) > menu_width:
stdscr.addstr(2, 0, text[: (menu_width - 1)])
stdscr.addstr(3,0,text[(menu_width-1):])
else: else:
stdscr.addstr(y, 0, project.title) stdscr.addstr(2, 0, text)
y = y + 1
def draw_tasks(stdscr, projects, project_index, selected_window, idx): def draw_tasks(stdscr, projects, project_index, selected_window, idx):
h, w = stdscr.getmaxyx() h, w = stdscr.getmaxyx()
width = w//2 - menu_width if len(projects) != 0:
width = w//2 - menu_width
tasks = projects[project_index].tasks tasks = projects[project_index].tasks
if len(tasks) != 0: if len(tasks) != 0:
# draw task names # draw task names
y = 1 y = 1
for i, task in enumerate(tasks): for i, task in enumerate(tasks):
stdscr.attron(curses.color_pair(statuses[task.status.value])) stdscr.attron(curses.color_pair(statuses[task.status.value]))
stdscr.addstr(y, menu_width+1, " " * (width-1)) stdscr.addstr(y, menu_width+1, " " * (width-1))
if i == idx and SelectedWindow(selected_window) == SelectedWindow.TASKS: if i == idx and SelectedWindow(selected_window) == SelectedWindow.TASKS:
stdscr.addstr(y, menu_width + 1, task.title, curses.A_REVERSE) stdscr.addstr(y, menu_width + 1, task.title, curses.A_REVERSE)
else: else:
stdscr.addstr(y, menu_width + 1, task.title) stdscr.addstr(y, menu_width + 1, task.title)
if task.status != Status.NONE: if task.status != Status.NONE:
stdscr.addstr(y, menu_width + width - stdscr.addstr(y, menu_width + width -
len(task.status.name), task.status.name) len(task.status.name), task.status.name)
stdscr.attroff(curses.color_pair(statuses[task.status.value])) stdscr.attroff(curses.color_pair(statuses[task.status.value]))
y = y + 1 y = y + 1
else:
stdscr.addstr(1, menu_width + 1 + width//2 - len("NO TASKS")//2, "NO TASKS", curses.color_pair(WHITE_MAGENTA))
text = "Press 't' to add a new task"
if len(text) > width:
stdscr.addstr(2, menu_width + 1, text[: (width - 1)])
stdscr.addstr(3,menu_width+1,text[(width-1):])
else: else:
stdscr.addstr(2, menu_width + 1, text) stdscr.addstr(1, menu_width + 1 + width//2 - len("NO TASKS")//2, "NO TASKS", curses.color_pair(WHITE_MAGENTA))
text = "Press 't' to add a new task"
if len(text) > width:
stdscr.addstr(2, menu_width + 1, text[: (width - 1)])
stdscr.addstr(3,menu_width+1,text[(width-1):])
else:
stdscr.addstr(2, menu_width + 1, text)
def draw_description(projects, stdscr, project_index,task_index, selected_window): def draw_description(projects, stdscr, project_index,task_index, selected_window):
@@ -517,6 +523,7 @@ def draw_layout(stdscr):
"ENTER - Edit selected task's description") "ENTER - Edit selected task's description")
def draw_sections(stdscr, projects: list, project_index: int,task_index: int,selected_window: int): def draw_sections(stdscr, projects: list, project_index: int,task_index: int,selected_window: int):
stdscr.clear()
draw_layout(stdscr) draw_layout(stdscr)
draw_projects(stdscr, projects, project_index, selected_window) draw_projects(stdscr, projects, project_index, selected_window)
@@ -634,8 +641,7 @@ def main(stdscr):
if newp: if newp:
create_project(projects, stdscr) create_project(projects, stdscr)
newp = False newp = False
draw_sections(stdscr, projects, project_index, task_index, selected_window)
draw_sections(stdscr,projects,project_index,task_index,selected_window)
if newt: if newt:
create_task(projects[project_index], stdscr) create_task(projects[project_index], stdscr)