Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateCalculator: Make the enter key trigger calculation #632

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions DateCalculator/DateCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2010 Jakim Friant
# Copyright (c) 2015 Douglas S. Blank <doug.blank@gmail.com>
# Copyright (c) 2020 Jan Sparreboom <jan@sparreboom.net>
# Copyright (c) 2024 Steve Youngs <steve@youngs.cc>
# Copyright (c) 2024-2025 Steve Youngs <steve@youngs.cc>
#
# 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
Expand All @@ -28,7 +28,7 @@
# Python modules
#
# ------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk, Gtk

# ------------------------------------------------------------------------
#
Expand All @@ -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

# ------------------------------------------------------------------------
#
Expand All @@ -56,6 +56,8 @@

from gramps.gen.datehandler import parser

_RETURN = Gdk.keyval_from_name("Return")
_KP_ENTER = Gdk.keyval_from_name("KP_Enter")

# ------------------------------------------------------------------------
#
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down