gramps/src/DateEdit.py

88 lines
3.0 KiB
Python
Raw Normal View History

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"""
* src/PlaceView.py: Make sure to add new place after edit * src/AddMedia.py: unicode conversion from gtk.Entry * src/AddSpouse.py: unicode conversion from gtk.Entry * src/AddrEdit.py: unicode conversion from gtk.Entry * src/AttrEdit.py: unicode conversion from gtk.Entry * src/AutoComp.py: unicode conversion from gtk.Entry * src/ChooseParents.py: unicode conversion from gtk.Entry * src/DateEdit.py: unicode conversion from gtk.Entry * src/EditPerson.py: unicode conversion from gtk.Entry * src/EditPlace.py: unicode conversion from gtk.Entry * src/EditSource.py: unicode conversion from gtk.Entry * src/EventEdit.py: unicode conversion from gtk.Entry * src/Find.py: unicode conversion from gtk.Entry * src/GrampsCfg.py: unicode conversion from gtk.Entry * src/ImageSelect.py: unicode conversion from gtk.Entry * src/LocEdit.py: unicode conversion from gtk.Entry * src/Marriage.py: unicode conversion from gtk.Entry * src/MergeData.py: unicode conversion from gtk.Entry * src/NameEdit.py: unicode conversion from gtk.Entry * src/PeopleView.py: unicode conversion from gtk.Entry * src/Report.py: unicode conversion from gtk.Entry * src/SelectChild.py: unicode conversion from gtk.Entry * src/Sources.py: unicode conversion from gtk.Entry * src/StartupDialog.py: unicode conversion from gtk.Entry * src/StyleEditor.py: unicode conversion from gtk.Entry * src/UrlEdit.py: unicode conversion from gtk.Entry * src/Utils.py: unicode conversion from gtk.Entry * src/VersionControl.py: unicode conversion from gtk.Entry * src/Witness.py: unicode conversion from gtk.Entry svn: r2534
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)
if not self.checkval.is_valid():
2002-10-20 19:55:16 +05:30
self.pixmap_obj.set_from_pixbuf(DateEdit.bad)
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)