From 8662cab78b290e7ae5e6d42584631d18a55447d9 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Sat, 13 Jul 2024 14:08:42 +0100 Subject: [PATCH] change show_other_months to styling only --- src/textual/widgets/_month_calendar.py | 40 ++++++-------------------- tests/test_month_calendar.py | 25 ++++++---------- 2 files changed, 16 insertions(+), 49 deletions(-) diff --git a/src/textual/widgets/_month_calendar.py b/src/textual/widgets/_month_calendar.py index e89bf0ce66..a1d8011b3c 100644 --- a/src/textual/widgets/_month_calendar.py +++ b/src/textual/widgets/_month_calendar.py @@ -331,49 +331,25 @@ def action_select_date(self) -> None: table.action_select_cursor() def action_previous_week(self) -> None: - table = self.query_one(MonthCalendarTable) - if self.show_other_months and table.cursor_row == 0: - self.date -= relativedelta(weeks=1) - else: - table.action_cursor_up() + self.date -= relativedelta(weeks=1) def action_next_week(self) -> None: - table = self.query_one(MonthCalendarTable) - if self.show_other_months and table.cursor_row == table.row_count - 1: - self.date += relativedelta(weeks=1) - else: - table.action_cursor_down() + self.date += relativedelta(weeks=1) def action_next_day(self) -> None: - table = self.query_one(MonthCalendarTable) - if table.cursor_column == len(table.columns) - 1: - next_date = self.date + relativedelta(days=1) - if self.show_other_months or next_date.month == self.date.month: - self.date = next_date - else: - table.action_cursor_right() + self.date += relativedelta(days=1) def action_previous_day(self) -> None: - table = self.query_one(MonthCalendarTable) - if table.cursor_column == 0: - previous_date = self.date - relativedelta(days=1) - if self.show_other_months or previous_date.month == self.date.month: - self.date = previous_date - else: - table.action_cursor_left() + self.date -= relativedelta(days=1) def action_next_month(self) -> None: - if self.show_other_months: - self.next_month() + self.next_month() def action_previous_month(self) -> None: - if self.show_other_months: - self.previous_month() + self.previous_month() def action_next_year(self) -> None: - if self.show_other_months: - self.next_year() + self.next_year() def action_previous_year(self) -> None: - if self.show_other_months: - self.previous_year() + self.previous_year() diff --git a/tests/test_month_calendar.py b/tests/test_month_calendar.py index 1000f7a12f..5eff44cae7 100644 --- a/tests/test_month_calendar.py +++ b/tests/test_month_calendar.py @@ -314,9 +314,8 @@ async def test_hover_coordinate_persists_after_first_weekday_changes(): async def test_calendar_updates_when_up_key_pressed_on_first_row(): - """If `show_other_months` is True, pressing the `up` key when the cursor - is on the first row should update the date to the previous week and bring - that month into view""" + """Pressing the `up` key when the cursor is on the first row should update + the date to the previous week and bring that month into view""" app = MonthCalendarApp(date=datetime.date(2021, 6, 3)) async with app.run_test() as pilot: @@ -335,9 +334,8 @@ async def test_calendar_updates_when_up_key_pressed_on_first_row(): async def test_calendar_updates_when_down_key_pressed_on_last_row(): - """If `show_other_months` is True, pressing the `down` key when the cursor - is on the last row should update the date to the next week and bring - that month into view""" + """Pressing the `down` key when the cursor is on the last row should update + the date to the next week and bring that month into view""" app = MonthCalendarApp(date=datetime.date(2021, 5, 31)) async with app.run_test() as pilot: @@ -355,10 +353,9 @@ async def test_calendar_updates_when_down_key_pressed_on_last_row(): assert table.get_cell_at(Coordinate(0, 0)).plain == "31" -async def test_cursor_wraps_around_to_previous_or_next_date_in_month(): +async def test_cursor_wraps_around_to_previous_or_next_date(): """Pressing the `left`/`right` key when the cursor is on the first/last - column should wrap around the cursor to the previous/next date in the - month""" + column should wrap around the cursor to the previous/next date""" app = MonthCalendarApp(date=datetime.date(2021, 6, 6)) async with app.run_test() as pilot: @@ -376,9 +373,8 @@ async def test_cursor_wraps_around_to_previous_or_next_date_in_month(): async def test_calendar_updates_when_date_outside_month_highlighted(): - """If `show_other_months` is True, highlighting a date from the previous - or next month should update the calendar to bring that entire month into - view""" + """Highlighting a date from the previous or next month should update the + calendar to bring that entire month into view""" app = MonthCalendarApp( date=datetime.date(2021, 6, 1), @@ -428,11 +424,6 @@ async def test_calendar_if_show_other_months_is_false(): assert table.cursor_coordinate == expected_coordinate assert app.messages == expected_messages - await pilot.press("left") - assert table.cursor_coordinate == expected_coordinate - assert app.messages == expected_messages - assert month_calendar.date == expected_date - await pilot.click(MonthCalendar, offset=(3, 1)) assert table.cursor_coordinate == expected_coordinate assert app.messages == expected_messages