Gtk.Calendar¶
class — extends Widget, Accessible, Buildable, ConstraintTarget
Displays a Gregorian calendar, one month at a time.
<picture> <source srcset="calendar-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkCalendar" src="calendar.png"> </picture>
A GtkCalendar can be created with Calendar.new.
The selected date can be retrieved from a GtkCalendar using
Calendar.get_date.
It can be altered with Calendar.set_date.
To place a visual marker on a particular day, use
Calendar.mark_day and to remove the marker,
Calendar.unmark_day. Alternative, all
marks can be cleared with Calendar.clear_marks.
Users should be aware that, although the Gregorian calendar is the legal calendar in most countries, it was adopted progressively between 1582 and 1929. Display before these dates is likely to be historically incorrect.
Shortcuts and Gestures¶
GtkCalendar supports the following gestures:
- Scrolling up or down will switch to the previous or next month.
- Date strings can be dropped for setting the current day.
CSS nodes¶
calendar.view
├── header
│ ├── button
│ ├── stack.month
│ ├── button
│ ├── button
│ ├── label.year
│ ╰── button
╰── grid
╰── label[.day-name][.week-number][.day-number][.other-month][.today]
GtkCalendar has a main node with name calendar. It contains a subnode
called header containing the widgets for switching between years and months.
The grid subnode contains all day labels, including week numbers on the left (marked with the .week-number css class) and day names on top (marked with the .day-name css class).
Day labels that belong to the previous or next month get the .other-month style class. The label of the current day get the .today style class.
Marked day labels get the :selected state assigned.
Constructors¶
new¶
Creates a new calendar, with the current date being selected.
Methods¶
clear_marks¶
Remove all visual markers.
get_date¶
Returns a GDateTime representing the shown
year, month and the selected day.
The returned date is in the local time zone.
get_day¶
Gets the day of the selected date.
get_day_is_marked¶
Returns if the day of the calendar is already marked.
Parameters:
day— the day number between 1 and 31.
get_month¶
Gets the month of the selected date.
get_show_day_names¶
Returns whether self is currently showing the names
of the week days.
This is the value of the Calendar.show-day-names
property.
get_show_heading¶
Returns whether self is currently showing the heading.
This is the value of the Calendar.show-heading
property.
get_show_week_numbers¶
Returns whether self is showing week numbers right
now.
This is the value of the Calendar.show-week-numbers
property.
get_year¶
Gets the year of the selected date.
mark_day¶
Places a visual marker on a particular day of the current month.
Parameters:
day— the day number to mark between 1 and 31.
select_day¶
:::warning Deprecated since 4.20 This API is deprecated. :::
Switches to date's year and month and select its day.
Parameters:
date— aGDateTimerepresenting the day to select
set_date¶
Switches to date's year and month and selects its day.
Parameters:
date— aGDateTimerepresenting the day to select
set_day¶
Sets the day for the selected date.
The new date must be valid. For example, setting the day to 31 when the month is February will fail.
Parameters:
day— The desired day for the selected date (as a number between 1 and 31).
set_month¶
Sets the month for the selected date.
The new date must be valid. For example, setting the month to 1 (February) when the day is 31 will fail.
Parameters:
month— The desired month for the selected date (as a number between 0 and 11).
set_show_day_names¶
Sets whether the calendar shows day names.
Parameters:
value— Whether to show day names above the day numbers
set_show_heading¶
Sets whether the calendar should show a heading.
The heading contains the current year and month as well as buttons for changing both.
Parameters:
value— Whether to show the heading in the calendar
set_show_week_numbers¶
Sets whether week numbers are shown in the calendar.
Parameters:
value— whether to show week numbers alongside the days
set_year¶
Sets the year for the selected date.
The new date must be valid. For example, setting the year to 2023 when the date is February 29 will fail.
Parameters:
year— The desired year for the selected date (withinGLib.DateTimelimits, i.e. from 0001 to 9999).
unmark_day¶
Removes the visual marker from a particular day.
Parameters:
day— the day number to unmark between 1 and 31.
Properties¶
date¶
The selected date.
This property gets initially set to the current date.
day¶
:::warning Deprecated since 4.20 This API is deprecated. :::
The selected day (as a number between 1 and 31).
month¶
:::warning Deprecated since 4.20 This API is deprecated. :::
The selected month (as a number between 0 and 11).
This property gets initially set to the current month.
show_day_names¶
Determines whether day names are displayed.
show_heading¶
Determines whether a heading is displayed.
show_week_numbers¶
Determines whether week numbers are displayed.
year¶
:::warning Deprecated since 4.20 This API is deprecated. :::
The selected year.
This property gets initially set to the current year.
Signals¶
day-selected¶
Emitted when the user selects a day.
next-month¶
Emitted when the user switches to the next month.
next-year¶
Emitted when user switches to the next year.
prev-month¶
Emitted when the user switches to the previous month.
prev-year¶
Emitted when user switches to the previous year.