From 04d976ceee07b9f4df76a538fb285485ce38ff53 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Thu, 30 Jan 2014 16:35:13 +0200 Subject: [PATCH] 7117: disallow new year unless Julian or like cal --- gramps/gen/lib/date.py | 3 +++ gramps/gui/editors/editdate.py | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/gramps/gen/lib/date.py b/gramps/gen/lib/date.py index 587797c6f..939508c21 100644 --- a/gramps/gen/lib/date.py +++ b/gramps/gen/lib/date.py @@ -1925,3 +1925,6 @@ def gregorian(date): date.convert_calendar(Date.CAL_GREGORIAN) return date +def calendar_has_fixed_newyear(cal): + """Does the given calendar have a fixed new year, or may it be reset?""" + return cal not in (Date.CAL_GREGORIAN, Date.CAL_JULIAN, Date.CAL_SWEDISH) diff --git a/gramps/gui/editors/editdate.py b/gramps/gui/editors/editdate.py index 43c20b396..607fcaa1c 100644 --- a/gramps/gui/editors/editdate.py +++ b/gramps/gui/editors/editdate.py @@ -64,7 +64,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext -from gramps.gen.lib.date import Date, DateError +from gramps.gen.lib.date import Date, DateError, calendar_has_fixed_newyear from gramps.gen.datehandler import displayer from gramps.gen.const import URL_MANUAL_PAGE from ..display import display_help @@ -135,7 +135,12 @@ class EditDate(ManagedWindow): for name in Date.ui_calendar_names: self.calendar_box.get_model().append([name]) - self.calendar_box.set_active(self.date.get_calendar()) + self.new_year = self.top.get_object('newyear') + self.new_year.set_text(self.date.newyear_to_str()) + + cal = self.date.get_calendar() + self.calendar_box.set_active(cal) + self.align_newyear_ui_with_calendar(cal) self.calendar_box.connect('changed', self.switch_calendar) self.quality_box = self.top.get_object('quality_box') @@ -171,8 +176,6 @@ class EditDate(ManagedWindow): self.stop_year.set_value(self.date.get_stop_year()) self.dual_dated = self.top.get_object('dualdated') - self.new_year = self.top.get_object('newyear') - self.new_year.set_text(self.date.newyear_to_str()) # Disable second date controls if not compound date if not self.date.is_compound(): @@ -358,6 +361,15 @@ class EditDate(ManagedWindow): else: self.calendar_box.set_sensitive(1) + def align_newyear_ui_with_calendar(self, cal): + if calendar_has_fixed_newyear(cal): + LOG.debug("new year disabled for cal {0}".format(cal)) + self.new_year.set_sensitive(0) + self.new_year.set_text('') + else: + LOG.debug("new year enabled for cal {0}".format(cal)) + self.new_year.set_sensitive(1) + def switch_calendar(self, obj): """ Change month names and convert the date based on the calendar @@ -369,6 +381,8 @@ class EditDate(ManagedWindow): LOG.debug(">>>switch_calendar: {0} changed, {1} -> {2}".format( obj, old_cal, new_cal)) + self.align_newyear_ui_with_calendar(new_cal) + (the_quality, the_modifier, the_calendar, the_value, the_text, the_newyear) = self.build_date_from_ui() try: