Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add month calendar #3667

Draft
wants to merge 94 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
38e3fb6
feat: add month calendar
TomJGooding Nov 12, 2023
9c9d4c2
impoort future annotations
TomJGooding Nov 12, 2023
d4fb00c
update reactives and remove compute method
TomJGooding Nov 14, 2023
acdfc87
remove unused var import
TomJGooding Nov 14, 2023
073c3cd
add provisional watch methods for year and month
TomJGooding Nov 14, 2023
ab1aa6d
add show cursor
TomJGooding Nov 14, 2023
684b2be
add previous and next year methods
TomJGooding Nov 14, 2023
c0d44e8
add previous and next month methods
TomJGooding Nov 14, 2023
5cc2b85
add method to get date coordinate
TomJGooding Nov 15, 2023
055d788
add move cursor method
TomJGooding Nov 15, 2023
5bd8bc2
experiment with adding pauses to tests for ci
TomJGooding Nov 15, 2023
7939c54
Merge branch 'main' into feat-add-month-calendar
TomJGooding Nov 20, 2023
53b1ae6
precommit isort
TomJGooding Nov 20, 2023
7a7266e
remove old pauses in tests
TomJGooding Nov 20, 2023
56b380a
add is_current_month property
TomJGooding Nov 20, 2023
4e139c9
watch reactive first weekday change
TomJGooding Nov 21, 2023
d6cec28
add default cursor date
TomJGooding Nov 22, 2023
42de0f9
update cursor date on cell highlighted
TomJGooding Nov 23, 2023
726274b
add bindings to example
TomJGooding Nov 23, 2023
cfcac14
add basic default css
TomJGooding Nov 23, 2023
caea6eb
Merge branch 'main' into feat-add-month-calendar
TomJGooding Nov 28, 2023
334e771
update cursor date with relative delta
TomJGooding Nov 29, 2023
5a5eed2
Merge branch 'main' of github.com:Textualize/textual into feat-add-mo…
darrenburns Dec 12, 2023
9779e63
Merge branch 'main' into feat-add-month-calendar
TomJGooding Dec 29, 2023
c75950c
change to single date reactive
TomJGooding Dec 29, 2023
2d5e5c3
fix unnecessarily rebuilding table
TomJGooding Dec 29, 2023
0af9260
persist hover after table updates
TomJGooding Dec 29, 2023
66812c1
add option to show other months
TomJGooding Dec 29, 2023
d08c0b3
center example
TomJGooding Dec 29, 2023
5c14a92
add date selected message
TomJGooding Dec 30, 2023
8a8733f
make calendar dates property private
TomJGooding Jan 4, 2024
3d659dc
simplify calendar dates
TomJGooding Jan 4, 2024
20f0875
change calendar to six weeks
TomJGooding Jan 4, 2024
86640ef
update calendar dates docstring
TomJGooding Jan 5, 2024
cbde850
add date highlighted message
TomJGooding Jan 8, 2024
4298ae1
add pause to messages test
TomJGooding Jan 8, 2024
ea45e94
Merge branch 'main' into feat-add-month-calendar
TomJGooding Jan 9, 2024
f85e8b5
stop table header selected message
TomJGooding Jan 9, 2024
1a3d851
fix typing in test app
TomJGooding Jan 9, 2024
e16cb16
cache calendar dates
TomJGooding Jan 10, 2024
80a5f08
fix coordinate search when unnecessary
TomJGooding Jan 13, 2024
2cd2fd6
make cursor coord unpacking consistent
TomJGooding Jan 14, 2024
7f8e432
add binding to test app to toggle show other months
TomJGooding Jan 19, 2024
3c2153e
watch hover coordinate to hide cursor for blank cell
TomJGooding Jan 19, 2024
d690d86
hide hover cursor if blank cell clicked
TomJGooding Jan 19, 2024
ddbb109
check if cell selected is blank
TomJGooding Jan 19, 2024
a28279e
extend hide other months tests
TomJGooding Jan 20, 2024
ca82691
attempt to improve typing
TomJGooding Jan 20, 2024
87e956e
Merge branch 'main' into feat-add-month-calendar
TomJGooding Jan 30, 2024
9574f4c
Merge branch 'main' into feat-add-month-calendar
TomJGooding Feb 7, 2024
3da2661
Merge branch 'main' into feat-add-month-calendar
TomJGooding Mar 21, 2024
ec1fa19
add note about python-dateutil
TomJGooding Mar 21, 2024
6d56462
Merge branch 'main' into feat-add-month-calendar
TomJGooding May 24, 2024
f4549ca
fix performance issues using set_reactive
TomJGooding May 24, 2024
1e3678d
add custom month calendar table
TomJGooding May 24, 2024
fa9ad42
add bindings for previous/next month and year
TomJGooding May 24, 2024
5d90bfd
rename private table message handlers
TomJGooding May 24, 2024
1a826f4
add todo for handling blank cells
TomJGooding May 24, 2024
f4ecbd8
update calendar when up/down pressed on first/last row
TomJGooding May 24, 2024
1689d31
add cursor wrap around to previous/next date
TomJGooding Jun 9, 2024
1e1168a
refactor tests with reusable app class
TomJGooding Jun 10, 2024
dc253f3
improve tests for up/down pressed on first/last row
TomJGooding Jun 10, 2024
6a01d11
rename cursor key actions
TomJGooding Jun 11, 2024
a513aef
fix pageup/pagedown bindings
TomJGooding Jun 11, 2024
a2a7af4
Merge branch 'main' into feat-add-month-calendar
TomJGooding Jun 11, 2024
df43416
check show_other_months in prev/next month/year actions
TomJGooding Jun 11, 2024
8662cab
change show_other_months to styling only
TomJGooding Jul 13, 2024
4c8e701
Merge branch 'main' into feat-add-month-calendar
TomJGooding Jul 16, 2024
631cde7
tweak styling and add todo for component classes
TomJGooding Jul 16, 2024
07e8c5a
Merge branch 'main' into feat-add-month-calendar
TomJGooding Aug 10, 2024
5cb7b7e
change to keyword arguments except date
TomJGooding Aug 10, 2024
7e8b621
tidy ordering of methods
TomJGooding Aug 10, 2024
3f7d56f
replace relativedelta with timedelta for days and weeks
TomJGooding Aug 13, 2024
e72df0b
add tests that prev/next month methods account for leap years
TomJGooding Aug 13, 2024
6fa86ac
replace relativedelta in prev/next year methods
TomJGooding Aug 13, 2024
328bf84
add tests that prev/next month methods account for leap/non-leap years
TomJGooding Aug 13, 2024
d44e3e5
replace relativedelta in prev/next month methods
TomJGooding Aug 13, 2024
077bd63
replace remaining relativedelta instances and remove import
TomJGooding Aug 13, 2024
a7d13ab
tidy tests to help readability
TomJGooding Aug 13, 2024
530adec
refactor _get_calendar_dates method
TomJGooding Aug 14, 2024
aec97b0
rename calendar table to grid
TomJGooding Aug 15, 2024
6789b01
Merge branch 'main' into feat-add-month-calendar
TomJGooding Aug 20, 2024
c6efdde
Merge branch 'main' into feat-add-month-calendar
TomJGooding Sep 11, 2024
694a24d
change to relative imports
TomJGooding Sep 11, 2024
172fbbe
fix `today` by dropping the `()`
TomJGooding Sep 11, 2024
c9b7bd0
add class docstrings
TomJGooding Sep 13, 2024
ed0f127
Revert "change to relative imports"
TomJGooding Sep 13, 2024
e59d91c
add docstrings to messages
TomJGooding Sep 13, 2024
69a1b2a
add docstrings for methods
TomJGooding Sep 14, 2024
52e2f38
add docstrings for action methods
TomJGooding Sep 14, 2024
9a92dee
Merge branch 'main' into feat-add-month-calendar
TomJGooding Sep 14, 2024
de46d7a
fix AttributeError by restoring order in init
TomJGooding Sep 14, 2024
5c9c2be
Merge branch 'main' into feat-add-month-calendar
TomJGooding Sep 24, 2024
a6c38bb
update casing for binding descriptions
TomJGooding Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/examples/widgets/month_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import datetime

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import MonthCalendar


