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
commit12f840536275ccebe2f382fb1ca40019b16b10f6 (patch)
tree668884dfc808a0a0dd5d28b57498e816cdd830d0
parent8dbf2bfa796f63ca9628ee3395aaa52af247b7ab (diff)
Optional due date; urls working
-rw-r--r--add_entry_form.py13
-rwxr-xr-xassignment-list.py11
-rw-r--r--db_sqlite.py56
-rw-r--r--edit_entry_form.py24
-rw-r--r--entry.py8
5 files changed, 92 insertions, 20 deletions
diff --git a/add_entry_form.py b/add_entry_form.py
index 87f35db..495d1ab 100644
--- a/add_entry_form.py
+++ b/add_entry_form.py
@@ -1,5 +1,5 @@
import sys
-from PyQt5.QtWidgets import QApplication, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton
+from PyQt5.QtWidgets import QApplication, QCheckBox, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton
from PyQt5.QtGui import QFont
from PyQt5.QtCore import QDate, Qt
from entry import Entry
@@ -28,9 +28,14 @@ class addEntryForm(QDialog):
self.new_entry_desc = QLineEdit()
entry_form_layout.addRow("Description:", self.new_entry_desc)
+ self.due_hbox = QHBoxLayout()
self.new_entry_due = QDateTimeEdit(QDate.currentDate())
self.new_entry_due.setDisplayFormat("MM/dd/yyyy")
- entry_form_layout.addRow("Due Date:", self.new_entry_due)
+ self.due_hbox.addWidget(self.new_entry_due)
+ self.new_entry_due_checkbox = QCheckBox()
+ self.new_entry_due_checkbox.setChecked(True)
+ self.due_hbox.addWidget(self.new_entry_due_checkbox)
+ entry_form_layout.addRow("Due Date:", self.due_hbox)
self.new_entry_due_alt = QLineEdit()
entry_form_layout.addRow("Due Date (Alt):", self.new_entry_due_alt)
@@ -61,7 +66,9 @@ class addEntryForm(QDialog):
def handleSubmit(self, parent):
# Check that the new entry is not blank
desc_text = self.new_entry_desc.text()
- due_text = self.new_entry_due.date() # due_text is a QDate
+ due_text = ""
+ if self.new_entry_due_checkbox.isChecked():
+ due_text = self.new_entry_due.date() # due_text is a QDate
due_alt_text = self.new_entry_due_alt.text()
link_text = self.new_entry_link.text()
diff --git a/assignment-list.py b/assignment-list.py
index 673a209..06fe806 100755
--- a/assignment-list.py
+++ b/assignment-list.py
@@ -39,6 +39,10 @@ class AssignmentList(QMainWindow):
self.add_group_act = QAction("Add Group", self)
self.add_group_act.triggered.connect(self.addGroup)
edit_menu.addAction(self.add_group_act)
+ edit_menu.addSeparator()
+ self.clean_hidden_act = QAction("Permanently Delete Removed Groups and Entries", self)
+ self.clean_hidden_act.triggered.connect(self.cleanHidden)
+ edit_menu.addAction(self.clean_hidden_act)
about_act = QAction("About", self)
about_act.triggered.connect(self.aboutDialog)
@@ -146,6 +150,13 @@ class AssignmentList(QMainWindow):
Globals.entries = list(filter(lambda e: e.id != id, Globals.entries))
self.drawGroups()
+ def cleanHidden(self):
+ """
+ Permanently delete removed groups and entries from db
+ """
+ # TODO consider creating a warning dialogue for this
+ DB.cleanHidden()
+
def drawGroups(self):
"""
Redraw the groups_hbox
diff --git a/db_sqlite.py b/db_sqlite.py
index 4c4cf0d..60c8aa0 100644
--- a/db_sqlite.py
+++ b/db_sqlite.py
@@ -86,13 +86,18 @@ def loadFromTables():
query.exec_("SELECT * FROM entries")
while query.next():
record = query.record()
- due_date_struct = strptime(record.field("due_date").value(), "%Y-%m-%d")
+ # create a QDate if the due date is set
+ if record.field("due_date").value():
+ due_date_struct = strptime(record.field("due_date").value(), "%Y-%m-%d")
+ due_date = QDate(due_date_struct.tm_year, due_date_struct.tm_mon, due_date_struct.tm_mday)
+ else:
+ due_date = ""
Globals.entries.append(
Entry(
record.field("id").value(),
record.field("parent_id").value(),
record.field("description").value(),
- QDate(due_date_struct.tm_year, due_date_struct.tm_mon, due_date_struct.tm_mday),
+ due_date,
record.field("alt_due_date").value(),
record.field("link").value(),
record.field("done").value(),
@@ -149,10 +154,13 @@ def insertEntry(new_entry):
""")
query.bindValue(":p_id", new_entry.parent_id)
query.bindValue(":desc", new_entry.desc)
- query.bindValue(":due", "{0}-{1}-{2}".format(
- new_entry.due.year(),
- new_entry.due.month(),
- new_entry.due.day()))
+ if new_entry.due:
+ query.bindValue(":due", "{0}-{1}-{2}".format(
+ new_entry.due.year(),
+ new_entry.due.month(),
+ new_entry.due.day()))
+ else:
+ query.bindValue(":due", "")
query.bindValue(":alt_due", new_entry.due_alt)
query.bindValue(":link", new_entry.link)
success = query.exec_()
@@ -219,10 +227,13 @@ def updateEntry(entry):
WHERE id = :id
""")
query.bindValue(":desc", entry.desc)
- query.bindValue(":due", "{0}-{1}-{2}".format(
- entry.due.year(),
- entry.due.month(),
- entry.due.day()))
+ if entry.due:
+ query.bindValue(":due", "{0}-{1}-{2}".format(
+ entry.due.year(),
+ entry.due.month(),
+ entry.due.day()))
+ else:
+ query.bindValue(":due", "")
query.bindValue(":alt_due", entry.due_alt)
query.bindValue(":link", entry.link)
query.bindValue(":done", entry.done)
@@ -289,3 +300,28 @@ def removeEntry(entry_id):
output = query.numRowsAffected()
database.close()
return output
+
+def cleanHidden():
+ """
+ Permanently delete removed/hidden groups and entries
+ """
+ database = QSqlDatabase.addDatabase("QSQLITE") # SQlite version 3
+ database.setDatabaseName(Globals.db_path)
+
+ if not database.open():
+ print("Unable to open data source file.")
+ sys.exit(1) # Error out. TODO consider throwing a dialog instead
+
+ query = QSqlQuery()
+
+ # Remove hidden entries
+ query.exec_("""
+ DELETE FROM entries WHERE hidden = 1
+ """)
+
+ # Remove hidden groups
+ query.exec_("""
+ DELETE FROM groups WHERE hidden = 1
+ """)
+
+ database.close()
diff --git a/edit_entry_form.py b/edit_entry_form.py
index 7af95dd..9a30e1e 100644
--- a/edit_entry_form.py
+++ b/edit_entry_form.py
@@ -1,7 +1,7 @@
import sys
-from PyQt5.QtWidgets import QApplication, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton
+from PyQt5.QtWidgets import QApplication, QCheckBox, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton
from PyQt5.QtGui import QFont
-from PyQt5.QtCore import Qt
+from PyQt5.QtCore import QDate, Qt
Globals = __import__("globals")
from entry import Entry
@@ -35,10 +35,19 @@ class editEntryForm(QDialog):
self.entry_desc.setText(entry.desc)
entry_form_layout.addRow("Description:", self.entry_desc)
- self.entry_due = QDateTimeEdit()
+ self.due_hbox = QHBoxLayout()
+ self.entry_due = QDateTimeEdit(QDate.currentDate())
self.entry_due.setDisplayFormat("MM/dd/yyyy")
- self.entry_due.setDate(entry.due)
- entry_form_layout.addRow("Due Date:", self.entry_due)
+ if entry.due:
+ self.entry_due.setDate(entry.due)
+ self.due_hbox.addWidget(self.entry_due)
+ self.entry_due_checkbox = QCheckBox()
+ if entry.due:
+ self.entry_due_checkbox.setChecked(True)
+ else:
+ self.entry_due_checkbox.setChecked(False)
+ self.due_hbox.addWidget(self.entry_due_checkbox)
+ entry_form_layout.addRow("Due Date:", self.due_hbox)
self.entry_due_alt = QLineEdit()
self.entry_due_alt.setText(entry.due_alt)
@@ -65,7 +74,10 @@ class editEntryForm(QDialog):
def handleSubmit(self):
desc_text = self.entry_desc.text()
- due_text = self.entry_due.date() # due_text is a QDate
+ if self.entry_due_checkbox.isChecked():
+ due_text = self.entry_due.date() # due_text is a QDate
+ else:
+ due_text = "" # due is unchecked
due_alt_text = self.entry_due_alt.text()
link_text = self.entry_link.text()
diff --git a/entry.py b/entry.py
index 261a32c..84af97d 100644
--- a/entry.py
+++ b/entry.py
@@ -19,6 +19,7 @@ class Entry:
body = QLabel()
body.setTextInteractionFlags(Qt.TextSelectableByMouse)
+ body.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
bullet.setFont(QFont("Arial", 11))
body.setFont(QFont("Arial", 11))
@@ -29,9 +30,14 @@ class Entry:
bullet.setText("- ")
output.addWidget(bullet)
- if(self.due):
+ if self.due:
body.setText("{0}/{1}/{2}: ".format(self.due.month(), self.due.day(), self.due.year()))
+ if self.link:
+ body.setOpenExternalLinks(True)
+ body.setText(body.text() + "<a href=\"{0}\">".format(self.link))
body.setText(body.text() + self.desc)
+ if self.link:
+ body.setText(body.text() + "</a>")
output.addWidget(body)
output.addStretch()