diff --git a/DateCalculator/DateCalculator.py b/DateCalculator/DateCalculator.py index 5c3c9b825..b6c14b9af 100644 --- a/DateCalculator/DateCalculator.py +++ b/DateCalculator/DateCalculator.py @@ -3,7 +3,7 @@ # Copyright (C) 2010 Jakim Friant # Copyright (c) 2015 Douglas S. Blank # Copyright (c) 2020 Jan Sparreboom -# Copyright (c) 2024 Steve Youngs +# Copyright (c) 2024-2025 Steve Youngs # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ # Python modules # # ------------------------------------------------------------------------ -from gi.repository import Gtk +from gi.repository import Gdk, Gtk # ------------------------------------------------------------------------ # @@ -38,7 +38,7 @@ from gramps.gen.plug import Gramplet from gramps.gen.datehandler import displayer from gramps.gen.lib import Date -from gramps.gui.utils import text_to_clipboard +from gramps.gui.utils import no_match_primary_mask, text_to_clipboard # ------------------------------------------------------------------------ # @@ -56,6 +56,8 @@ from gramps.gen.datehandler import parser +_RETURN = Gdk.keyval_from_name("Return") +_KP_ENTER = Gdk.keyval_from_name("KP_Enter") # ------------------------------------------------------------------------ # @@ -82,12 +84,14 @@ def build_gui(self): self.entry1 = self.__add_entry( _("Reference Date or Date Range"), _("a valid Gramps date") ) + self.entry1.connect("key-press-event", self.key_press) self.entry2 = self.__add_entry( _("Date or offset ±y or ±y, m, d"), _( "1. a Date\n2. a positive or negative number, representing years\n3. a positive or negative list of values, representing years, months, days" ), ) + self.entry2.connect("key-press-event", self.key_press) self.result = self.__add_entry(_("Result")) self.result.set_editable(False) @@ -123,6 +127,12 @@ def __add_entry(self, name, tooltip=""): self.top.pack_start(entry, False, False, 6) return entry + def key_press(self, obj, event): + if no_match_primary_mask(event.get_state()): + if event.keyval in (_RETURN, _KP_ENTER): + self.apply_clicked(obj) + return False + def apply_clicked(self, obj): """ Method that is run when you click the Calculate button.