Gtk.Calendar
Gtk.Calendar — Displays a calendar and allows the user to select a date
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Calendar
Functions:
- new
() -> Gtk.Widget
- select_month
(self, month:int, year:int)
- select_day
(self, day:int)
- mark_day
(self, day:int)
- unmark_day
(self, day:int)
- get_day_is_marked
(self, day:int) -> bool
- clear_marks
(self)
- get_display_options
(self) -> Gtk.CalendarDisplayOptions
- set_display_options
(self, flags:Gtk.CalendarDisplayOptions)
- get_date
(self) -> year:int, month:int, day:int
- set_detail_func
(self, func:Gtk.CalendarDetailFunc, data=None)
- get_detail_width_chars
(self) -> int
- set_detail_width_chars
(self, chars:int)
- get_detail_height_rows
(self) -> int
- set_detail_height_rows
(self, rows:int)
Signals:
- “day-selected”
(calendar, user_data)
- “day-selected-double-click”
(calendar, user_data)
- “month-changed”
(calendar, user_data)
- “next-month”
(calendar, user_data)
- “next-year”
(calendar, user_data)
- “prev-month”
(calendar, user_data)
- “prev-year”
(calendar, user_data)
Description:
Gtk.Calendar
is a widget that displays a Gregorian calendar, one month at a time. It can be created with Gtk.Calendar::new()
.
The month and year currently displayed can be altered with Gtk.Calendar::select_month()
. The exact day can be selected from the displayed month using Gtk.Calendar::select_day()
.
To place a visual marker on a particular day, use Gtk.Calendar::mark_day()
and to remove the marker, Gtk.Calendar::unmark_day()
. Alternative, all marks can be cleared with Gtk.Calendar::clear_marks()
.
The way in which the calendar itself is displayed can be altered using Gtk.Calendar::set_display_options()
.
The selected date can be retrieved from a Gtk.Calendar
using Gtk.Calendar::get_date()
.
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.
Function Details:
new()
new () -> Gtk.Widget
Creates a new calendar, with the current date being selected.
- Returns:
a newly
Gtk.Calendar
widget
select_month()
select_month (self, month:int, year:int)
Shifts the calendar to a different month.
select_day()
select_day (self, day:int)
Selects a day from the current month.
mark_day()
mark_day (self, day:int)
Places a visual marker on a particular day.
unmark_day()
unmark_day (self, day:int)
Removes the visual marker from a particular day.
get_day_is_marked()
get_day_is_marked (self, day:int) -> bool
Returns if the day
of the calendar
is already marked.
Returns: whether the day is marked.
Since: 3.0
clear_marks()
clear_marks (self)
Remove all visual markers.
get_display_options()
get_display_options (self) -> Gtk.CalendarDisplayOptions
Returns the current display options of calendar
.
Returns: the display options.
Since: 2.4
set_display_options()
set_display_options (self, flags:Gtk.CalendarDisplayOptions)
Sets display options (whether to display the heading and the monthheadings).
- Since: 2.4
get_date()
get_date (self) -> year:int, month:int, day:int
Obtains the selected date from a Gtk.Calendar
.
set_detail_func()
set_detail_func (self, func:Gtk.CalendarDetailFunc, data=None)
Installs a function which provides Pango markup with detail informationfor each day. Examples for such details are holidays or appointments. Thatinformation is shown below each day when “show-details” is set.A tooltip containing with full detail information is provided, if the entiretext should not fit into the details area, or if “show-details”is not set. The size of the details area can be restricted by setting the“detail-width-chars” and “detail-height-rows”properties.
- Since: 2.14
get_detail_width_chars()
get_detail_width_chars (self) -> int
Queries the width of detail cells, in characters.See “detail-width-chars”.
Returns: The width of detail cells, in characters.
Since: 2.14
set_detail_width_chars()
set_detail_width_chars (self, chars:int)
Updates the width of detail cells.See “detail-width-chars”.
- Since: 2.14
get_detail_height_rows()
get_detail_height_rows (self) -> int
Queries the height of detail cells, in rows.See “detail-width-chars”.
Returns: The height of detail cells, in rows.
Since: 2.14
set_detail_height_rows()
set_detail_height_rows (self, rows:int)
Updates the height of detail cells.See “detail-height-rows”.
- Since: 2.14
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Calendar(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Calendar")
self.connect("destroy", Gtk.main_quit)
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=2)
self.add(hbox)
self.calendar = Gtk.Calendar()
self.calendar.connect("day-selected-double-click", self.on_date_selected)
hbox.pack_start(self.calendar, True, True, 0)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
hbox.pack_start(vbox, False, False, 0)
checkbuttonHeading = Gtk.CheckButton(label="Show Heading")
checkbuttonHeading.set_active(True)
checkbuttonHeading.connect("toggled", self.on_show_heading_change)
vbox.pack_start(checkbuttonHeading, False, False, 0)
checkbuttonDayNames = Gtk.CheckButton(label="Show Day Names")
checkbuttonDayNames.set_active(True)
checkbuttonDayNames.connect("toggled", self.on_show_days_change)
vbox.pack_start(checkbuttonDayNames, False, False, 0)
checkbuttonPreventChange = Gtk.CheckButton(label="Prevent Month/Year Change")
checkbuttonPreventChange.connect("toggled", self.on_prevent_month_change)
vbox.pack_start(checkbuttonPreventChange, False, False, 0)
checkbuttonShowWeeks = Gtk.CheckButton(label="Show Week Numbers")
checkbuttonShowWeeks.connect("toggled", self.on_show_weeks_change)
vbox.pack_start(checkbuttonShowWeeks, False, False, 0)
def on_date_selected(self, calendar):
year, month, day = self.calendar.get_date()
month += 1
print("Date selected: %i/%i/%i" % (year, month, day))
def on_show_heading_change(self, checkbutton):
self.calendar.set_property("show-heading", checkbutton.get_active())
def on_show_days_change(self, checkbutton):
self.calendar.set_property("show-day-names", checkbutton.get_active())
def on_prevent_month_change(self, checkbutton):
self.calendar.set_property("no-month-change", checkbutton.get_active())
def on_show_weeks_change(self, checkbutton):
self.calendar.set_property("show-week-numbers", checkbutton.get_active())
window = Calendar()
window.show_all()
Gtk.main()