diff --git a/gramps/gen/lib/date.py b/gramps/gen/lib/date.py index cbf2810c5..3de400eb6 100644 --- a/gramps/gen/lib/date.py +++ b/gramps/gen/lib/date.py @@ -1909,3 +1909,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 8ad6a016b..f2a129d4b 100644 --- a/gramps/gui/editors/editdate.py +++ b/gramps/gui/editors/editdate.py @@ -63,7 +63,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 @@ -134,7 +134,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') @@ -170,8 +175,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(): @@ -357,6 +360,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 @@ -368,6 +380,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: