2007-01-12 Zsolt Foldvari <zfoldvar@users.sourceforge.net>

* src/GrampsWidgets.py: cleanup
	* src/DateEdit.py: align DateEdit methods to ValidatableMaskedEntry
	behavior



svn: r7894
This commit is contained in:
Zsolt Foldvari 2007-01-12 11:54:40 +00:00
parent 0f348602bf
commit e06e67798c
3 changed files with 22 additions and 48 deletions

View File

@ -1,3 +1,8 @@
2007-01-12 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/GrampsWidgets.py: cleanup
* src/DateEdit.py: align DateEdit methods to ValidatableMaskedEntry
behavior
2007-01-11 Don Allingham <don@gramps-project.org> 2007-01-11 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_ReadGedcom.py (GedcomParser): fix parsing of the PLAC.FORM * src/GrampsDb/_ReadGedcom.py (GedcomParser): fix parsing of the PLAC.FORM
construct, handle Heredis's broken REPO format construct, handle Heredis's broken REPO format

View File

@ -126,52 +126,30 @@ class DateEdit:
self.pixmap_obj = button_obj.get_child() self.pixmap_obj = button_obj.get_child()
self.text_obj.connect('validate',self.validate) self.text_obj.connect('validate',self.validate)
self.text_obj.connect('empty',self.validate) self.text_obj.connect('content-changed',self.set_date)
self.button_obj.connect('clicked',self.invoke_date_editor) self.button_obj.connect('clicked',self.invoke_date_editor)
self.text = unicode(self.text_obj.get_text()) self.text_obj.set_text(DateHandler.displayer.display(self.date_obj))
self.check() self.text_obj.validate()
def check(self): def set_date(self, widget):
""" """
Check current date object and display LED indicating the validity. Parse date from text entry to date object
""" """
if self.date_obj.get_modifier() == Date.MOD_TEXTONLY: date = DateHandler.parser.parse(unicode(self.text_obj.get_text()))
self.text_obj.set_invalid() self.date_obj.copy(date)
return False
else:
self.text_obj.set_valid()
return True
def parse_and_check(self,*obj):
"""
Called with the text box loses focus. Parses the text and calls
the check() method ONLY if the text has changed.
"""
text = unicode(self.text_obj.get_text())
if text != self.text:
self.text = text
self.date_obj.copy(DateHandler.parser.parse(text))
self.text_obj.set_text(DateHandler.displayer.display(self.date_obj))
if self.check():
return None
else:
return ValidationError('Bad Date')
def validate(self, widget, data): def validate(self, widget, data):
""" """
Called with the text box loses focus. Parses the text and calls Validate current date in text entry
the check() method ONLY if the text has changed.
""" """
self.date_obj.copy(DateHandler.parser.parse(unicode(data))) # if text could not be parsed it is assumed invalid
if self.check(): if self.date_obj.get_modifier() == Date.MOD_TEXTONLY:
return None
else:
return ValidationError('Bad Date') return ValidationError('Bad Date')
def invoke_date_editor(self,obj): def invoke_date_editor(self,obj):
""" """
Invokes Date Editor dialog when the user clicks the LED button. Invokes Date Editor dialog when the user clicks the Calendar button.
If date was in fact built, sets the date_obj to the newly built If date was in fact built, sets the date_obj to the newly built
date. date.
""" """
@ -181,12 +159,13 @@ class DateEdit:
def update_after_editor(self,date_obj): def update_after_editor(self,date_obj):
""" """
Update text field and LED button to reflect the given date instance. Update text entry and validate it
""" """
if date_obj: if date_obj:
self.date_obj.copy(date_obj) # first we set the text entry, that emits 'content-changed'
self.text_obj.set_text(DateHandler.displayer.display(self.date_obj)) # signal thus the date object gets updated too
self.check() self.text_obj.set_text(DateHandler.displayer.display(date_obj))
self.text_obj.validate()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -549,8 +549,6 @@ class MonitoredDate:
field.set_editable(not readonly) field.set_editable(not readonly)
button.set_sensitive(not readonly) button.set_sensitive(not readonly)
field.set_text(DateHandler.displayer.display(self.date))
class PlaceEntry: class PlaceEntry:
""" """
Handles the selection of a existing or new Place. Supports Drag and Drop Handles the selection of a existing or new Place. Supports Drag and Drop
@ -2033,9 +2031,6 @@ class ValidatableMaskedEntry(MaskedEntry):
'validate': (gobject.SIGNAL_RUN_LAST, 'validate': (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
(gobject.TYPE_PYOBJECT,)), (gobject.TYPE_PYOBJECT,)),
'empty': (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_PYOBJECT,
(gobject.TYPE_PYOBJECT,)),
'changed': 'override', 'changed': 'override',
} }
@ -2173,11 +2168,6 @@ class ValidatableMaskedEntry(MaskedEntry):
error = self.emit("validate", text) error = self.emit("validate", text)
if error: if error:
raise error raise error
else:
error = self.emit("empty", text)
if error:
raise error
self.set_valid() self.set_valid()
return text return text