本文整理汇总了Python中gi.repository.Gtk.Calendar方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.Calendar方法的具体用法?Python Gtk.Calendar怎么用?Python Gtk.Calendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.Calendar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gtk_calendar_get_pydate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def gtk_calendar_get_pydate(gtk_calendar):
"""
Get the Python date from a :py:class:`Gtk.Calendar` instance. If the day
in *gtk_calendar* is not within the valid range for the specified month, it
will be rounded to the closest value (i.e. 0 for unset will become 1 etc.).
:param gtk_calendar: The calendar to get the date from.
:type gtk_calendar: :py:class:`Gtk.Calendar`
:return: The date as returned by the calendar's :py:meth:`~Gtk.Calendar.get_date` method.
:rtype: :py:class:`datetime.date`
"""
if not isinstance(gtk_calendar, Gtk.Calendar):
raise ValueError('calendar must be a Gtk.Calendar instance')
year, month, day = gtk_calendar.get_date()
month += 1 # account for Gtk.Calendar starting at 0
_, last_day_of_month = calendar.monthrange(year, month)
day = max(1, min(day, last_day_of_month))
return datetime.date(year, month, day)
示例2: set_date
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def set_date(self, date, date_kind):
self.__date_kind = date_kind
if date_kind == GTGCalendar.DATE_KIND_DUE:
self.__fuzzydate_btns.show()
else:
self.__fuzzydate_btns.hide()
if not date:
# we set the widget to today's date if there is not a date defined
date = Date.today()
self.__date = date
if not date.is_fuzzy():
self.__calendar.select_day(date.day)
# Calendar use 0..11 for a month so we need -1
# We can't use conversion through python's datetime
# because it is often an invalid date
self.__calendar.select_month(date.month - 1, date.year)
示例3: get_date
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def get_date(self):
'''Get the datetime object for the selected date'''
year, month, day = Gtk.Calendar.get_date(self)
if day == 0:
day = 1
try:
date = datetime.date(year, month + 1, day)
except ValueError:
# This error may mean that day number is higher than allowed.
# If so, set date to the last day of the month.
if day > 27:
date = datetime.date(year, month + 2, 1) - datetime.timedelta(days = 1)
else:
raise
return date
示例4: set_page
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def set_page(self, page):
treepath = self.treeview.set_current_page(page, vivificate=True)
if treepath:
self.treeview.select_treepath(treepath)
dates = daterange_from_path(page)
if dates:
if dates[0] == 'year':
# Calendar is per month, so do not switch view for year page
pass
else:
cur_date = self.calendar.get_date()
if cur_date < dates[1] or cur_date > dates[2]:
self.calendar.select_date(dates[1])
else:
self.calendar.select_day(0)
self.treeview.get_selection().unselect_all()
示例5: test_gtk_calendar_and_pydate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def test_gtk_calendar_and_pydate(self):
gtk_calendar = Gtk.Calendar()
year, month, day = 2018, 2, 28 # February 28th, 2018
gtk_calendar.select_month(month - 1, year) # GTK months start at 0
gtk_calendar.select_day(day)
date = gui_utilities.gtk_calendar_get_pydate(gtk_calendar)
self.assertIsInstance(date, datetime.date)
self.assertEquals((date.year, date.month, date.day), (year, month, day))
month, day = 1, 27 # January 27th, 2018
date = date.replace(month=month, day=day)
gui_utilities.gtk_calendar_set_pydate(gtk_calendar, date)
self.assertEquals(gtk_calendar.get_date(), (year, month - 1, day))
示例6: test_gtk_calendar_and_pydate_rounding
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def test_gtk_calendar_and_pydate_rounding(self):
gtk_calendar = Gtk.Calendar()
year, month, day = 2018, 4, 31 # April 31st, 2018 (does not exist)
gtk_calendar.select_month(month - 1, year) # GTK months start at 0
gtk_calendar.select_day(day)
date = gui_utilities.gtk_calendar_get_pydate(gtk_calendar)
self.assertEquals((date.year, date.month, date.day), (year, month, 30))
示例7: gtk_calendar_set_pydate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def gtk_calendar_set_pydate(gtk_calendar, pydate):
"""
Set the date on a :py:class:`Gtk.Calendar` instance from a Python
:py:class:`datetime.date` object.
:param gtk_calendar: The gtk_calendar to set the date for.
:type gtk_calendar: :py:class:`Gtk.Calendar`
:param pydate: The date to set on the gtk_calendar.
:type pydate: :py:class:`datetime.date`
"""
gtk_calendar.select_month(pydate.month - 1, pydate.year)
gtk_calendar.select_day(pydate.day)
示例8: show
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def show(self):
width, height = self.__window.get_size()
self.__window.show()
self.__window.grab_add()
# We grab the pointer in the calendar
# Gdk.pointer_grab(
# self.__window.get_window(),
# True,
# Gdk.ModifierType.BUTTON1_MASK | Gdk.ModifierType.MOD2_MASK
# )
# FIXME THIS DOES NOT WORK!!!!!!!
Gdk.pointer_grab(
self.get_window(),
True,
# Gdk.ModifierType.BUTTON1_MASK | Gdk.ModifierType.MOD2_MASK,
# FIXME!!!! JUST GUESSING THE TYPE
Gdk.EventMask.ALL_EVENTS_MASK,
None,
None,
0,
)
if self.get_decorated():
self.__window.connect("delete-event", self.close_calendar)
else:
self.__window.connect('button-press-event', self.__focus_out)
self.__sigid = self.__calendar.connect("day-selected",
self.__day_selected,
"RealDate",)
self.__sigid_month = self.__calendar.connect("month-changed",
self.__month_changed)
# Problem: Gtk.Calendar does not tell you directly if the
# "day-selected" signal was caused by the user clicking on
# a date, or just browsing the calendar.
# Solution: we track that in a variable
self.__is_user_just_browsing_the_calendar = False
self.__mark_today_in_bold()
示例9: __from_calendar_date_to_datetime
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def __from_calendar_date_to_datetime(self, calendar_date):
"""
Gtk.Calendar uses a 0-based convention for counting months.
The rest of the world, including the datetime module, starts from 1.
This is a converter between the two. GTG follows the datetime
convention.
"""
year, month, day = calendar_date
return datetime.date(year, month + 1, day)
示例10: calendar_to_datetime
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def calendar_to_datetime(self, calendar):
"""
Gtk.Calendar uses a 0-based convention for counting months.
The rest of the world, including the datetime module, starts from 1.
This is a converter between the two. GTG follows the datetime
convention.
"""
year, month, day = calendar.get_date()
return datetime.date(year, month + 1, day)
示例11: on_pick_date
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def on_pick_date(button, date_entry):
# Parse the existing date
date = date_entry.get_text()
year, month, day = parseDateTag(date)
# Prepare the date of the picker
calendar = Gtk.Calendar()
curyear, curmonth, curday = calendar.get_date()
year = curyear if year is None else year
month = curmonth if month is None else month - 1
day = curday if day is None else day
calendar.select_month(month, year)
calendar.select_day(day)
# Show the dialog
dialog = Gtk.Dialog(_("Pick a date"),
None,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.add(calendar)
dialog.get_content_area().pack_start(sw, True, True, 0)
dialog.resize(300, 200)
dialog.show_all()
response = dialog.run()
dialog.destroy()
if response == Gtk.ResponseType.ACCEPT:
year, month, day = calendar.get_date()
date_entry.set_text("%04d.%02d.%02d" % (year, month + 1, day))
示例12: do_key_press_event
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def do_key_press_event(self, event):
handled = Gtk.Calendar.do_key_press_event(self, event)
if handled and (event.keyval in KEYVALS_SPACE
or event.keyval in KEYVALS_ENTER):
self.emit('activate')
return handled
示例13: do_button_press_event
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def do_button_press_event(self, event):
handled = Gtk.Calendar.do_button_press_event(self, event)
if event.button == 1 and self.selected:
self.selected = False
self.emit('activate')
return handled
示例14: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def __init__(self, week_numbers=False):
Gtk.Calendar.__init__(self)
self.set_property("show-week-numbers", week_numbers)
示例15: set_date
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import Calendar [as 别名]
def set_date(self, date):
# Set the day temporarily to a day that is present in all months.
self.select_day(1)
# Gtk.Calendar show months in range [0,11].
self.select_month(date.month - 1, date.year)
# Select the day after the month and year have been set
self.select_day(date.day)