summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-09-16 09:36:14 -0400
committerLouie S <louie@example.com>2023-09-16 09:36:14 -0400
commitf52c158655f1c8623b7bd73716606e0ea6a7bfaf (patch)
tree5365780295c80b904ed69d7ace2f0fc45dbd30d2
parent12f840536275ccebe2f382fb1ca40019b16b10f6 (diff)
Button toggling
-rwxr-xr-xassignment-list.py111
-rw-r--r--entry.py5
2 files changed, 75 insertions, 41 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
diff --git a/entry.py b/entry.py
index 84af97d..ba393b7 100644
--- a/entry.py
+++ b/entry.py
@@ -18,11 +18,12 @@ class Entry:
bullet = QLabel()
body = QLabel()
+ bullet.setFont(QFont("Arial", 11))
+
body.setTextInteractionFlags(Qt.TextSelectableByMouse)
body.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
-
- bullet.setFont(QFont("Arial", 11))
body.setFont(QFont("Arial", 11))
+ body.setWordWrap(True)
if self.done:
bullet.setText("\u2713 ")