2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2002 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
"""
|
|
|
|
The DateEdit interface provides visual feedback to the user via a pixamp
|
|
|
|
to indicate if the assocated GtkEntry box contains a valid date. Green
|
|
|
|
means complete and valid date. Yellow means a valid, but incomplete date.
|
|
|
|
Red means that the date is not valid, and will be viewed as a text string
|
|
|
|
instead of a date.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__version__ = "$Revision$"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.gdk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Date
|
|
|
|
import const
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DateEdit
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DateEdit:
|
|
|
|
"""Class that associates a pixmap with a text widget, providing visual
|
|
|
|
feedback that indicates if the text widget contains a valid date"""
|
|
|
|
|
|
|
|
good = gtk.gdk.pixbuf_new_from_file(const.good_xpm)
|
|
|
|
bad = gtk.gdk.pixbuf_new_from_file(const.bad_xpm)
|
|
|
|
caution = gtk.gdk.pixbuf_new_from_file(const.caution_xpm)
|
|
|
|
|
|
|
|
def __init__(self,text_obj,pixmap_obj):
|
|
|
|
"""Creates a connection between the text_obj and the pixmap_obj"""
|
|
|
|
|
|
|
|
self.text_obj = text_obj
|
|
|
|
self.pixmap_obj = pixmap_obj
|
|
|
|
self.checkval = Date.Date()
|
|
|
|
self.text_obj.connect('focus-out-event',self.check)
|
|
|
|
self.check(None,None)
|
|
|
|
|
2003-01-02 10:01:52 +05:30
|
|
|
def set_calendar(self,cobj):
|
|
|
|
self.checkval.set_calendar_obj(cobj)
|
|
|
|
self.check(None,None)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def check(self,obj,val):
|
|
|
|
"""Called with the text box loses focus. If the string contains a
|
|
|
|
valid date, sets the appropriate pixmap"""
|
|
|
|
|
2003-12-17 10:53:16 +05:30
|
|
|
text = unicode(self.text_obj.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
self.checkval.set(text)
|
2004-03-22 10:11:35 +05:30
|
|
|
if not self.checkval.is_valid():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.pixmap_obj.set_from_pixbuf(DateEdit.bad)
|
2004-03-22 10:11:35 +05:30
|
|
|
elif self.checkval.get_incomplete():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.pixmap_obj.set_from_pixbuf(DateEdit.caution)
|
|
|
|
else:
|
|
|
|
self.pixmap_obj.set_from_pixbuf(DateEdit.good)
|
|
|
|
|
|
|
|
|