Merge pull request #1161 from SNoiraud/FR11809

This commit is contained in:
Nick Hall 2022-02-15 22:37:36 +00:00
commit 471ddcbce7
3 changed files with 60 additions and 43 deletions

View File

@ -240,6 +240,7 @@ register('paths.quick-backup-filename',
register('preferences.quick-backup-include-mode', False) register('preferences.quick-backup-include-mode', False)
register('preferences.date-format', 0) register('preferences.date-format', 0)
register('preferences.calendar-format-report', 0) register('preferences.calendar-format-report', 0)
register('preferences.calendar-format-input', 0)
register('preferences.cprefix', 'C%04d') register('preferences.cprefix', 'C%04d')
register('preferences.default-source', False) register('preferences.default-source', False)
register('preferences.tag-on-import', False) register('preferences.tag-on-import', False)

View File

@ -1311,6 +1311,19 @@ class GrampsPreferences(ConfigureDialog):
grid.attach(lwidget, 1, row, 1, 1) grid.attach(lwidget, 1, row, 1, 1)
grid.attach(obox, 2, row, 2, 1) grid.attach(obox, 2, row, 2, 1)
row += 1
# Calendar format on input:
obox = Gtk.ComboBoxText()
list(map(obox.append_text, Date.ui_calendar_names))
active = config.get('preferences.calendar-format-input')
if active >= len(formats):
active = 0
obox.set_active(active)
obox.connect('changed', self.date_calendar_for_input_changed)
lwidget = BasicLabel(_("%s: ") % _('Calendar on input'))
grid.attach(lwidget, 1, row, 1, 1)
grid.attach(obox, 2, row, 2, 1)
row += 1 row += 1
# Status bar: # Status bar:
obox = Gtk.ComboBoxText() obox = Gtk.ComboBoxText()

View File

@ -44,7 +44,6 @@ unambiguously built using UI controls such as menus and spin buttons.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import logging import logging
LOG = logging.getLogger(".EditDate")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -59,7 +58,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 from gramps.gen.config import config
from gramps.gen.lib.date import Date, DateError, calendar_has_fixed_newyear 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_SECT1 from gramps.gen.const import URL_MANUAL_SECT1
@ -67,24 +66,26 @@ from ..display import display_help
from ..managedwindow import ManagedWindow from ..managedwindow import ManagedWindow
from ..glade import Glade from ..glade import Glade
LOG = logging.getLogger(".EditDate")
_ = glocale.translation.sgettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
MOD_TEXT = ( MOD_TEXT = (
(Date.MOD_NONE , _('Regular')), (Date.MOD_NONE, _('Regular')),
(Date.MOD_BEFORE , _('Before')), (Date.MOD_BEFORE, _('Before')),
(Date.MOD_AFTER , _('After')), (Date.MOD_AFTER, _('After')),
(Date.MOD_ABOUT , _('About')), (Date.MOD_ABOUT, _('About')),
(Date.MOD_RANGE , _('Range')), (Date.MOD_RANGE, _('Range')),
(Date.MOD_SPAN , _('Span')), (Date.MOD_SPAN, _('Span')),
(Date.MOD_TEXTONLY , _('Text only')) ) (Date.MOD_TEXTONLY, _('Text only')))
QUAL_TEXT = ( QUAL_TEXT = (
(Date.QUAL_NONE, _('Regular')), (Date.QUAL_NONE, _('Regular')),
(Date.QUAL_ESTIMATED, _('Estimated')), (Date.QUAL_ESTIMATED, _('Estimated')),
(Date.QUAL_CALCULATED, _('Calculated')) ) (Date.QUAL_CALCULATED, _('Calculated')))
CAL_TO_MONTHS_NAMES = { CAL_TO_MONTHS_NAMES = {
Date.CAL_GREGORIAN : displayer.short_months, Date.CAL_GREGORIAN : displayer.short_months,
@ -93,7 +94,7 @@ CAL_TO_MONTHS_NAMES = {
Date.CAL_FRENCH : displayer.french, Date.CAL_FRENCH : displayer.french,
Date.CAL_PERSIAN : displayer.persian, Date.CAL_PERSIAN : displayer.persian,
Date.CAL_ISLAMIC : displayer.islamic, Date.CAL_ISLAMIC : displayer.islamic,
Date.CAL_SWEDISH : displayer.swedish } Date.CAL_SWEDISH : displayer.swedish}
WIKI_HELP_PAGE = URL_MANUAL_SECT1 WIKI_HELP_PAGE = URL_MANUAL_SECT1
WIKI_HELP_SEC = _('Editing_dates', 'manual') WIKI_HELP_SEC = _('Editing_dates', 'manual')
@ -199,19 +200,23 @@ class EditDate(ManagedWindow):
self.calendar_box.set_active(Date.CAL_JULIAN) self.calendar_box.set_active(Date.CAL_JULIAN)
self.dual_dated.connect('toggled', self.switch_dual_dated) self.dual_dated.connect('toggled', self.switch_dual_dated)
cal = config.get('preferences.calendar-format-input')
self.calendar_box.set_active(cal)
# The dialog is modal -- since dates don't have names, we don't # The dialog is modal -- since dates don't have names, we don't
# 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.validated_date = self.return_date = None self.validated_date = self.return_date = None
for o in self.top.get_objects(): for obj in self.top.get_objects():
if o != self.ok_button: if obj != self.ok_button:
for signal in ['changed', 'value-changed']: for signal in ['changed', 'value-changed']:
try: try:
o.connect_after(signal, self.revalidate) obj.connect_after(signal, self.revalidate)
except TypeError: except TypeError:
pass # some of them don't support the signal, ignore them... # some of them don't support the signal, ignore them...
pass
self.revalidate() self.revalidate()
self.show() self.show()
@ -219,8 +224,7 @@ class EditDate(ManagedWindow):
response = self.window.run() response = self.window.run()
LOG.debug("response: {0}".format(response)) LOG.debug("response: {0}".format(response))
if response == Gtk.ResponseType.HELP: if response == Gtk.ResponseType.HELP:
display_help(webpage=WIKI_HELP_PAGE, display_help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
section=WIKI_HELP_SEC)
elif response == Gtk.ResponseType.DELETE_EVENT: elif response == Gtk.ResponseType.DELETE_EVENT:
break break
else: else:
@ -236,7 +240,7 @@ class EditDate(ManagedWindow):
self.close() self.close()
break break
def revalidate(self, obj = None): def revalidate(self, obj=None):
""" """
If anything changed, revalidate the date and If anything changed, revalidate the date and
enable/disable the "OK" button based on the result. enable/disable the "OK" button based on the result.
@ -245,31 +249,31 @@ class EditDate(ManagedWindow):
the_text, the_newyear) = self.build_date_from_ui() the_text, the_newyear) = self.build_date_from_ui()
LOG.debug("revalidate: {0} changed, value: {1}".format( LOG.debug("revalidate: {0} changed, value: {1}".format(
obj, the_value)) obj, the_value))
d = Date(self.date) dat = Date(self.date)
if not self.ok_button.get_sensitive(): if not self.ok_button.get_sensitive():
self.statusbar.pop(1) self.statusbar.pop(1)
try: try:
d.set( dat.set(quality=the_quality,
quality=the_quality,
modifier=the_modifier, modifier=the_modifier,
calendar=the_calendar, calendar=the_calendar,
value=the_value, value=the_value,
text=the_text, text=the_text,
newyear=the_newyear) newyear=the_newyear)
# didn't throw yet? # didn't throw yet?
self.validated_date = d self.validated_date = dat
LOG.debug("validated_date set to: {0}".format(d.__dict__)) LOG.debug("validated_date set to: {0}".format(dat.__dict__))
self.ok_button.set_sensitive(1) self.ok_button.set_sensitive(1)
self.calendar_box.set_sensitive(1) self.calendar_box.set_sensitive(1)
return True return True
except DateError as e: except DateError as dummy_err:
self.ok_button.set_sensitive(0) self.ok_button.set_sensitive(0)
self.calendar_box.set_sensitive(0) self.calendar_box.set_sensitive(0)
curmode = MOD_TEXT[self.type_box.get_active()][1]
txtmode = MOD_TEXT[-1][1]
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}'"
).format( " to `{text_mode}'").format(
cur_mode = MOD_TEXT[self.type_box.get_active()][1], cur_mode=curmode, text_mode=txtmode))
text_mode = MOD_TEXT[-1][1]))
return False return False
def build_menu_names(self, obj): def build_menu_names(self, obj):
@ -380,11 +384,10 @@ class EditDate(ManagedWindow):
self.align_newyear_ui_with_calendar(new_cal) self.align_newyear_ui_with_calendar(new_cal)
(the_quality, the_modifier, the_calendar, (the_quality, the_modifier, dummy_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:
self.date.set( self.date.set(quality=the_quality,
quality=the_quality,
modifier=the_modifier, modifier=the_modifier,
calendar=old_cal, calendar=old_cal,
value=the_value, value=the_value,