From c0206bd626123976a2584f7e6c9d485029fd8350 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 25 Nov 2025 15:43:22 +1100 Subject: [PATCH] Remove old alarm logic --- bouquin/locales/en.json | 1 - bouquin/main_window.py | 51 +---------------------------------- bouquin/markdown_editor.py | 30 --------------------- tests/test_markdown_editor.py | 43 ----------------------------- 4 files changed, 1 insertion(+), 124 deletions(-) diff --git a/bouquin/locales/en.json b/bouquin/locales/en.json index d6e7ad7..d8b428d 100644 --- a/bouquin/locales/en.json +++ b/bouquin/locales/en.json @@ -172,7 +172,6 @@ "send": "Send", "reminder": "Reminder", "set_reminder": "Set reminder prompt", - "set_reminder_prompt": "Enter a time", "reminder_no_text_fallback": "You scheduled a reminder to alert you now!", "invalid_time_title": "Invalid time", "invalid_time_message": "Please enter a time in the format HH:MM", diff --git a/bouquin/main_window.py b/bouquin/main_window.py index 17683db..3fb1195 100644 --- a/bouquin/main_window.py +++ b/bouquin/main_window.py @@ -44,7 +44,6 @@ from PySide6.QtWidgets import ( QTabWidget, QVBoxLayout, QWidget, - QInputDialog, QLabel, QPushButton, QApplication, @@ -1195,55 +1194,7 @@ class MainWindow(QMainWindow): # ----------- Alarms handler ------------# def _on_alarm_requested(self): - """Create a one-shot reminder based on the current line in the editor.""" - editor = getattr(self, "editor", None) - if editor is None: - return - - # Use the current line in the markdown editor as the reminder text - try: - editor.get_current_line_text().strip() - except AttributeError: - c = editor.textCursor() - c.block().text().strip() - - # Ask user for a time today in HH:MM format - time_str, ok = QInputDialog.getText( - self, - strings._("set_reminder"), - strings._("set_reminder_prompt") + " (HH:MM)", - ) - if not ok or not time_str.strip(): - return - - try: - hour, minute = map(int, time_str.strip().split(":", 1)) - except ValueError: - QMessageBox.warning( - self, - strings._("invalid_time_title"), - strings._("invalid_time_message"), - ) - return - - t = QTime(hour, minute) - if not t.isValid(): - QMessageBox.warning( - self, - strings._("invalid_time_title"), - strings._("invalid_time_message"), - ) - return - - # Normalise to HH:MM - time_str = f"{t.hour():02d}:{t.minute():02d}" - - # Insert / update ⏰ in the editor text - if hasattr(editor, "insert_alarm_marker"): - editor.insert_alarm_marker(time_str) - - # Rebuild timers, but only if this page is for "today" - self._rebuild_reminders_for_today() + self.upcoming_reminders._add_reminder() def _on_timer_requested(self): """Start a Pomodoro timer for the current line.""" diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index 994ff45..c5efa74 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -420,36 +420,6 @@ class MarkdownEditor(QTextEdit): cursor.setPosition(match.end(), QTextCursor.MoveMode.KeepAnchor) cursor.insertImage(img_format) - def insert_alarm_marker(self, time_str: str) -> None: - """ - Append or replace an ⏰ HH:MM marker on the current line. - time_str is expected to be 'HH:MM'. - """ - cursor = self.textCursor() - block = cursor.block() - line = block.text() - - # Strip any existing ⏰ HH:MM at the end of the line - new_line = re.sub(r"\s*⏰\s*\d{1,2}:\d{2}\s*$", "", line).rstrip() - - # Append the new marker - new_line = f"{new_line} ⏰ {time_str}" - - # --- : only replace the block's text, not its newline --- - block_start = block.position() - block_end = block_start + len(line) - - bc = QTextCursor(self.document()) - bc.beginEditBlock() - bc.setPosition(block_start) - bc.setPosition(block_end, QTextCursor.KeepAnchor) - bc.insertText(new_line) - bc.endEditBlock() - - # Move cursor to end of the edited line - cursor.setPosition(block.position() + len(new_line)) - self.setTextCursor(cursor) - def _get_current_line(self) -> str: """Get the text of the current line.""" cursor = self.textCursor() diff --git a/tests/test_markdown_editor.py b/tests/test_markdown_editor.py index 8097a2e..043a33f 100644 --- a/tests/test_markdown_editor.py +++ b/tests/test_markdown_editor.py @@ -1783,34 +1783,6 @@ def test_backspace_on_empty_checkbox_removes_marker(qtbot, editor): assert editor._CHECK_UNCHECKED_DISPLAY not in editor.toPlainText() -def test_insert_alarm_marker_on_checkbox_line_does_not_merge_lines(editor, qtbot): - # Two checkbox lines - editor.from_markdown("- [ ] Test\n- [ ] Foobar") - - # Move caret to second line ("Foobar") - cursor = editor.textCursor() - cursor.movePosition(QTextCursor.Start) - cursor.movePosition(QTextCursor.Down) - editor.setTextCursor(cursor) - - # Add an alarm to the second line - editor.insert_alarm_marker("16:54") - qtbot.wait(0) - - lines = lines_keep(editor) - - # Still two separate lines - assert len(lines) == 2 - - # First line unchanged (no alarm) - assert "Test" in lines[0] - assert "⏰" not in lines[0] - - # Second line has the alarm marker - assert "Foobar" in lines[1] - assert "⏰ 16:54" in lines[1] - - def test_render_images_with_corrupted_data(qtbot, app): """Test rendering images with corrupted data that creates null QImage""" themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT)) @@ -1830,21 +1802,6 @@ def test_render_images_with_corrupted_data(qtbot, app): assert len(text) >= 0 -def test_insert_alarm_marker(qtbot, app): - """Test inserting alarm markers""" - themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT)) - editor = MarkdownEditor(theme_manager=themes) - qtbot.addWidget(editor) - editor.show() - - # Insert alarm marker - editor.insert_alarm_marker("14:30") - qtbot.wait(50) - - content = editor.to_markdown() - assert "14:30" in content or "⏰" in content - - def test_editor_with_tables(qtbot, app): """Test editor with markdown tables""" themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))