From e06e67798c71dd532648d5095f9c2ce7b48be554 Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Fri, 12 Jan 2007 11:54:40 +0000 Subject: [PATCH] 2007-01-12 Zsolt Foldvari * src/GrampsWidgets.py: cleanup * src/DateEdit.py: align DateEdit methods to ValidatableMaskedEntry behavior svn: r7894 --- ChangeLog | 5 ++++ src/DateEdit.py | 55 ++++++++++++++------------------------------ src/GrampsWidgets.py | 10 -------- 3 files changed, 22 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4595338a8..fb5043797 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-01-12 Zsolt Foldvari + * src/GrampsWidgets.py: cleanup + * src/DateEdit.py: align DateEdit methods to ValidatableMaskedEntry + behavior + 2007-01-11 Don Allingham * src/GrampsDb/_ReadGedcom.py (GedcomParser): fix parsing of the PLAC.FORM construct, handle Heredis's broken REPO format diff --git a/src/DateEdit.py b/src/DateEdit.py index c0c9e362c..877cc693c 100644 --- a/src/DateEdit.py +++ b/src/DateEdit.py @@ -126,52 +126,30 @@ class DateEdit: self.pixmap_obj = button_obj.get_child() 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.text = unicode(self.text_obj.get_text()) - self.check() - - def check(self): - """ - Check current date object and display LED indicating the validity. - """ - if self.date_obj.get_modifier() == Date.MOD_TEXTONLY: - self.text_obj.set_invalid() - return False - else: - self.text_obj.set_valid() - return True + self.text_obj.set_text(DateHandler.displayer.display(self.date_obj)) + self.text_obj.validate() - def parse_and_check(self,*obj): + def set_date(self, widget): """ - Called with the text box loses focus. Parses the text and calls - the check() method ONLY if the text has changed. + Parse date from text entry to date object """ - 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') - + date = DateHandler.parser.parse(unicode(self.text_obj.get_text())) + self.date_obj.copy(date) + def validate(self, widget, data): """ - Called with the text box loses focus. Parses the text and calls - the check() method ONLY if the text has changed. + Validate current date in text entry """ - self.date_obj.copy(DateHandler.parser.parse(unicode(data))) - if self.check(): - return None - else: + # if text could not be parsed it is assumed invalid + if self.date_obj.get_modifier() == Date.MOD_TEXTONLY: return ValidationError('Bad Date') 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 date. """ @@ -181,12 +159,13 @@ class DateEdit: 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: - self.date_obj.copy(date_obj) - self.text_obj.set_text(DateHandler.displayer.display(self.date_obj)) - self.check() + # first we set the text entry, that emits 'content-changed' + # signal thus the date object gets updated too + self.text_obj.set_text(DateHandler.displayer.display(date_obj)) + self.text_obj.validate() #------------------------------------------------------------------------- # diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index a94d843f6..9219801b0 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -548,8 +548,6 @@ class MonitoredDate: self.date, field, button, uistate, track) field.set_editable(not readonly) button.set_sensitive(not readonly) - - field.set_text(DateHandler.displayer.display(self.date)) class PlaceEntry: """ @@ -2033,9 +2031,6 @@ class ValidatableMaskedEntry(MaskedEntry): 'validate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_PYOBJECT, (gobject.TYPE_PYOBJECT,)), - 'empty': (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_PYOBJECT, - (gobject.TYPE_PYOBJECT,)), 'changed': 'override', } @@ -2173,11 +2168,6 @@ class ValidatableMaskedEntry(MaskedEntry): error = self.emit("validate", text) if error: raise error - else: - error = self.emit("empty", text) - if error: - raise error - self.set_valid() return text