Latest working changes
This commit is contained in:
parent
14ec441322
commit
8a67085d5b
@ -15,7 +15,7 @@ requires-python = ">=3.8"
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
|
||||
"Operating System :: OS Independent",
|
||||
"Operating System :: Unix",
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Environment :: Console"
|
||||
]
|
||||
|
@ -2,13 +2,15 @@
|
||||
|
||||
import numpy as np
|
||||
import yaml
|
||||
import os
|
||||
import glob
|
||||
|
||||
|
||||
class Task:
|
||||
""" This class represents each task,
|
||||
"""
|
||||
"""This class represents each task,"""
|
||||
|
||||
def __init__(self, summary, score, description):
|
||||
""" Initialize the task class
|
||||
"""
|
||||
"""Initialize the task class"""
|
||||
# Each task has the following properties
|
||||
self.summary = summary # Summary of the task
|
||||
self.score = score # Score for ticket
|
||||
@ -33,7 +35,6 @@ class Board:
|
||||
if file:
|
||||
self.read_yaml(file)
|
||||
|
||||
|
||||
def read_yaml(self, file):
|
||||
"""Read the yaml file in and set up the data
|
||||
|
||||
@ -42,15 +43,16 @@ class Board:
|
||||
"""
|
||||
|
||||
# Read in the data
|
||||
with open(file, 'r') as f:
|
||||
with open(file, "r") as f:
|
||||
data = yaml.safe_load(f)
|
||||
|
||||
# Assign the data to board variables
|
||||
self.columns = data['columns']
|
||||
self.columns = data["columns"]
|
||||
self.tasks = [[] for col in self.columns]
|
||||
for task in data['tasks']:
|
||||
self.tasks[self.columns.index(task['column'])].append(
|
||||
Task(task['summary'], task['score'], task['description']))
|
||||
for task in data["tasks"]:
|
||||
self.tasks[self.columns.index(task["column"])].append(
|
||||
Task(task["summary"], task["score"], task["description"])
|
||||
)
|
||||
|
||||
def write_yaml(self, file):
|
||||
"""Write the yaml file
|
||||
@ -61,17 +63,22 @@ class Board:
|
||||
|
||||
# Set up data to write out
|
||||
data = dict()
|
||||
data['columns'] = self.columns
|
||||
data['tasks'] = list()
|
||||
data["columns"] = self.columns
|
||||
data["tasks"] = list()
|
||||
for col, task_list in zip(self.columns, self.tasks):
|
||||
for task in task_list:
|
||||
data['tasks'].append({'column':col, 'summary':task.summary, 'score':task.score,
|
||||
'description':task.description})
|
||||
data["tasks"].append(
|
||||
{
|
||||
"column": col,
|
||||
"summary": task.summary,
|
||||
"score": task.score,
|
||||
"description": task.description,
|
||||
}
|
||||
)
|
||||
|
||||
with open(file, 'w') as f:
|
||||
with open(file, "w") as f:
|
||||
yaml.dump(data, f)
|
||||
|
||||
|
||||
def move_task(self, col_index, task_index, direction):
|
||||
"""This class method moves tasks between columns by incrementing/decrementing the column
|
||||
index
|
||||
@ -93,8 +100,6 @@ class Board:
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def print_board_items(self):
|
||||
for i, col in enumerate(self.columns):
|
||||
print(col)
|
||||
@ -123,3 +128,30 @@ class Board:
|
||||
def del_task(self, icol, itask):
|
||||
del self.tasks[icol][itask]
|
||||
|
||||
|
||||
class BoardList:
|
||||
"""This class is used to process the full list of boards"""
|
||||
|
||||
def __init__(self):
|
||||
self.boards = self.get_boards()
|
||||
|
||||
def get_boards(self):
|
||||
"""This function returns the boards that have been created"""
|
||||
configpath = os.path.join(
|
||||
os.environ.get("APPDATA")
|
||||
or os.environ.get("XDG_CONFIG_HOME")
|
||||
or os.path.join(os.environ["HOME"], ".config"),
|
||||
"pykban",
|
||||
)
|
||||
|
||||
boards = list()
|
||||
for board in glob.glob(os.path.join(configpath, "(*.yaml)")):
|
||||
with open(board, "r") as f:
|
||||
data = yaml.safe_load(f)
|
||||
try:
|
||||
boards.append((data["name"], board))
|
||||
except KeyError:
|
||||
print("Board yaml file is missing the name attribute")
|
||||
sys.exit()
|
||||
|
||||
return boards
|
||||
|
@ -19,6 +19,14 @@ EditColScreen {
|
||||
layout: vertical;
|
||||
background: #000000 25%;
|
||||
}
|
||||
|
||||
SelectBoardScreen{
|
||||
align: center middle;
|
||||
overflow-x: hidden;
|
||||
layout: vertical;
|
||||
background: #000000 25%;
|
||||
}
|
||||
|
||||
.column {
|
||||
width: 1fr;
|
||||
height: 100%;
|
||||
|
@ -3,23 +3,26 @@ from textual.widgets import Static, Label, ListItem, ListView, TextArea, Input
|
||||
from textual.containers import Horizontal, Vertical
|
||||
from textual.screen import Screen
|
||||
from textual.binding import Binding
|
||||
from board import Board, Task
|
||||
from .board import Board, Task, BoardList
|
||||
|
||||
|
||||
class TaskList(ListView):
|
||||
"""
|
||||
Inherited widget from Listview to use as the kanban board columns
|
||||
"""
|
||||
|
||||
# Keybinds
|
||||
BINDINGS = [
|
||||
Binding("k", "cursor_up", "Cursor Up", show=False, priority=True),
|
||||
Binding("j", "cursor_down", "Cursor Down", show=False, priority=True),
|
||||
]
|
||||
|
||||
|
||||
class EditTaskScreen(Screen):
|
||||
"""
|
||||
This is a screen used to edit the name of a task
|
||||
"""
|
||||
|
||||
CSS = """
|
||||
Label{
|
||||
width:50%;
|
||||
@ -47,9 +50,10 @@ class EditTaskScreen(Screen):
|
||||
}
|
||||
"""
|
||||
BINDINGS = [
|
||||
Binding('ctrl+s', 'save', 'Save Changes', priority=True),
|
||||
Binding('escape', 'exit', 'Exit Without Changes', priority=True),
|
||||
Binding("ctrl+s", "save", "Save Changes", priority=True),
|
||||
Binding("escape", "exit", "Exit Without Changes", priority=True),
|
||||
]
|
||||
|
||||
def __init__(self, text):
|
||||
"""
|
||||
Initialize the screen
|
||||
@ -61,19 +65,18 @@ class EditTaskScreen(Screen):
|
||||
"""
|
||||
Compose the widgets on the screen, this screen doesn't need dynamic layout changes
|
||||
"""
|
||||
yield Label('Task Name:')
|
||||
yield Label("Task Name:")
|
||||
yield Input(value=self.text.summary)
|
||||
yield Label('Score:')
|
||||
yield Label("Score:")
|
||||
if self.text.score:
|
||||
yield Input(value=self.text.score)
|
||||
else:
|
||||
yield Input(value="")
|
||||
yield Label('Description:')
|
||||
yield Label("Description:")
|
||||
if self.text.description:
|
||||
yield TextArea(self.text.description, language='markdown')
|
||||
yield TextArea(self.text.description, language="markdown")
|
||||
else:
|
||||
yield TextArea(language='markdown')
|
||||
|
||||
yield TextArea(language="markdown")
|
||||
|
||||
def action_save(self):
|
||||
query = self.query(selector=Input)
|
||||
@ -86,10 +89,12 @@ class EditTaskScreen(Screen):
|
||||
def action_exit(self):
|
||||
self.dismiss(None)
|
||||
|
||||
|
||||
class EditColScreen(Screen):
|
||||
"""
|
||||
This is a screen used to edit the name of a task
|
||||
"""
|
||||
|
||||
CSS = """
|
||||
Label{
|
||||
width:50%;
|
||||
@ -104,9 +109,10 @@ class EditColScreen(Screen):
|
||||
}
|
||||
"""
|
||||
BINDINGS = [
|
||||
Binding('ctrl+s', 'save', 'Save Changes', priority=True),
|
||||
Binding('enter', 'save', 'Save Changes', priority=True),
|
||||
Binding("ctrl+s", "save", "Save Changes", priority=True),
|
||||
Binding("enter", "save", "Save Changes", priority=True),
|
||||
]
|
||||
|
||||
def __init__(self, text):
|
||||
"""
|
||||
Initialize the screen
|
||||
@ -118,58 +124,159 @@ class EditColScreen(Screen):
|
||||
"""
|
||||
Compose the widgets on the screen, this screen doesn't need dynamic layout changes
|
||||
"""
|
||||
yield Label('Column Name:')
|
||||
yield Label("Column Name:")
|
||||
yield Input(value=self.text)
|
||||
|
||||
|
||||
def action_save(self):
|
||||
query = self.query(selector=Input)
|
||||
self.dismiss(query.nodes[0].value)
|
||||
|
||||
|
||||
class KanbanForm(App):
|
||||
CSS_PATH = 'layout.tcss'
|
||||
class SelectBoardScreen(Screen):
|
||||
"""This is a screen used to select a board"""
|
||||
|
||||
BINDINGS = [
|
||||
Binding("a", "new_task", "Add New Task", show=False, ),
|
||||
Binding("l", "fnext", "Focus Next", show=False, ),
|
||||
Binding("h", "fprev", "Focus Prev", show=False, ),
|
||||
Binding("enter", "pick_option", "Save Changes", priority=True),
|
||||
Binding("q", "exit", "Exit"),
|
||||
]
|
||||
CSS = """
|
||||
$bg: #282828;
|
||||
Label{
|
||||
width:50%;
|
||||
background: #282828;
|
||||
padding: 0;
|
||||
}
|
||||
TaskList{
|
||||
width:50%;
|
||||
background: #282828;
|
||||
padding: 0 0;
|
||||
border: #ebdbb9;
|
||||
}
|
||||
ListView{
|
||||
width:50%;
|
||||
background: #282828;
|
||||
}
|
||||
ListItem{
|
||||
border: solid #ebdbb2 100%;
|
||||
background: $bg;
|
||||
}
|
||||
|
||||
ListView > ListItem.--highlight {
|
||||
background: $bg;
|
||||
}
|
||||
|
||||
ListView:focus > ListItem.--highlight {
|
||||
background: #458588;
|
||||
}
|
||||
|
||||
Label:focus{
|
||||
background: #458588;
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, logger):
|
||||
"""
|
||||
Initialize the screen
|
||||
"""
|
||||
super().__init__()
|
||||
self.board_list = BoardList()
|
||||
self.logger = logger
|
||||
|
||||
def compose(self):
|
||||
"""
|
||||
Compose the widgets on the screen, this screen doesn't need dynamic layout changes
|
||||
"""
|
||||
yield Label("Select a board:")
|
||||
yield TaskList(
|
||||
*[ListItem(Label(board)) for board in self.board_list.get_boards()],
|
||||
ListItem(Label("Add a new board")),
|
||||
)
|
||||
|
||||
def action_pick_option(self):
|
||||
"""Pick a board from the ListItem"""
|
||||
self.focused.highlighted_child
|
||||
|
||||
|
||||
class MainBoardScreen(Screen):
|
||||
CSS_PATH = "layout.tcss"
|
||||
BINDINGS = [
|
||||
Binding(
|
||||
"a",
|
||||
"new_task",
|
||||
"Add New Task",
|
||||
show=False,
|
||||
),
|
||||
Binding(
|
||||
"l",
|
||||
"fnext",
|
||||
"Focus Next",
|
||||
show=False,
|
||||
),
|
||||
Binding(
|
||||
"h",
|
||||
"fprev",
|
||||
"Focus Prev",
|
||||
show=False,
|
||||
),
|
||||
Binding("L", "move_up", "Focus Next", show=False),
|
||||
Binding("H", "move_down", "Focus Prev", show=False),
|
||||
Binding("e", "edit_task", "Edit Task", show=False,),
|
||||
Binding("r", "edit_column", "Edit Column Name", show=False,),
|
||||
Binding("d", "delete_task", "Delete Task", show=False,),
|
||||
Binding('q', 'exit', "Exit")
|
||||
Binding(
|
||||
"e",
|
||||
"edit_task",
|
||||
"Edit Task",
|
||||
show=False,
|
||||
),
|
||||
Binding(
|
||||
"r",
|
||||
"edit_column",
|
||||
"Edit Column Name",
|
||||
show=False,
|
||||
),
|
||||
Binding(
|
||||
"d",
|
||||
"delete_task",
|
||||
"Delete Task",
|
||||
show=False,
|
||||
),
|
||||
Binding("q", "exit", "Exit"),
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the Kanban Form App"""
|
||||
super().__init__()
|
||||
|
||||
def compose(self):
|
||||
"""
|
||||
Initialization function for form
|
||||
"""
|
||||
# Initialize our board class
|
||||
self.board = Board(file = '.board.yaml')
|
||||
self.board = Board(file=".board.yaml")
|
||||
self.cols = list()
|
||||
|
||||
self.col_widgets = list()
|
||||
|
||||
|
||||
with Horizontal():
|
||||
for i, col in enumerate(self.board.get_columns()):
|
||||
if i < len(self.board.get_columns()) - 1:
|
||||
col_class = 'column'
|
||||
col_class = "column"
|
||||
else:
|
||||
col_class = 'last-column'
|
||||
col_class = "last-column"
|
||||
with Vertical(classes=col_class):
|
||||
if i == 0:
|
||||
yield Static(col, classes='header-focused')
|
||||
yield Static(col, classes="header-focused")
|
||||
else:
|
||||
yield Static(col, classes='header')
|
||||
yield Static(col, classes="header")
|
||||
yield TaskList(
|
||||
*[ListItem(Label(task.summary)) for task in self.board.get_tasks()[i]])
|
||||
*[
|
||||
ListItem(Label(task.summary))
|
||||
for task in self.board.get_tasks()[i]
|
||||
]
|
||||
)
|
||||
|
||||
def action_fnext(self):
|
||||
"""Focus next column"""
|
||||
query = self.query(selector=Static)
|
||||
query = [node for node in query.nodes if str(node) == 'Static()']
|
||||
query = [node for node in query.nodes if str(node) == "Static()"]
|
||||
icol, _ = self.get_col_task()
|
||||
query[icol].classes = "header"
|
||||
self.children[0].focus_next()
|
||||
@ -178,8 +285,6 @@ class KanbanForm(App):
|
||||
except IndexError:
|
||||
query[0].classes = "header-focused"
|
||||
|
||||
|
||||
|
||||
def action_move_up(self):
|
||||
icol, itask = self.get_col_task()
|
||||
text = self.board.get_task(icol, itask).summary
|
||||
@ -192,11 +297,10 @@ class KanbanForm(App):
|
||||
self.action_fnext()
|
||||
self.focused.action_cursor_down()
|
||||
|
||||
|
||||
def action_fprev(self):
|
||||
"""Focus previous column"""
|
||||
query = self.query(selector=Static)
|
||||
query = [node for node in query.nodes if str(node) == 'Static()']
|
||||
query = [node for node in query.nodes if str(node) == "Static()"]
|
||||
icol, _ = self.get_col_task()
|
||||
query[icol].classes = "header"
|
||||
self.children[0].focus_previous()
|
||||
@ -236,18 +340,16 @@ class KanbanForm(App):
|
||||
self.board.del_task(icol, itask)
|
||||
|
||||
def update_col(self, text):
|
||||
""" Update the column
|
||||
"""
|
||||
"""Update the column"""
|
||||
icol, itask = self.get_col_task()
|
||||
query = self.query(selector=Static)
|
||||
query = [node for node in query.nodes if str(node) == 'Static()']
|
||||
query = [node for node in query.nodes if str(node) == "Static()"]
|
||||
query[icol].update(text)
|
||||
self.board.get_columns()[icol] = text
|
||||
|
||||
|
||||
def action_exit(self):
|
||||
"""Exit the application"""
|
||||
self.board.write_yaml(file='.board.yaml')
|
||||
self.board.write_yaml(file=".board.yaml")
|
||||
self.exit()
|
||||
|
||||
def get_col_task(self):
|
||||
@ -283,20 +385,33 @@ class KanbanForm(App):
|
||||
self.board.update_task(icol, itask, task)
|
||||
|
||||
def new_task(self, task):
|
||||
""" This function adds a new task to our board
|
||||
"""
|
||||
"""This function adds a new task to our board"""
|
||||
if task:
|
||||
icol, _ = self.get_col_task()
|
||||
self.focused.mount(ListItem(Label(task.summary)))
|
||||
self.board.add_task(icol, task)
|
||||
self.focused.action_cursor_down()
|
||||
|
||||
|
||||
class KanbanForm(App):
|
||||
"""Main Kanban app"""
|
||||
|
||||
CSS_PATH = "layout.tcss"
|
||||
SCREENS = {"main": SelectBoardScreen()}
|
||||
|
||||
def on_mount(self):
|
||||
self.push_screen("main")
|
||||
|
||||
|
||||
# def on_key(self):
|
||||
# with open('log','a') as f:
|
||||
# f.write("{}".format(self.children[0].focus_next))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def run_tui():
|
||||
kb = KanbanForm()
|
||||
kb.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tui()
|
||||
|
Reference in New Issue
Block a user