Replies: 2 comments
|
In my opinion, it would be better to have the possibility to set the multiple surnames editor as default, but keeping the default number of surnames as 1. if len(self.obj.get_primary_name().get_surname_list()) > 1:to if len(self.obj.get_primary_name().get_surname_list()) > 0:With this modification, if I enter a new person, by default the multiple surnames editor appears, but with only one blank surname. If I need to add a second surname, I add one by clicking the "+" (Only one click, versus 2 before the modification). I think this behaviour is better. |
|
Maybe there could be an option to set as default editor the one with multiple surnames, and if selected, another option could appear to define the default number of surnames |
Uh oh!
There was an error while loading. Please reload this page.
Context
Today, every brand-new
Person/Namecreated for editing (via "Add newperson" in any view, "Add child" in the family editor, the alternate-name
"+" button, etc.) always starts with exactly one blank
Surname, andthat blank
Surnamealways defaults to origin type None(
gramps/gen/lib/surname.pySurname.__init__:self.origintype = NameOriginType()). Users who habitually enter people with multiplesurnames (e.g. Spanish/Portuguese paternal+maternal convention) or who
always know the origin type up front (e.g. always "Patronymic") have to
redo the same manual steps — click "Multiple Surnames", add a row, set the
origin type — for every single new person.
This plan adds two new preferences, modeled directly on an existing,
proven pattern in the codebase:
FamilyRelTypealready reads its defaultvalue from
config.get("preferences.family-relation-type")inside its own__init__when no explicit value is given(
gramps/gen/lib/familyreltype.py:63-66), andFamily.unserialize()always overwrites that config-driven default with real data
(
gramps/gen/lib/family.py:244-245), proving the pattern is safe onimport/load paths. We mirror this exactly for
NameOriginType.surnames" — when on, new blank
Names start with 2 blankSurnamerowsinstead of 1, so the person editor opens directly in its existing
"Multiple Surnames" view (
EditPerson._post_init,gramps/gui/editors/editperson.py:235, already switches UI purely basedon
len(surname_list) > 1).what origin type a brand-new blank
Surnamegets, instead of always"None".
1. Config registration —
gramps/gen/config.pyAdd two new keys next to the existing name/surname-related preferences
(near
preferences.patronimic-surname/preferences.family-relation-type,around line 317-335):
2.
NameOriginTypereads the config default —gramps/gen/lib/nameorigintype.pyMirror
FamilyRelTypeexactly:This is the only change needed for Feature B. Every bare
Surname()construction anywhere in the codebase (importers,
preset_name, the"+ add surname" button, etc.) already goes through
NameOriginType()withno explicit value, so they all automatically honor the new preference.
Surname.unserialize()(surname.py:140,self.origintype = NameOriginType(origin_type)) always passes a concrete value fromserialized data, so load/import paths are unaffected — same safety
argument as the existing
FamilyRelType/Family.unserialize()precedent.3. Shared helper for blank-surname count —
gramps/gen/utils/db.pyAdd next to
preset_name(which already importsSurname/NameOriginTypefrom
..libat line 39):Also update the fallback in
preset_name()(gen/utils/db.py:515,currently
surnames = [Surname()]) tosurnames = [Surname() for _unused in range(new_surname_count())], so a "guessed" child/parent name thatends up with zero inherited surnames (because the base person has none)
still honors the preference instead of silently collapsing to one.
4. Replace duplicated call sites
Replace every occurrence of the repeated
with
add_default_surnames(X)(importadd_default_surnamesfromgramps.gen.utils.db). Confirmed call sites (all construct a brand-newblank
Person/Namefor editing — this is the full set, found viagrep -rn "add_surname(Surname())"):gramps/gui/editors/editperson.py:168(EditPerson.empty_object()) —required for correctness, not just consistency:
EditPrimary'schange-detection (
editors/editprimary.py, comparesself.obj.serialize()againstself.empty_object().serialize()) wouldotherwise falsely report unsaved changes whenever the preference is on,
since the real new-person object (built elsewhere, see below) would have
2 surnames while
empty_object()still built 1.gramps/gui/viewmanager.py:1590(add_new_person, global "Add newperson" keybinding)
gramps/gui/widgets/fanchart.py:2381(add_person_cb) and:2396(
add_child_to_fam_cb)gramps/plugins/lib/libpersonview.py:449(add, People list view)gramps/plugins/view/persontreeview.py:121(add)gramps/plugins/view/relview.py:1794(add_child_to_fam)gramps/gui/editors/editfamily.py:363, 374, 384, 1355, 1367, 1385(
north_american,no_name,latin_americanchild-name-guessinghelpers, both the
ChildEmbedListandEditFamilyvariants) — theplaceholder is overwritten by
preset_name()in most branches, butmatters for the no-inherited-surname fallback and
no_name()specifically.
gramps/gui/editors/displaytabs/nameembedlist.py:166(alternate-nametab "+" button — creates a brand-new blank
Namefor editing, matchingFeature A's scope)
Leave unchanged (always add exactly one row regardless of the
preference, by design):
gramps/gui/editors/displaytabs/surnametab.py:240(add_button_clicked,the "+" button inside the multi-surname tab that adds one more row to
an already-existing name) — it constructs
Surname()directly, so itautomatically picks up the Feature B origin-type default already; no
change needed here.
gramps/gen/lib/surnamebase.py:138(get_primary_surname()'s defensiveself-heal when queried on a
Namewith zero surnames) andgramps/gui/editors/editperson.py:~939(save()'s safety-net fixup ifthe user manually deletes all surname rows before saving) — both are
defensive fallbacks for an already-existing
Name, not "new person"creation, so they intentionally keep creating exactly one
Surname()(which still gets the correct default origin type automatically).
5. Preferences dialog UI —
gramps/gui/configure.pyAdd to the "Data" panel (
add_data_panel, same section that already hasthe
preferences.patronimic-surnamecheckbox around line 1697-1707 andthe "Default family relationship" combo around line 1858-1872), right
after the family-relationship combo:
This reuses
NameOriginType.get_map()/get_custom()(both already publicmethods, the same ones
SurnameTab.build_columns()uses ingramps/gui/editors/displaytabs/surnametab.py:121-133to build its ownorigin-type combo) rather than reaching into the "private"
_DATAMAPattribute — so no new precedent or lint concern is introduced.
NameOriginType/Surname/configare already imported inconfigure.py.6. Layering / lint
gen/lib→gen/config,gen/utils/db.py→gen/config) stay entirely insidegen, matching the already-provenFamilyRelTypeprecedent — no violation of the "genmust not importgui" rule.new_surname_count,add_default_surnames) need fulltype hints and concise docstrings per
CLAUDE.md.blackon every changed file; runmypy(note*.gpr.pyfiles areexcluded, not relevant here).
7. Tests
New file
gramps/gen/lib/test/nameorigintype_test.py(no existing testfile for
NameOriginTypeorFamilyRelTypeto follow, so thisestablishes the pattern) — uses the real
configsingleton fromgramps.gen.config, saving/restoringpreferences.default-surname-origin-typein
setUp/tearDown:NameOriginType()returns the configured defaultNameOriginType(NameOriginType.LOCATION)ignores configNameOriginType.NONENew file
gramps/gen/utils/test/db_test.py(create thetest/dir if itdoesn't exist) covering
new_surname_count()/add_default_surnames():preset_name()fallback (no inherited surnames) respects the preferencetoo
Verification
python3 -m unittest gramps.gen.lib.test.nameorigintype_testpython3 -m unittest gramps.gen.utils.test.db_test(per project convention, do not run the full
unittest discoversuitelocally — that's left to CI).
mypyandblack --checkon all changed files.python3 Gramps.py, toggle both new preferences inEdit → Preferences → Data tab, then:
opens directly in "Multiple Surnames" mode with 2 blank rows when the
checkbox is on, and that the new origin-type combo default appears on
those rows.
prompt to save changes (validates the
empty_object()fix).when there's no father/mother surname to inherit.
All reactions