Skip to content

Commit c56fa9c

Browse files
committed
Updated Place Format editor and displayer etc.
1 parent 47fa0a8 commit c56fa9c

11 files changed

Lines changed: 997 additions & 220 deletions

File tree

gramps/gen/db/generic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
KEY_TO_NAME_MAP, DBMODE_R, DBMODE_W)
5050
from .utils import write_lock_file, clear_lock_file
5151
from .exceptions import DbVersionError, DbUpgradeRequiredError
52+
from ..display.place import displayer as _pd
5253
from ..errors import HandleError
5354
from ..utils.callback import Callback
5455
from ..updatecallback import UpdateCallback
@@ -633,6 +634,7 @@ def load(self, directory, callback=None, mode=DBMODE_W,
633634
self.placeabbr_types = self._get_metadata('placeabbr_types', set())
634635
self.placehier_types = self._get_metadata('placehier_types', set())
635636
PlaceType.set_db_data(self._get_metadata('place_types_data', None))
637+
_pd.load_formats(self._get_metadata('place_formats', []))
636638

637639
# surname list
638640
self.surname_list = self.get_surname_list()
@@ -2319,6 +2321,9 @@ def save_place_types(self, close=False):
23192321
"""
23202322
self._set_metadata('place_types_data', PlaceType.get_db_data(close))
23212323

2324+
def save_place_formats(self, formats):
2325+
self._set_metadata('place_formats', formats)
2326+
23222327
def get_default_handle(self):
23232328
return self._get_metadata("default-person-handle", None)
23242329

gramps/gen/display/place.py

Lines changed: 244 additions & 124 deletions
Large diffs are not rendered by default.

gramps/gen/lib/placeref.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,16 @@ def get_handle_referents(self):
178178
def set_type_for_place(self, place):
179179
"""
180180
Set the hierarchy type for the PlaceRef based on the type of the
181-
enclosing place. If place type is unknown (new place), set to ADMIN.
181+
enclosing place. If place type is a likely ADMIN candidate,
182+
set to ADMIN.
182183
If ref.type is already set, skip.
183184
"""
184185
if self.type == PlaceHierType.UNKNOWN:
185186
p_type = place.get_type()
186-
if p_type.value == PlaceType.UNKNOWN:
187+
g_mask = (PlaceType.G_PLACE | PlaceType.G_UNPOP |
188+
PlaceType.G_REGION | PlaceType.G_COUNTRY |
189+
PlaceType.G_BUILDING)
190+
if p_type.value > PlaceType.UNKNOWN or p_type & g_mask:
187191
self.type.set(PlaceHierType.ADMIN)
188192

189193
def set_type(self, p_type):

gramps/gen/utils/location.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
#-------------------------------------------------------------------------
3434
def get_location_list(db, place, date=None, lang='', hier=PlaceHierType.ADMIN):
3535
"""
36-
Return a list of place names and types for display.
36+
Return a list of place names, types, and handles for display.
3737
the list is in order of smallest (most enclosed) to largest place.
3838
The list will match the date, lang and hierarchy type.
3939
"""
4040
if date is None:
4141
date = __get_latest_date(place)
4242
visited = [place.handle]
43-
lines = [(__get_name(place, date, lang), __get_type(place, date))]
43+
name, abbrs = __get_name(place, date, lang)
44+
lines = [(name, __get_type(place, date), place.handle, abbrs)]
4445
while True:
4546
handle = None
4647
for placeref in place.get_placeref_list():
@@ -55,19 +56,26 @@ def get_location_list(db, place, date=None, lang='', hier=PlaceHierType.ADMIN):
5556
if place is None:
5657
break
5758
visited.append(handle)
58-
lines.append((__get_name(place, date, lang), __get_type(place, date)))
59+
name, abbrs = __get_name(place, date, lang)
60+
lines.append((name, __get_type(place, date), place.handle, abbrs))
5961
return lines
6062

63+
6164
def __get_name(place, date, lang):
65+
""" Gets the name for a given date and language. Returns the str name and
66+
a list of abbreviations (PlaceAbbrevType)
67+
"""
6268
endonym = None
6369
for place_name in place.get_names():
6470
name_date = place_name.get_date_object()
6571
if name_date.is_empty() or date.match_exact(name_date):
6672
if place_name.get_language() == lang:
67-
return place_name.get_value()
73+
return place_name.get_value(), place_name.get_abbrevs()
6874
if endonym is None:
6975
endonym = place_name.get_value()
70-
return endonym if endonym is not None else '?'
76+
abbs = place_name.get_abbrevs()
77+
return (endonym, abbs) if endonym is not None else ('?', [])
78+
7179

7280
def __get_type(place, date):
7381
for place_type in place.get_types():
@@ -76,6 +84,7 @@ def __get_type(place, date):
7684
return place_type
7785
return PlaceType(PlaceType.UNKNOWN)
7886

87+
7988
def __get_latest_date(place):
8089
latest_date = None
8190
for place_name in place.get_names():
@@ -103,9 +112,9 @@ def get_main_location(db, place, date=None):
103112
result as a dictionary of place types and names.
104113
"""
105114
return dict([(int(place_type), name)
106-
for name, place_type
107-
in get_location_list(db, place, date)
108-
if not place_type.is_custom()])
115+
for name, place_type, dummy_hndl, dummy_abbrs
116+
in get_location_list(db, place, date)
117+
if not place_type.is_custom()])
109118

