Add ability to add tasks to board
This commit is contained in:
parent
bb987e2c18
commit
afac87cc49
@ -2,20 +2,17 @@
|
|||||||
|
|
||||||
## To Do
|
## To Do
|
||||||
|
|
||||||
- task 2
|
|
||||||
|
|
||||||
- task 1
|
- Update the task information
|
||||||
|
- Task 2
|
||||||
|
|
||||||
## Review
|
## Review
|
||||||
|
|
||||||
|
|
||||||
- task 4
|
- Task 3
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
|
||||||
|
|
||||||
|
- Task 4
|
||||||
|
|
||||||
- task 3
|
|
||||||
|
|
||||||
|
|
||||||
|
13
src/board.py
13
src/board.py
@ -55,7 +55,7 @@ class Board:
|
|||||||
# Now add the task to the list structures
|
# Now add the task to the list structures
|
||||||
elif item_type == "-":
|
elif item_type == "-":
|
||||||
# The tasks are a list of [col index, task name]
|
# The tasks are a list of [col index, task name]
|
||||||
self.tasks[-1].append(" "+' '.join(line.split(' ')[1:]))
|
self.tasks[-1].append(' '.join(line.split(' ')[1:]).strip())
|
||||||
|
|
||||||
|
|
||||||
def write_md(self):
|
def write_md(self):
|
||||||
@ -64,7 +64,7 @@ class Board:
|
|||||||
for i,col in enumerate(self.columns):
|
for i,col in enumerate(self.columns):
|
||||||
f.write('## {}\n\n'.format(col))
|
f.write('## {}\n\n'.format(col))
|
||||||
for task in self.tasks[i]:
|
for task in self.tasks[i]:
|
||||||
f.write('- {}\n'.format(task[1][1:]))
|
f.write('- {}\n'.format(task))
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
|
||||||
|
|
||||||
@ -107,3 +107,12 @@ class Board:
|
|||||||
def get_task(self, icol, itask):
|
def get_task(self, icol, itask):
|
||||||
""" Return a task based on column and task index"""
|
""" Return a task based on column and task index"""
|
||||||
return self.tasks[icol][itask]
|
return self.tasks[icol][itask]
|
||||||
|
|
||||||
|
def update_task( self, icol, itask, text):
|
||||||
|
""" Update the task based on text """
|
||||||
|
self.tasks[icol][itask] = text
|
||||||
|
|
||||||
|
def add_task( self, icol, text):
|
||||||
|
"""Add a task to icol"""
|
||||||
|
self.tasks[icol].append(text)
|
||||||
|
|
||||||
|
@ -3,6 +3,13 @@ Screen {
|
|||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditScreen {
|
||||||
|
align: center middle;
|
||||||
|
overflow-x: hidden;
|
||||||
|
layout: vertical;
|
||||||
|
background: #282828 50%;
|
||||||
|
}
|
||||||
|
|
||||||
.column {
|
.column {
|
||||||
width: 1fr;
|
width: 1fr;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
74
src/tui.py
74
src/tui.py
@ -1,6 +1,7 @@
|
|||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.widgets import Static, Label, ListItem, ListView
|
from textual.widgets import Static, Label, ListItem, ListView, TextArea, Input
|
||||||
from textual.containers import Horizontal, Vertical
|
from textual.containers import Horizontal, Vertical
|
||||||
|
from textual.screen import Screen
|
||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
from board import Board
|
from board import Board
|
||||||
|
|
||||||
@ -15,15 +16,51 @@ class TaskList(ListView):
|
|||||||
Binding("j", "cursor_down", "Cursor Down", show=False, priority=True),
|
Binding("j", "cursor_down", "Cursor Down", show=False, priority=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class EditScreen(Screen):
|
||||||
|
"""
|
||||||
|
This is a screen used to edit the name of a task
|
||||||
|
"""
|
||||||
|
CSS="""
|
||||||
|
Label{
|
||||||
|
width:50%;
|
||||||
|
}
|
||||||
|
Input{
|
||||||
|
width:50%;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
BINDINGS = [
|
||||||
|
Binding('enter', 'save', 'Save Changes', priority=True)
|
||||||
|
]
|
||||||
|
def __init__(self,text):
|
||||||
|
"""
|
||||||
|
Initialize the screen
|
||||||
|
"""
|
||||||
|
super().__init__()
|
||||||
|
self.text = text
|
||||||
|
|
||||||
|
def compose(self):
|
||||||
|
"""
|
||||||
|
Compose the widgets on the screen, this screen doesn't need dynamic layout changes
|
||||||
|
"""
|
||||||
|
yield Label('Task Name:')
|
||||||
|
yield Input(value=self.text)
|
||||||
|
|
||||||
|
|
||||||
|
def action_save(self):
|
||||||
|
query = self.query(selector=Input)
|
||||||
|
self.dismiss(query.nodes[0].value)
|
||||||
|
|
||||||
|
|
||||||
class KanbanForm(App):
|
class KanbanForm(App):
|
||||||
CSS_PATH = 'layout.tcss'
|
CSS_PATH = 'layout.tcss'
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
Binding("l", "fnext", "Focus Next", show=False, priority=True),
|
Binding("l", "fnext", "Focus Next", show=False, ),
|
||||||
Binding("h", "fprev", "Focus Prev", show=False, priority=True),
|
Binding("a", "new_task", "Add New Task", show=False, ),
|
||||||
Binding("L", "move_up", "Focus Next", show=False, priority=True),
|
Binding("h", "fprev", "Focus Prev", show=False, ),
|
||||||
Binding("H", "move_down", "Focus Prev", show=False, priority=True),
|
Binding("L", "move_up", "Focus Next", show=False),
|
||||||
Binding('q', 'exit', "Exit", priority=True, show=False)
|
Binding("H", "move_down", "Focus Prev", show=False),
|
||||||
|
Binding("e", "edit_task", "Edit Task", show=False,),
|
||||||
|
Binding('q', 'exit', "Exit")
|
||||||
]
|
]
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
@ -82,8 +119,17 @@ class KanbanForm(App):
|
|||||||
self.action_fprev()
|
self.action_fprev()
|
||||||
self.focused.action_cursor_down()
|
self.focused.action_cursor_down()
|
||||||
|
|
||||||
|
def action_edit_task(self):
|
||||||
|
icol, itask = self.get_col_task()
|
||||||
|
task = self.board.get_task(icol, itask)
|
||||||
|
self.push_screen(EditScreen(task), self.update_task)
|
||||||
|
|
||||||
|
def action_new_task(self):
|
||||||
|
self.push_screen(EditScreen(""), self.new_task)
|
||||||
|
|
||||||
def action_exit(self):
|
def action_exit(self):
|
||||||
""" Exit the application """
|
""" Exit the application """
|
||||||
|
self.board.write_md()
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
def get_col_task(self):
|
def get_col_task(self):
|
||||||
@ -107,6 +153,22 @@ class KanbanForm(App):
|
|||||||
|
|
||||||
return col_index, task_index
|
return col_index, task_index
|
||||||
|
|
||||||
|
def update_task(self, text):
|
||||||
|
""" This function gets the text inputted in the edit screen and updates the underlying
|
||||||
|
task and the board class
|
||||||
|
|
||||||
|
"""
|
||||||
|
icol, itask = self.get_col_task()
|
||||||
|
self.focused.highlighted_child.children[0].update(text)
|
||||||
|
self.board.update_task(icol, itask, text)
|
||||||
|
|
||||||
|
def new_task(self, text):
|
||||||
|
""" This function adds a new task to our board
|
||||||
|
"""
|
||||||
|
icol,_ = self.get_col_task()
|
||||||
|
self.focused.mount(ListItem(Label(text)))
|
||||||
|
self.board.add_task(icol, text)
|
||||||
|
self.focused.highlighted_child
|
||||||
|
|
||||||
# def on_key(self):
|
# def on_key(self):
|
||||||
# with open('log','a') as f:
|
# with open('log','a') as f:
|
||||||
|
Reference in New Issue
Block a user