7360: Calendar conversion broken in date editor

Port my fix from gramps34: [ecdcca] [aa9deb]
The enable/disable code behaves worse under gtk3, need further polish
(this is not related to the current fix). Sometimes the changes
to the d/m/y edit fields don't fire the "changed" signal with the
UI value seen by build_date_from_ui
This commit is contained in:
Vassilii Khachaturov 2014-01-21 12:25:42 +02:00
parent 22b71da84b
commit 55a0cc990f

View File

@ -204,7 +204,7 @@ class EditDate(ManagedWindow):
# want to have several open dialogs, since then the user will # want to have several open dialogs, since then the user will
# loose track of which is which. Much like opening files. # loose track of which is which. Much like opening files.
self.return_date = None self.validated_date = self.return_date = None
for o in self.top.get_objects(): for o in self.top.get_objects():
try: try:
@ -232,7 +232,7 @@ class EditDate(ManagedWindow):
if not self.revalidate(): if not self.revalidate():
continue continue
self.return_date = Date() self.return_date = Date()
self.return_date.copy(self.date) self.return_date.copy(self.validated_date)
self.close() self.close()
break break
@ -256,12 +256,15 @@ class EditDate(ManagedWindow):
value=the_value, value=the_value,
text=the_text, text=the_text,
newyear=the_newyear) newyear=the_newyear)
self.date.copy(d) # didn't throw yet?
LOG.debug("return_date set to: {0}".format(d.to_struct())) self.validated_date = d
LOG.debug("validated_date set to: {0}".format(d.to_struct()))
self.ok_button.set_sensitive(1) self.ok_button.set_sensitive(1)
self.calendar_box.set_sensitive(1)
return True return True
except DateError as e: except DateError as e:
self.ok_button.set_sensitive(0) self.ok_button.set_sensitive(0)
self.calendar_box.set_sensitive(0)
self.statusbar.push(1, self.statusbar.push(1,
_("Correct the date or switch from `{cur_mode}' to `{text_mode}'" _("Correct the date or switch from `{cur_mode}' to `{text_mode}'"
).format( ).format(
@ -363,9 +366,12 @@ class EditDate(ManagedWindow):
old_cal = self.date.get_calendar() old_cal = self.date.get_calendar()
new_cal = self.calendar_box.get_active() new_cal = self.calendar_box.get_active()
LOG.debug(">>>switch_calendar: {0} changed, {1} -> {2}".format(
obj, old_cal, new_cal))
(the_quality, the_modifier, the_calendar, (the_quality, the_modifier, the_calendar,
the_value, the_text, the_newyear) = self.build_date_from_ui() the_value, the_text, the_newyear) = self.build_date_from_ui()
try:
self.date.set( self.date.set(
quality=the_quality, quality=the_quality,
modifier=the_modifier, modifier=the_modifier,
@ -373,7 +379,9 @@ class EditDate(ManagedWindow):
value=the_value, value=the_value,
text=the_text, text=the_text,
newyear=the_newyear) newyear=the_newyear)
except DateError:
pass
else:
if not self.date.is_empty(): if not self.date.is_empty():
self.date.convert_calendar(new_cal) self.date.convert_calendar(new_cal)
@ -390,3 +398,5 @@ class EditDate(ManagedWindow):
self.stop_day.set_value(self.date.get_stop_day()) self.stop_day.set_value(self.date.get_stop_day())
self.stop_month_box.set_active(self.date.get_stop_month()) self.stop_month_box.set_active(self.date.get_stop_month())
self.stop_year.set_value(self.date.get_stop_year()) self.stop_year.set_value(self.date.get_stop_year())
LOG.debug("<<<switch_calendar: {0} changed, {1} -> {2}".format(
obj, old_cal, new_cal))