110119
#-------------------------------------------------------------------------
111120
#

gramps/gen/utils/unknown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def make_unknown(class_arg, explanation, class_func, commit_func, transaction,
117117
obj.set_type(EventType.UNKNOWN)
118118
elif isinstance(obj, Place):
119119
obj.set_title(_('Unknown'))
120-
obj.name.set_value(_('Unknown'))
120+
obj.set_name.PlaceName(value=_('Unknown'))
121121
elif isinstance(obj, Source):
122122
obj.set_title(_('Unknown'))
123123
elif isinstance(obj, Citation):

gramps/gui/configure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ def _cursor_changed(self, _obj):
18451845
name = model.get_value(node, 0)
18461846
self.ptype_entry.set_text(name)
18471847
rem_btn = self.top.get_object("remove")
1848-
if typ in self.ptype_in_use or typ > 0:
1848+
if typ in self.ptype_in_use or typ >= 0:
18491849
rem_btn.set_sensitive(False)
18501850
else:
18511851
rem_btn.set_sensitive(True)
@@ -1982,6 +1982,9 @@ def group_entry_focus_out(self, entry, _event):
19821982

19831983
def remove_group(self, _obj, group):
19841984
""" Remove a group (right click over groups checkbox)"""
1985+
# don't remove standard Groups!
1986+
if group <= PlaceType.G_OTHER:
1987+
return
19851988
# find and remove references to this group in types
19861989
for typ, tup in PlaceType.DATAMAP.items():
19871990
new_tup = (tup[0], tup[1] & ~group, tup[2])

gramps/gui/editors/editplace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#-------------------------------------------------------------------------
3838
from gramps.gen.const import GRAMPS_LOCALE as glocale
3939
_ = glocale.translation.sgettext
40-
from gramps.gen.lib import NoteType, Place
40+
from gramps.gen.lib import NoteType, Place, PlaceName
4141
from gramps.gen.db import DbTxn
4242
from .editprimary import EditPrimary
4343
from .displaytabs import (PlaceRefEmbedList, PlaceNameEmbedList,
@@ -75,6 +75,8 @@
7575
class EditPlace(EditPrimary):
7676
""" Edit the place """
7777
def __init__(self, dbstate, uistate, track, place, callback=None):
78+
if not place.get_names():
79+
place.add_name(PlaceName())
7880
EditPrimary.__init__(self, dbstate, uistate, track, place,
7981
dbstate.db.get_place_from_handle,
8082
dbstate.db.get_place_from_gramps_id, callback)

0 commit comments

Comments
 (0)