summaryrefslogtreecommitdiff
path: root/assignment-list.py
diff options
context:
space:
mode:
Diffstat (limited to 'assignment-list.py')
-rwxr-xr-xassignment-list.py111
1 files changed, 72 insertions, 39 deletions
diff --git a/assignment-list.py b/assignment-list.py
index 06fe806..9591155 100755
--- a/assignment-list.py
+++ b/assignment-list.py
@@ -3,7 +3,7 @@ import sys
import time
from PyQt5.QtWidgets import QAction, QApplication, QHBoxLayout, QLabel, QMainWindow, QMessageBox, QPushButton, QToolBar, QVBoxLayout, QWidget
from PyQt5.QtGui import QFont
-from PyQt5.QtCore import Qt
+from PyQt5.QtCore import QDate, QDateTime, Qt
from add_group_form import addGroupForm
from edit_group_form import editGroupForm
from add_entry_form import addEntryForm
@@ -14,6 +14,11 @@ DB = __import__("db_sqlite")
class AssignmentList(QMainWindow):
def __init__(self):
super().__init__()
+
+ # Class globals
+ self.renderGroupButtons = True
+ self.renderEntryButtons = True
+
self.initializeUI()
def initializeUI(self):
@@ -29,6 +34,7 @@ class AssignmentList(QMainWindow):
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu("File")
edit_menu = menu_bar.addMenu("Edit")
+ view_menu = menu_bar.addMenu("View")
help_menu = menu_bar.addMenu("Help")
exit_act = QAction("Exit", self)
@@ -44,6 +50,16 @@ class AssignmentList(QMainWindow):
self.clean_hidden_act.triggered.connect(self.cleanHidden)
edit_menu.addAction(self.clean_hidden_act)
+ self.hide_entry_buttons = QAction("Hide Entry Buttons", self, checkable=True)
+ self.hide_entry_buttons.setShortcut("Ctrl+H")
+ self.hide_entry_buttons.triggered.connect(self.hideEntryButtons)
+ view_menu.addAction(self.hide_entry_buttons)
+ self.hide_group_buttons = QAction("Hide Group Buttons", self, checkable=True)
+ self.hide_group_buttons.setShortcut("Ctrl+Shift+H")
+ self.hide_group_buttons.triggered.connect(self.hideGroupButtons)
+ view_menu.addAction(self.hide_group_buttons)
+
+
about_act = QAction("About", self)
about_act.triggered.connect(self.aboutDialog)
help_menu.addAction(about_act)
@@ -109,6 +125,13 @@ class AssignmentList(QMainWindow):
Globals.groups = list(filter(lambda g: g.id != id, Globals.groups))
self.drawGroups()
+ def hideGroupButtons(self):
+ """
+ Set a flag to avoid rendering buttons under groups
+ """
+ self.renderGroupButtons = not self.renderGroupButtons
+ self.drawGroups()
+
def addEntry(self, parent):
"""
Open the 'addEntry' form
@@ -150,6 +173,13 @@ class AssignmentList(QMainWindow):
Globals.entries = list(filter(lambda e: e.id != id, Globals.entries))
self.drawGroups()
+ def hideEntryButtons(self):
+ """
+ Set a flag to avoid rendering buttons under entries
+ """
+ self.renderEntryButtons = not self.renderEntryButtons
+ self.drawGroups()
+
def cleanHidden(self):
"""
Permanently delete removed groups and entries from db
@@ -176,7 +206,7 @@ class AssignmentList(QMainWindow):
Globals.groups = sorted(Globals.groups, key=lambda g: g.id)
# Sort the entries (by due_date for now)
- Globals.entries = sorted(Globals.entries, key=lambda e: (e.parent_id, e.due, e.id))
+ Globals.entries = sorted(Globals.entries, key=lambda e: (e.parent_id, (e.due if e.due else QDate.currentDate()), e.done, e.id))
# Create columns as vertical boxes
column_left = QVBoxLayout()
@@ -193,25 +223,27 @@ class AssignmentList(QMainWindow):
g_layout.addLayout(self.drawEntries(g.id))
# Include buttons at the bottom to edit the group
- buttons_hbox = QHBoxLayout()
+ if self.renderGroupButtons:
+ buttons_hbox = QHBoxLayout()
- add_entry_button = QPushButton()
- add_entry_button.setText("Add Entry")
- add_entry_button.clicked.connect((lambda id: lambda: self.addEntry(id))(g.id))
- buttons_hbox.addWidget(add_entry_button)
+ add_entry_button = QPushButton()
+ add_entry_button.setText("Add Entry")
+ add_entry_button.clicked.connect((lambda id: lambda: self.addEntry(id))(g.id))
+ buttons_hbox.addWidget(add_entry_button)
- edit_group_button = QPushButton()
- edit_group_button.setText("Edit Group")
- edit_group_button.clicked.connect((lambda id: lambda: self.editGroup(id))(g.id))
- buttons_hbox.addWidget(edit_group_button)
+ edit_group_button = QPushButton()
+ edit_group_button.setText("Edit Group")
+ edit_group_button.clicked.connect((lambda id: lambda: self.editGroup(id))(g.id))
+ buttons_hbox.addWidget(edit_group_button)
- del_group_button = QPushButton()
- del_group_button.setText("Remove Group")
- del_group_button.clicked.connect((lambda id: lambda: self.removeGroup(id))(g.id))
- buttons_hbox.addWidget(del_group_button)
+ del_group_button = QPushButton()
+ del_group_button.setText("Remove Group")
+ del_group_button.clicked.connect((lambda id: lambda: self.removeGroup(id))(g.id))
+ buttons_hbox.addWidget(del_group_button)
+
+ buttons_hbox.addStretch()
+ g_layout.addLayout(buttons_hbox)
- buttons_hbox.addStretch()
- g_layout.addLayout(buttons_hbox)
if g.column.lower() == "left":
column_left.addLayout(g_layout)
else:
@@ -242,28 +274,29 @@ class AssignmentList(QMainWindow):
entries_vbox.addLayout(e.buildLayout())
# entry modifier buttons
- buttons_hbox = QHBoxLayout()
-
- edit_entry_button = QPushButton()
- edit_entry_button.setText("Edit Entry")
- edit_entry_button.clicked.connect((lambda id: lambda: self.editEntry(id))(e.id))
- buttons_hbox.addWidget(edit_entry_button)
-
- mark_done_button = QPushButton()
- if e.done:
- mark_done_button.setText("Not Done")
- else:
- mark_done_button.setText("Done")
- mark_done_button.clicked.connect((lambda id: lambda: self.toggleDoneEntry(id))(e.id))
- buttons_hbox.addWidget(mark_done_button)
-
- del_entry_button = QPushButton()
- del_entry_button.setText("Remove Entry")
- del_entry_button.clicked.connect((lambda id: lambda: self.removeEntry(id))(e.id))
- buttons_hbox.addWidget(del_entry_button)
-
- buttons_hbox.addStretch()
- entries_vbox.addLayout(buttons_hbox)
+ if self.renderEntryButtons:
+ buttons_hbox = QHBoxLayout()
+
+ edit_entry_button = QPushButton()
+ edit_entry_button.setText("Edit Entry")
+ edit_entry_button.clicked.connect((lambda id: lambda: self.editEntry(id))(e.id))
+ buttons_hbox.addWidget(edit_entry_button)
+
+ mark_done_button = QPushButton()
+ if e.done:
+ mark_done_button.setText("Not Done")
+ else:
+ mark_done_button.setText("Done")
+ mark_done_button.clicked.connect((lambda id: lambda: self.toggleDoneEntry(id))(e.id))
+ buttons_hbox.addWidget(mark_done_button)
+
+ del_entry_button = QPushButton()
+ del_entry_button.setText("Remove Entry")
+ del_entry_button.clicked.connect((lambda id: lambda: self.removeEntry(id))(e.id))
+ buttons_hbox.addWidget(del_entry_button)
+
+ buttons_hbox.addStretch()
+ entries_vbox.addLayout(buttons_hbox)
return entries_vbox