class MonthCalendarApp(App):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a CSS variable containing the following CSS to this app yields better results. I reckon we should add the equivalent CSS to the widget itself to override the default DataTable behaviour (unless you can think of a reason not to).

    MonthCalendar { height: auto; width: auto; }
    MonthCalendar > DataTable { height: auto; width: auto; }

We don't do this in the DataTable itself because it's intended to scroll, but this widget has a very constrained height compared to the DataTable which can be arbitrarily large.

Copy link
Contributor Author

@TomJGooding TomJGooding Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I should have mentioned, I haven't started looking at the DEFAULT_CSS yet as I wanted to focus on the core functionality first. Do you think the table/columns widths should just be static, or allow the developer to specify the column width (or perhaps even grow dynamically according to the widget width)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't started looking at the DEFAULT_CSS yet as I wanted to focus on the core functionality first.

Seems sensible.

Do you think the table/columns widths should just be static, or allow the developer to specify the column width (or perhaps even grow dynamically according to the widget width)?

I think static for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now added some basic DEFAULT_CSS in cfcac14. I've flagged min-width as TODO as this might depend on locale?

CSS = """
Screen {
align: center middle;
}
"""

BINDINGS = [
Binding("ctrl+s", "toggle_show_other_months"),
]

def compose(self) -> ComposeResult:
yield MonthCalendar(datetime.date(year=2021, month=6, day=3))

def action_toggle_show_other_months(self) -> None:
calendar = self.query_one(MonthCalendar)
calendar.show_other_months = not calendar.show_other_months


if __name__ == "__main__":
app = MonthCalendarApp()
app.run()
2 changes: 2 additions & 0 deletions src/textual/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ._loading_indicator import LoadingIndicator
from ._log import Log
from ._markdown import Markdown, MarkdownViewer
from ._month_calendar import MonthCalendar
from ._option_list import OptionList
from ._placeholder import Placeholder
from ._pretty import Pretty
Expand Down Expand Up @@ -66,6 +67,7 @@
"Log",
"Markdown",
"MarkdownViewer",
"MonthCalendar",
"OptionList",
"Placeholder",
"Pretty",
Expand Down
1 change: 1 addition & 0 deletions src/textual/widgets/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from ._loading_indicator import LoadingIndicator as LoadingIndicator
from ._log import Log as Log
from ._markdown import Markdown as Markdown
from ._markdown import MarkdownViewer as MarkdownViewer
from ._month_calendar import MonthCalendar as MonthCalendar
from ._option_list import OptionList as OptionList
from ._placeholder import Placeholder as Placeholder
from ._pretty import Pretty as Pretty
Expand Down
Loading
Loading