added adding of projects

This commit is contained in:
Sem van der Hoeven
2020-08-28 14:35:44 +02:00
parent c17c06565c
commit 55b09e965d

View File

@@ -51,6 +51,8 @@ class Project:
def __init__(self, title: str):
self.title = title
self.tasks = []
self.tasks.append(Task(
"Example task", "Project: " + title + ". This is an example of a task description.\nIt can be used to provide some extra information about the task."))
def addTask(self, task):
self.tasks.append(task)
@@ -89,14 +91,17 @@ class Status(Enum):
print("next is {}".format(Status(v)))
return Status(v)
class SelectedWindow(Enum):
PROJECTS = 1
TASKS = 2
def save(projects: list):
with open(FILENAME, 'wb') as savefile:
pickle.dump(projects, savefile, pickle.HIGHEST_PROTOCOL)
def load():
try:
with open(FILENAME, 'rb') as data:
@@ -104,10 +109,12 @@ def load():
return loaded
except FileNotFoundError as err:
temp_project = Project("Example project")
temp_project.addTask(Task("Example task", "This is an example of a task description.\nIt can be used to provide some extra information about the task."))
temp_project.addTask(Task(
"Example task", "This is an example of a task description.\nIt can be used to provide some extra information about the task."))
return [temp_project]
def create_project(projects: list, stdscr, si: int):
def create_project(projects: list, stdscr):
# TODO create project add window
###########################################################
@@ -119,9 +126,13 @@ def create_project(projects: list, stdscr, si: int):
window = curses.newwin(7, 50, window_y, window_x)
window.clear()
window.border()
window.addstr(0, 5, "ADD PROJECT", curses.color_pair(YELLOW_BLACK) | curses.A_REVERSE)
made_choice = False
window.addstr(0, 5, "ADD PROJECT", curses.color_pair(
YELLOW_BLACK) | curses.A_REVERSE)
window.addstr(2, 1, "Project name:", curses.A_REVERSE)
window.addstr(4,25 - len("Ctrl + G to stop editing")//2,"Ctrl + G to stop editing")
window.addstr(4, 25 - len("Enter to confirm") //
2, "Enter to confirm")
lnstr = len("project name:")
scr2 = curses.newwin(1, 47 - lnstr, window_y + 2, w // 2 - 23 + lnstr)
@@ -131,28 +142,56 @@ def create_project(projects: list, stdscr, si: int):
window.refresh()
textpad = Textbox(scr2, insert_mode=True)
entered = False
project_name = textpad.edit()
project_name = project_name[:-1]
window.addstr(4, 1, " " * 48) # clear the "ctrl g to stop editing" message
# clear the "ctrl g to stop editing" message
window.addstr(4, 1, " " * 48)
text = "Add project: '" + project_name + "'?"
window.addstr(4, 25 - len(text) // 2, text)
si = 1
# highlight the option yes if the selected index = 1, otherwise highlight no
window.addstr(5, 10, "YES", (2097152 << 1) >> (si == 1))
window.addstr(5, 35, "NO", (2097152 << 1) >> (si != 1))
k = 0
while (k != 10):
if k == curses.KEY_RIGHT or k == 454:
si = 2 if si == 1 else 1
elif k == curses.KEY_LEFT or k == 452:
si = 1 if si == 2 else 2
# highlight the option yes if the selected index = 1, otherwise highlight no
window.addstr(5, 10, "YES", (2097152 << 1) >> (si == 1))
window.addstr(5, 35, "NO", (2097152 << 1) >> (si != 1))
window.refresh()
scr2.refresh()
stdscr.refresh()
k = stdscr.getch()
if k == 10:
if si == 1:
# selected yes
projects.append(Project(project_name))
window.clear()
scr2.clear()
scr2.refresh()
window.refresh()
stdscr.refresh()
del scr2
del window
def create_task(project):
# TODO create task add window when add project window is made
pass
def get_x_pos_center(text: str):
return curses.COLS // 2 - len(text) // 2
@@ -293,7 +332,8 @@ def draw_description(projects,stdscr, task, selected_window):
controls, curses.color_pair(WHITE_MAGENTA))
stdscr.hline(instructions_start, controls_start + (w//2)//2 + len(controls)//2+1, curses.ACS_HLINE,
w // 2 - len(controls) // 2, curses.color_pair(MAGENTA_BLACK))
stdscr.addstr(instructions_start + 1, controls_start + 1, "CTRL+G - Stop editing")
stdscr.addstr(instructions_start + 1, controls_start +
1, "CTRL+G - Stop editing")
scr2 = curses.newwin(edit_win_lines, edit_win_cols, 2, w // 2 + 2)
rectangle(stdscr, 1, w//2+1, h - controls_lines-2, w-2)
@@ -319,7 +359,6 @@ def draw_description(projects,stdscr, task, selected_window):
def main(stdscr):
global editing
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_MAGENTA)
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_CYAN)
@@ -336,7 +375,6 @@ def main(stdscr):
project_index = 0
task_index = 0
selected_window = 1
select_index = 2
projects = load()
newp = False # making new project
newt = False # making new task
@@ -371,7 +409,6 @@ def main(stdscr):
task_index = 0
elif k == curses.KEY_RIGHT or k == 454: # right key
if not newp:
selected_window = selected_window + 1
if selected_window > len(SelectedWindow):
selected_window = 1
@@ -381,11 +418,8 @@ def main(stdscr):
# so we don't want the index to be out of bounds
if SelectedWindow(selected_window) == SelectedWindow.PROJECTS:
task_index = 0
else:
select_index = 2 if select_index == 1 else 1
elif k == curses.KEY_LEFT or k == 452: # left key
if not newp:
selected_window = selected_window - 1
if selected_window < 1:
selected_window = len(SelectedWindow)
@@ -395,9 +429,6 @@ def main(stdscr):
# so we don't want the index to be out of bounds
if SelectedWindow(selected_window) == SelectedWindow.PROJECTS:
task_index = 0
else:
select_index = 1 if select_index == 2 else 2
pass
elif k == 32: # space key
if SelectedWindow(selected_window) == SelectedWindow.TASKS:
@@ -418,8 +449,16 @@ def main(stdscr):
draw_instructions(stdscr)
draw_description(
projects, stdscr, projects[project_index].tasks[task_index], selected_window)
if newp:
create_project(projects, stdscr,select_index)
create_project(projects, stdscr)
newp = False
draw_projects(stdscr, projects, project_index, selected_window)
draw_tasks(stdscr, projects[project_index].tasks,
selected_window, task_index)
draw_instructions(stdscr)
draw_description(
projects, stdscr, projects[project_index].tasks[task_index], selected_window)
k = stdscr.getch()
stdscr.refresh()