#!/usr/bin/env python # example calendar.py # # Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson, Mattias Gronlund # Copyright (C) 2000 Tony Gale # Copyright (C) 2001-2004 John Finlay # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import pygtk pygtk.require('2.0') import gtk, pango import time class CalendarExample: DEF_PAD = 10 DEF_PAD_SMALL = 5 TM_YEAR_BASE = 1900 calendar_show_header = 0 calendar_show_days = 1 calendar_month_change = 2 calendar_show_week = 3 def calendar_date_to_string(self): year, month, day = self.window.get_date() mytime = time.mktime((year, month+1, day, 0, 0, 0, 0, 0, -1)) return time.strftime("%x", time.localtime(mytime)) def calendar_set_signal_strings(self, sig_str): prev_sig = self.prev_sig.get() self.prev2_sig.set_text(prev_sig) prev_sig = self.last_sig.get() self.prev_sig.set_text(prev_sig) self.last_sig.set_text(sig_str) def calendar_month_changed(self, widget): buffer = "month_changed: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_day_selected(self, widget): buffer = "day_selected: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_day_selected_double_click(self, widget): buffer = "day_selected_double_click: %s" buffer = buffer % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) year, month, day = self.window.get_date() if self.marked_date[day-1] == 0: self.window.mark_day(day) self.marked_date[day-1] = 1 else: self.window.unmark_day(day) self.marked_date[day-1] = 0 def calendar_prev_month(self, widget): buffer = "prev_month: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_next_month(self, widget): buffer = "next_month: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_prev_year(self, widget): buffer = "prev_year: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_next_year(self, widget): buffer = "next_year: %s" % self.calendar_date_to_string() self.calendar_set_signal_strings(buffer) def calendar_set_flags(self): options = 0 for i in range(5): if self.settings[i]: options = options + (1<