Skip to content

Commit

Permalink
change show_other_months to styling only
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Jul 13, 2024
1 parent df43416 commit 8662cab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
40 changes: 8 additions & 32 deletions src/textual/widgets/_month_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 8 additions & 17 deletions tests/test_month_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8662cab

Please sign in to comment.