aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2020-06-01 09:11:02 +0200
committerJoris2020-06-01 09:11:02 +0200
commit3844f76d18e376777ca4d7c124df6d6b4896a361 (patch)
tree425a2380f960f81f929b1b1b6e860bd42626127d
parentadfab777568215d3c72facf07b734c1ff6046d78 (diff)
Separate tasks panel on status
-rw-r--r--src/db/init.py3
-rw-r--r--src/db/tasks.py25
-rw-r--r--src/gui/tags/panel/widget.py7
-rw-r--r--src/gui/tasks/dialog.py5
-rw-r--r--src/gui/tasks/table/menu.py3
-rw-r--r--src/gui/tasks/table/widget.py30
-rw-r--r--src/gui/tasks/widget.py14
-rw-r--r--src/gui/window.py7
-rw-r--r--src/model/difficulty.py2
-rw-r--r--src/model/status.py30
-rw-r--r--src/service/tasks.py9
11 files changed, 98 insertions, 37 deletions
diff --git a/src/db/init.py b/src/db/init.py
index 77920cf..5d847a3 100644
--- a/src/db/init.py
+++ b/src/db/init.py
@@ -21,7 +21,8 @@ def init(path):
" duration INTEGER,"
" difficulty INT,"
" priority INT,"
- " description TEXT"
+ " description TEXT,"
+ " status TEXT"
" )")
cursor.execute(
diff --git a/src/db/tasks.py b/src/db/tasks.py
index 142abae..dca7710 100644
--- a/src/db/tasks.py
+++ b/src/db/tasks.py
@@ -3,8 +3,10 @@ import time
from typing import List
from model.task import Task, ValidTaskForm
+from model.status import Status
+from model import difficulty, priority, status
-def get(cursor: Cursor) -> List[Task]:
+def get(cursor: Cursor, s: Status) -> List[Task]:
cursor.execute(
" SELECT"
" id,"
@@ -15,7 +17,11 @@ def get(cursor: Cursor) -> List[Task]:
" difficulty,"
" priority,"
" description"
- " FROM tasks")
+ " FROM"
+ " tasks"
+ " WHERE"
+ " status = ?",
+ (status.format(s),))
res = []
@@ -26,14 +32,14 @@ def get(cursor: Cursor) -> List[Task]:
updated_at = task[2],
name = task[3],
duration = task[4],
- difficulty = task[5],
- priority = task[6],
+ difficulty = difficulty.parse(task[5]),
+ priority = priority.parse(task[6]),
description = task[7]
))
return res
-def insert(cursor: Cursor, form: ValidTaskForm):
+def insert(cursor: Cursor, s: Status, form: ValidTaskForm):
now = int(time.time())
cursor.execute(
" INSERT INTO tasks("
@@ -43,9 +49,10 @@ def insert(cursor: Cursor, form: ValidTaskForm):
" duration,"
" difficulty,"
" priority,"
- " description"
- " ) VALUES (?, ?, ?, ?, ?, ?, ?)",
- (now, now, form.name, form.duration, int(form.difficulty), int(form.priority), form.description))
+ " description,"
+ " status"
+ " ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+ (now, now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, status.format(s)))
return Task(
id = cursor.lastrowid,
@@ -70,7 +77,7 @@ def update(cursor: Cursor, task: Task, form: ValidTaskForm):
" priority = ?,"
" description = ?"
" WHERE id = ?",
- (now, form.name, form.duration, int(form.difficulty), int(form.priority), form.description, task.id))
+ (now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, task.id))
return Task(
id = task.id,
diff --git a/src/gui/tags/panel/widget.py b/src/gui/tags/panel/widget.py
index fb51385..faca1da 100644
--- a/src/gui/tags/panel/widget.py
+++ b/src/gui/tags/panel/widget.py
@@ -11,14 +11,19 @@ def widget(parent):
layout = QtWidgets.QVBoxLayout(widget)
widget.setLayout(layout)
+ layout.addSpacing(15)
+
add_tag_signal = gui.tags.panel.signal.AddTag()
- add_tag_button = QtWidgets.QPushButton("Add a tag", widget)
+ add_tag_button = QtWidgets.QPushButton(" Add a tag", widget)
+ add_tag_button.setFixedHeight(30)
add_tag_button.setIcon(gui.icon.new_folder(widget.style()))
add_tag_button.clicked.connect(lambda: gui.tags.panel.dialog.add(widget, add_tag_signal).exec_())
layout.addWidget(add_tag_button)
+ layout.addSpacing(20)
+
table = gui.tags.panel.table.widget.Widget(widget, add_tag_signal)
layout.addWidget(table)
diff --git a/src/gui/tasks/dialog.py b/src/gui/tasks/dialog.py
index 1471910..3233dd6 100644
--- a/src/gui/tasks/dialog.py
+++ b/src/gui/tasks/dialog.py
@@ -3,16 +3,17 @@ from typing import List
from model.tag import Tag
from model.task import Task, ValidTaskForm
+from model.status import Status
import database
import db.task_tags
import db.tasks
import gui.tasks.form.widget
import service.tasks
-def add(parent_widget, add_task_signal):
+def add(parent_widget, status: Status, add_task_signal):
def on_add(task_form: ValidTaskForm):
- task = service.tasks.create(database.cursor(), task_form)
+ task = service.tasks.create(database.cursor(), status, task_form)
add_task_signal.emit(task, task_form.tags)
return widget(parent_widget, "Add a task", "add", None, [], on_add)
diff --git a/src/gui/tasks/table/menu.py b/src/gui/tasks/table/menu.py
index db89551..0ad9857 100644
--- a/src/gui/tasks/table/menu.py
+++ b/src/gui/tasks/table/menu.py
@@ -3,10 +3,11 @@ from typing import List
import db.tasks
import gui.tasks.dialog
+from model.status import Status
from model.task import Task, ValidTaskForm
from model.tag import Tag
-def open(table, update_task_signal, position):
+def open(table: QtWidgets.QTableWidget, status: Status, update_task_signal, position):
rows = set([index.row() for index in table.selectedIndexes()])
menu = QtWidgets.QMenu(table)
diff --git a/src/gui/tasks/table/widget.py b/src/gui/tasks/table/widget.py
index 2f3328b..14806fa 100644
--- a/src/gui/tasks/table/widget.py
+++ b/src/gui/tasks/table/widget.py
@@ -10,6 +10,7 @@ from model.priority import Priority
from model.tag import Tag
from model.task import Task
from model.task_tag import TaskTag
+from model.status import Status
import database
import db.tags
import db.task_tags
@@ -29,10 +30,11 @@ class Widget(QtWidgets.QTableWidget):
self,
parent,
on_show: gui.signal.Reload,
- add_task_signal: gui.tasks.signal.AddTask):
+ add_task_signal: gui.tasks.signal.AddTask,
+ status: Status):
super().__init__(parent)
- self.init_state()
+ self.init_state(status)
self.sort()
self.setSelectionBehavior(QtWidgets.QTableView.SelectRows)
@@ -46,27 +48,23 @@ class Widget(QtWidgets.QTableWidget):
# Menu
self.setContextMenuPolicy(Qt.CustomContextMenu)
- self.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(self, self._update_task_signal, position))
+ self.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(self, status, self._update_task_signal, position))
self.doubleClicked.connect(lambda index: self.on_double_click(index.row()))
add_task_signal.connect(lambda task, tags: self.insert(task, tags))
self._update_task_signal.connect(lambda row, task, tags: self.update_task(row, task, tags))
on_show.connect(lambda: self.on_show())
- def on_show(self):
- self._tags = db.tags.get(database.cursor())
- self.update_view()
-
- def init_state(self):
+ def init_state(self, status: Status):
self._update_task_signal = gui.tasks.signal.UpdateTask()
cursor = database.cursor()
- self._tasks = service.tasks.get(cursor)
+ self._status = status
+ self._tasks = service.tasks.get(cursor, self._status)
self._task_tags = db.task_tags.get(cursor)
self._tags = db.tags.get(cursor)
self._sort_column = 0
self._sort_is_ascending = True
-
def init_header(self):
self._header_view = QtWidgets.QHeaderView(Qt.Horizontal, self)
self._header_model = QtGui.QStandardItemModel()
@@ -75,7 +73,15 @@ class Widget(QtWidgets.QTableWidget):
self._header_view.setSectionsClickable(True)
self._header_view.sectionClicked.connect(self.on_header_click)
self.setHorizontalHeader(self._header_view)
- # header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
+
+ def on_show(self):
+ cursor = database.cursor()
+ self._tasks = service.tasks.get(cursor, self._status)
+ self._task_tags = db.task_tags.get(cursor)
+ self._tags = db.tags.get(cursor)
+ self.setRowCount(len(self._tasks))
+ self.sort()
+ self.update_view()
def on_header_click(self, column):
if self._sort_column == column:
@@ -138,6 +144,7 @@ class Widget(QtWidgets.QTableWidget):
self.insertRow(row)
self.update_row(row)
self._task_tags += [TaskTag(task_id=task.id, tag_id=tag_id) for tag_id in tags]
+ self.setRowCount(len(self._tasks))
return row
def is_reversed(self) -> bool:
@@ -189,6 +196,7 @@ class Widget(QtWidgets.QTableWidget):
self._task_tags = [tt for tt in self._task_tags if tt.task_id in [t.id for t in self._tasks]]
for row in sorted(rows, reverse=True):
self.removeRow(row)
+ self.setRowCount(len(self._tasks))
def get_selected_rows(self):
return list(set([index.row() for index in self.selectedIndexes()]))
diff --git a/src/gui/tasks/widget.py b/src/gui/tasks/widget.py
index 3134124..87b15d3 100644
--- a/src/gui/tasks/widget.py
+++ b/src/gui/tasks/widget.py
@@ -1,24 +1,30 @@
from PyQt5 import QtWidgets
+from model.status import Status
import gui.tasks.signal
import gui.tasks.table.widget
import gui.icon
import gui.signal
-def widget(parent, on_show: gui.signal.Reload):
+def widget(parent, on_show: gui.signal.Reload, status: Status):
widget = QtWidgets.QWidget(parent)
layout = QtWidgets.QVBoxLayout(widget)
widget.setLayout(layout)
+ layout.addSpacing(15)
+
add_task_signal = gui.tasks.signal.AddTask()
- add_task_button = QtWidgets.QPushButton("Add a task", widget)
+ add_task_button = QtWidgets.QPushButton(" Add a task", widget)
+ add_task_button.setFixedHeight(30)
add_task_button.setIcon(gui.icon.new_folder(widget.style()))
- add_task_button.clicked.connect(lambda: gui.tasks.dialog.add(widget, add_task_signal).exec_())
+ add_task_button.clicked.connect(lambda: gui.tasks.dialog.add(widget, status, add_task_signal).exec_())
layout.addWidget(add_task_button)
- table = gui.tasks.table.widget.Widget(widget, on_show, add_task_signal)
+ layout.addSpacing(20)
+
+ table = gui.tasks.table.widget.Widget(widget, on_show, add_task_signal, status)
layout.addWidget(table)
return widget
diff --git a/src/gui/window.py b/src/gui/window.py
index efacfd4..35670c7 100644
--- a/src/gui/window.py
+++ b/src/gui/window.py
@@ -4,6 +4,7 @@ import gui.tasks.widget
import gui.tasks.widget
import gui.tags.panel.widget
import gui.signal
+from model.status import Status
def get():
window = QtWidgets.QMainWindow()
@@ -27,9 +28,9 @@ def get():
tabs.currentChanged.connect(on_current_tab_changed)
- tabs.addTab(gui.tasks.widget.widget(tabs, show_todo), "Todo")
- tabs.addTab(gui.tasks.widget.widget(tabs, show_waiting), "Waiting")
- tabs.addTab(gui.tasks.widget.widget(tabs, show_maybe), "Maybe")
+ tabs.addTab(gui.tasks.widget.widget(tabs, show_todo, Status.READY), "Todo")
+ tabs.addTab(gui.tasks.widget.widget(tabs, show_waiting, Status.WAITING), "Waiting")
+ tabs.addTab(gui.tasks.widget.widget(tabs, show_maybe, Status.MAYBE), "Maybe")
tabs.addTab(gui.tags.panel.widget.widget(tabs), "Tags")
return window
diff --git a/src/model/difficulty.py b/src/model/difficulty.py
index e38f19b..526cdb9 100644
--- a/src/model/difficulty.py
+++ b/src/model/difficulty.py
@@ -23,7 +23,7 @@ def parse(string: str) -> Optional[Difficulty]:
if string == "Easy":
return Difficulty.EASY
elif string == "Normal":
- return Difficulty.MIDDLE
+ return Difficulty.NORMAL
elif string == "Hard":
return Difficulty.HARD
else:
diff --git a/src/model/status.py b/src/model/status.py
new file mode 100644
index 0000000..6881e0a
--- /dev/null
+++ b/src/model/status.py
@@ -0,0 +1,30 @@
+from enum import IntEnum
+from typing import Optional
+
+class Status(IntEnum):
+ READY = 0
+ WAITING = 1
+ MAYBE = 2
+
+values = [
+ Status.READY,
+ Status.WAITING,
+ Status.MAYBE]
+
+def format(status: Status) -> str:
+ if status == Status.READY:
+ return "Ready"
+ elif status == Status.WAITING:
+ return "Waiting"
+ elif status == Status.MAYBE:
+ return "Maybe"
+
+def parse(string: str) -> Optional[Status]:
+ if string == "Ready":
+ return Status.READY
+ elif string == "Waiting":
+ return Status.WAITING
+ elif string == "Maybe":
+ return Status.MAYBE
+ else:
+ return None
diff --git a/src/service/tasks.py b/src/service/tasks.py
index 870002a..0dfe94f 100644
--- a/src/service/tasks.py
+++ b/src/service/tasks.py
@@ -1,15 +1,16 @@
from typing import List
from model.task import Task, ValidTaskForm
+from model.status import Status
import db.tasks
import db.task_tags
import database
-def get(cursor) -> List[Task]:
- return db.tasks.get(cursor)
+def get(cursor, status: Status) -> List[Task]:
+ return db.tasks.get(cursor, status)
-def create(cursor, task_form: ValidTaskForm) -> Task:
- task = db.tasks.insert(cursor, task_form)
+def create(cursor, status: Status, task_form: ValidTaskForm) -> Task:
+ task = db.tasks.insert(cursor, status, task_form)
db.task_tags.insert_many(cursor, task.id, task_form.tags)
database.commit()
return task