Skip to content

Commit

Permalink
#2 add option to remove special days
Browse files Browse the repository at this point in the history
  • Loading branch information
rohankishore authored Jun 14, 2024
1 parent e243e9c commit 9673ae0
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions tempus/Calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ def initUI(self, date, festivals):
mark_remainder_button.clicked.connect(self.add_remainder)
mark_remainder_button.setText("Add Reminder 🎗️")

mark_special_button = PushButton()
mark_special_button.setText("Mark as Special ✨")
mark_special_button.clicked.connect(self.mark_special)
self.mark_special_button = PushButton()
self.mark_special_button.setText("Mark as Special ✨")
self.mark_special_button.clicked.connect(self.mark_special)

vbox.addWidget(festival_label, alignment=Qt.AlignmentFlag.AlignTop)
hbox.addWidget(add_todo_button, alignment=Qt.AlignmentFlag.AlignTop)
hbox.addWidget(mark_remainder_button, alignment=Qt.AlignmentFlag.AlignTop)
vbox.addWidget(mark_special_button)
vbox.addWidget(self.mark_special_button)

if festivals:
for festival in festivals:
Expand Down Expand Up @@ -227,6 +227,11 @@ def mark_special(self):
dialog = SpecialDateDialog(self.date)
dialog.exec()

def clear_special_date(self):
y = SpecialDateDialog(self.date)
y.hide()
y.clear_special_date()


class ReminderDialog(QDialog):
def __init__(self, date):
Expand Down Expand Up @@ -359,6 +364,7 @@ def remove_reminder_from_database(self, reminder_id):
self.cursor.execute('DELETE FROM reminders WHERE id = ?', (reminder_id,))
self.conn.commit()


class SpecialDateDialog(QDialog):
def __init__(self, date):
super().__init__()
Expand All @@ -368,15 +374,8 @@ def __init__(self, date):
self.conn = sqlite3.connect('resources/misc/special_dates.db')
self.cursor = self.conn.cursor()

# Create a table to store special dates
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS special_dates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT,
reason TEXT
)
''')
self.conn.commit()
# Create a table to store special dates if not exists
self.create_special_dates_table()

# Set up the dialog layout
self.setWindowTitle(f"Special Date: {self.date}")
Expand All @@ -391,16 +390,37 @@ def __init__(self, date):

# Create the save button
self.save_button = PushButton()
self.save_button.setIcon(FluentIcon.SAVE)
self.save_button.setText("Save")
self.layout.addWidget(self.save_button)

# Connect the button's clicked signal to the save_special_date method
# Create the clear button
self.clear_button = PushButton()

self.cursor.execute('SELECT reason FROM special_dates WHERE date = ?', (self.date,))
result = self.cursor.fetchone()
if result:
self.clear_button.setText("Unmark as Special")
self.layout.addWidget(self.clear_button)
else:
self.clear_button.hide()

# Connect button signals to methods
self.save_button.clicked.connect(self.save_special_date)
self.clear_button.clicked.connect(self.clear_special_date)

# Load existing special date if any
self.load_special_date()

def create_special_dates_table(self):
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS special_dates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT,
reason TEXT
)
''')
self.conn.commit()

def load_special_date(self):
self.cursor.execute('SELECT reason FROM special_dates WHERE date = ?', (self.date,))
result = self.cursor.fetchone()
Expand All @@ -414,6 +434,11 @@ def save_special_date(self):
self.conn.commit()
self.close()

def clear_special_date(self):
self.cursor.execute('DELETE FROM special_dates WHERE date = ?', (self.date,))
self.conn.commit()
self.reason_input.clear()


class Calendar(QCalendarWidget):
def __init__(self):
Expand Down

0 comments on commit 9673ae0

Please sign in to comment.