Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions gramps/gen/utils/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@
to communicate events to any callback methods in either the database code
or the UI code.
"""
import sys
# -------------------------------------------------------------------------
#
# Standard python modules
#
# -------------------------------------------------------------------------
from __future__ import annotations
import types
import traceback
import inspect
import copy
import sys
from collections.abc import Callable

log = sys.stderr.write

Expand Down Expand Up @@ -265,7 +272,7 @@ def trav(cls):
)
)

def connect(self, signal_name, callback):
def connect(self, signal_name: str, callback: Callable) -> int | None:
"""
Connect a callable to a signal_name. The callable will be called
with the signal is emitted. The callable must accept the argument
Expand All @@ -278,7 +285,7 @@ def connect(self, signal_name, callback):
self._log(
"Warning: attempt to connect to unknown signal: %s\n" % str(signal_name)
)
return
return None

# Add callable to callback_map
if signal_name not in self.__callback_map:
Expand All @@ -293,7 +300,7 @@ def connect(self, signal_name, callback):

return self._current_key

def disconnect(self, key):
def disconnect(self, key: int):
"""
Disconnect a callback.
"""
Expand Down
45 changes: 42 additions & 3 deletions gramps/gui/selectors/baseselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Copyright (C) 2003-2006 Donald N. Allingham
# 2009-2011 Gary Burton
# 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
Expand Down Expand Up @@ -93,7 +94,8 @@ def __init__(
self.track_ref_for_deletion("renderer")
self.renderer.set_property("ellipsize", Pango.EllipsizeMode.END)

self.db = dbstate.db
self.dbstate = dbstate
self.db_connections: list[int] = []
self.tree = None
self.model = None

Expand Down Expand Up @@ -157,7 +159,11 @@ def __init__(
self.set_show_search_bar(show_search_bar)
while Gtk.events_pending():
Gtk.main_iteration()
self.build_tree()

self.dbstate.connect("database-changed", self._db_changed)
self.dbstate.connect("no-database", self._no_db)
self._db_changed(self.dbstate.db)

loading = self.glade.get_object("loading")
loading.hide()

Expand Down Expand Up @@ -313,6 +319,15 @@ def setup_filter(self):
]
self.search_bar.setup_filter(cols)

def _object_add_callback(self, handle_list):
self.build_tree()

def _object_delete_callback(self, handle_list):
self.build_tree()

def _object_update_callback(self, handle_list):
self.build_tree()

def build_tree(self):
"""
Builds the selection people see in the Selector
Expand All @@ -336,7 +351,7 @@ def build_tree(self):
# reset the model with correct sorting
self.clear_model()
self.model = self.get_model_class()(
self.db,
self.dbstate.db,
self.uistate,
self.sort_col,
self.sortorder,
Expand Down Expand Up @@ -389,10 +404,34 @@ def clear_model(self):
self.model.destroy()
self.model = None

def apply_clear(self):
self.showall.set_active(False)

def _db_changed(self, db):
if self.dbstate.is_open():
self.clear_model()
self._disconnect_db_signals()
self.dbstate.db = db
if self.dbstate.is_open():
self._connect_db_signals()
self.build_tree()

def _no_db(self):
self.clear_model()
self._disconnect_db_signals()

def _connect_db_signals(self):
pass

def _disconnect_db_signals(self):
map(self.dbstate.db.disconnect, self.db_connections)
self.db_connections.clear()

def _cleanup_on_exit(self):
"""Unset all things that can block garbage collection.
Finalize rest
"""
self._disconnect_db_signals()
self.clear_model()
self.db = None
self.tree = None
Expand Down
42 changes: 31 additions & 11 deletions gramps/gui/selectors/selectperson.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Copyright (C) 2003-2006 Donald N. Allingham
# 2009 Gary Burton
# 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
Expand All @@ -19,6 +20,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

# -------------------------------------------------------------------------
#
# Standard python modules
#
# -------------------------------------------------------------------------
from __future__ import annotations

# -------------------------------------------------------------------------
#
# internationalization
Expand Down Expand Up @@ -67,28 +75,40 @@ def __init__(
# instead of the default defined for get_window_title()
if title is not None:
self.title = title
self.WIKI_HELP_PAGE = URL_MANUAL_SECT1
if title == _("Select Father"):
self.WIKI_HELP_SEC = _("Select_Father_selector", "manual")
elif title == _("Select Mother"):
self.WIKI_HELP_SEC = _("Select_Mother_selector", "manual")
elif title == _("Select Child"):
self.WIKI_HELP_SEC = _("Select_Child_selector", "manual")
else:
self.WIKI_HELP_SEC = _("Select_Person_selector", "manual")
if not hasattr(self, "WIKI_HELP_PAGE"): # allow derived class to define
self.WIKI_HELP_PAGE = URL_MANUAL_SECT1
if title == _("Select Father"):
self.WIKI_HELP_SEC = _("Select_Father_selector", "manual")
elif title == _("Select Mother"):
self.WIKI_HELP_SEC = _("Select_Mother_selector", "manual")
elif title == _("Select Child"):
self.WIKI_HELP_SEC = _("Select_Child_selector", "manual")
else:
self.WIKI_HELP_SEC = _("Select_Person_selector", "manual")

BaseSelector.__init__(
self, dbstate, uistate, track, filter, skip, show_search_bar, default
)

def _connect_db_signals(self):
self.db_connections.append(
self.db.connect("person-add", self._object_add_callback)
)
self.db_connections.append(
self.db.connect("person-delete", self._object_delete_callback)
)
self.db_connections.append(
self.db.connect("person-update", self._object_update_callback)
)

def _local_init(self):
"""
Perform local initialisation for this class
"""
self.setup_configs("interface.person-sel", 600, 450)
self.tree.connect("key-press-event", self._key_press)

def get_window_title(self):
def get_window_title(self) -> str:
return _("Select Person")

def get_model_class(self):
Expand All @@ -110,7 +130,7 @@ def get_column_titles(self):
def get_from_handle_func(self):
return self.db.get_person_from_handle

def exact_search(self):
def exact_search(self) -> tuple[int]:
"""
Returns a tuple indicating columns requiring an exact search
"""
Expand Down
137 changes: 0 additions & 137 deletions gramps/plugins/tool/relcalc.glade

This file was deleted.

Loading