7117: disallow new year unless Julian or like cal

This commit is contained in:
Vassilii Khachaturov 2014-01-30 16:35:13 +02:00
parent 816bc10a64
commit 856ba57b6e
2 changed files with 21 additions and 4 deletions

View File

@ -1909,3 +1909,6 @@ def gregorian(date):
date.convert_calendar(Date.CAL_GREGORIAN) date.convert_calendar(Date.CAL_GREGORIAN)
return date 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)

View File

@ -63,7 +63,7 @@ from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = 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.datehandler import displayer
from gramps.gen.const import URL_MANUAL_PAGE from gramps.gen.const import URL_MANUAL_PAGE
from ..display import display_help from ..display import display_help
@ -134,7 +134,12 @@ class EditDate(ManagedWindow):
for name in Date.ui_calendar_names: for name in Date.ui_calendar_names:
self.calendar_box.get_model().append([name]) 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.calendar_box.connect('changed', self.switch_calendar)
self.quality_box = self.top.get_object('quality_box') 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.stop_year.set_value(self.date.get_stop_year())
self.dual_dated = self.top.get_object('dualdated') 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 # Disable second date controls if not compound date
if not self.date.is_compound(): if not self.date.is_compound():
@ -357,6 +360,15 @@ class EditDate(ManagedWindow):
else: else:
self.calendar_box.set_sensitive(1) 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): def switch_calendar(self, obj):
""" """
Change month names and convert the date based on the calendar 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( LOG.debug(">>>switch_calendar: {0} changed, {1} -> {2}".format(
obj, old_cal, new_cal)) obj, old_cal, new_cal))
self.align_newyear_ui_with_calendar(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: try: