From 42b71b23d6b3e163197bcc3b8d580b469447917e Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Thu, 31 Dec 2020 19:34:11 +0100 Subject: [PATCH 1/2] Allow user to set default calendar in date editor Fixes #11809 --- gramps/gen/config.py | 1 + gramps/gui/configure.py | 13 +++++++++++++ gramps/gui/editors/editdate.py | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index 7e660ce9c..d53141685 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -240,6 +240,7 @@ register('paths.quick-backup-filename', register('preferences.quick-backup-include-mode', False) register('preferences.date-format', 0) register('preferences.calendar-format-report', 0) +register('preferences.calendar-format-input', 0) register('preferences.cprefix', 'C%04d') register('preferences.default-source', False) register('preferences.tag-on-import', False) diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index 38d1e394e..2e0f8db47 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -1311,6 +1311,19 @@ class GrampsPreferences(ConfigureDialog): grid.attach(lwidget, 1, row, 1, 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 # Status bar: obox = Gtk.ComboBoxText() diff --git a/gramps/gui/editors/editdate.py b/gramps/gui/editors/editdate.py index 3c7ced14a..1cbe5a07c 100644 --- a/gramps/gui/editors/editdate.py +++ b/gramps/gui/editors/editdate.py @@ -60,6 +60,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- 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.datehandler import displayer from gramps.gen.const import URL_MANUAL_SECT1 @@ -199,6 +200,9 @@ class EditDate(ManagedWindow): self.calendar_box.set_active(Date.CAL_JULIAN) 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 # want to have several open dialogs, since then the user will # loose track of which is which. Much like opening files. From 8de8e36095cd75dfeeb1ac60abe4d007db11087f Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Tue, 12 Jan 2021 11:05:48 +0100 Subject: [PATCH 2/2] editdate: better pylint score --- gramps/gui/editors/editdate.py | 85 +++++++++++++++++----------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/gramps/gui/editors/editdate.py b/gramps/gui/editors/editdate.py index 1cbe5a07c..eaf26c753 100644 --- a/gramps/gui/editors/editdate.py +++ b/gramps/gui/editors/editdate.py @@ -44,7 +44,6 @@ unambiguously built using UI controls such as menus and spin buttons. # #------------------------------------------------------------------------- import logging -LOG = logging.getLogger(".EditDate") #------------------------------------------------------------------------- # @@ -59,7 +58,6 @@ from gi.repository import Gtk # #------------------------------------------------------------------------- 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.datehandler import displayer @@ -68,24 +66,26 @@ from ..display import display_help from ..managedwindow import ManagedWindow from ..glade import Glade +LOG = logging.getLogger(".EditDate") +_ = glocale.translation.sgettext #------------------------------------------------------------------------- # # Constants # #------------------------------------------------------------------------- MOD_TEXT = ( - (Date.MOD_NONE , _('Regular')), - (Date.MOD_BEFORE , _('Before')), - (Date.MOD_AFTER , _('After')), - (Date.MOD_ABOUT , _('About')), - (Date.MOD_RANGE , _('Range')), - (Date.MOD_SPAN , _('Span')), - (Date.MOD_TEXTONLY , _('Text only')) ) + (Date.MOD_NONE, _('Regular')), + (Date.MOD_BEFORE, _('Before')), + (Date.MOD_AFTER, _('After')), + (Date.MOD_ABOUT, _('About')), + (Date.MOD_RANGE, _('Range')), + (Date.MOD_SPAN, _('Span')), + (Date.MOD_TEXTONLY, _('Text only'))) QUAL_TEXT = ( - (Date.QUAL_NONE, _('Regular')), - (Date.QUAL_ESTIMATED, _('Estimated')), - (Date.QUAL_CALCULATED, _('Calculated')) ) + (Date.QUAL_NONE, _('Regular')), + (Date.QUAL_ESTIMATED, _('Estimated')), + (Date.QUAL_CALCULATED, _('Calculated'))) CAL_TO_MONTHS_NAMES = { Date.CAL_GREGORIAN : displayer.short_months, @@ -94,7 +94,7 @@ CAL_TO_MONTHS_NAMES = { Date.CAL_FRENCH : displayer.french, Date.CAL_PERSIAN : displayer.persian, Date.CAL_ISLAMIC : displayer.islamic, - Date.CAL_SWEDISH : displayer.swedish } + Date.CAL_SWEDISH : displayer.swedish} WIKI_HELP_PAGE = URL_MANUAL_SECT1 WIKI_HELP_SEC = _('Editing_dates', 'manual') @@ -209,13 +209,14 @@ class EditDate(ManagedWindow): self.validated_date = self.return_date = None - for o in self.top.get_objects(): - if o != self.ok_button: + for obj in self.top.get_objects(): + if obj != self.ok_button: for signal in ['changed', 'value-changed']: try: - o.connect_after(signal, self.revalidate) + obj.connect_after(signal, self.revalidate) 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.show() @@ -223,8 +224,7 @@ class EditDate(ManagedWindow): response = self.window.run() LOG.debug("response: {0}".format(response)) if response == Gtk.ResponseType.HELP: - display_help(webpage=WIKI_HELP_PAGE, - section=WIKI_HELP_SEC) + display_help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC) elif response == Gtk.ResponseType.DELETE_EVENT: break else: @@ -240,7 +240,7 @@ class EditDate(ManagedWindow): self.close() break - def revalidate(self, obj = None): + def revalidate(self, obj=None): """ If anything changed, revalidate the date and enable/disable the "OK" button based on the result. @@ -249,31 +249,31 @@ class EditDate(ManagedWindow): the_text, the_newyear) = self.build_date_from_ui() LOG.debug("revalidate: {0} changed, value: {1}".format( obj, the_value)) - d = Date(self.date) + dat = Date(self.date) if not self.ok_button.get_sensitive(): self.statusbar.pop(1) try: - d.set( - quality=the_quality, - modifier=the_modifier, - calendar=the_calendar, - value=the_value, - text=the_text, - newyear=the_newyear) + dat.set(quality=the_quality, + modifier=the_modifier, + calendar=the_calendar, + value=the_value, + text=the_text, + newyear=the_newyear) # didn't throw yet? - self.validated_date = d - LOG.debug("validated_date set to: {0}".format(d.__dict__)) + self.validated_date = dat + LOG.debug("validated_date set to: {0}".format(dat.__dict__)) self.ok_button.set_sensitive(1) self.calendar_box.set_sensitive(1) return True - except DateError as e: + except DateError as dummy_err: self.ok_button.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, - _("Correct the date or switch from `{cur_mode}' to `{text_mode}'" - ).format( - cur_mode = MOD_TEXT[self.type_box.get_active()][1], - text_mode = MOD_TEXT[-1][1])) + _("Correct the date or switch from `{cur_mode}'" + " to `{text_mode}'").format( + cur_mode=curmode, text_mode=txtmode)) return False def build_menu_names(self, obj): @@ -384,16 +384,15 @@ class EditDate(ManagedWindow): 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() try: - self.date.set( - quality=the_quality, - modifier=the_modifier, - calendar=old_cal, - value=the_value, - text=the_text, - newyear=the_newyear) + self.date.set(quality=the_quality, + modifier=the_modifier, + calendar=old_cal, + value=the_value, + text=the_text, + newyear=the_newyear) except DateError: pass else: