From 2f4682acbdb62472ed06f68e5a05ef7c7067ad6c Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sun, 31 May 2015 17:54:21 +0100 Subject: [PATCH] Add a couple more place displayer options --- gramps/gen/config.py | 1 + gramps/gen/display/place.py | 17 +++++++++++++++++ gramps/gui/configure.py | 22 ++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index 7df4032f0..ce982484b 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -295,6 +295,7 @@ register('preferences.name-format', 1) register('preferences.place-auto', True) register('preferences.place-number', False) register('preferences.place-reverse', False) +register('preferences.place-restrict', 0) register('preferences.place-lang', '') register('preferences.patronimic-surname', False) register('preferences.no-given-text', "[%s]" % _("Missing Given Name")) diff --git a/gramps/gen/display/place.py b/gramps/gen/display/place.py index be3bab30f..7a390f798 100644 --- a/gramps/gen/display/place.py +++ b/gramps/gen/display/place.py @@ -56,6 +56,15 @@ class PlaceDisplay(object): else: lang = config.get('preferences.place-lang') places = get_location_list(db, place, date, lang) + + if config.get('preferences.place-restrict') > 0: + index = _find_populated_place(places) + if index is not None: + if config.get('preferences.place-restrict') == 1: + places = places[:index+1] + else: + places = places[index:] + names = [item[0] for item in places] if config.get('preferences.place-number'): @@ -68,4 +77,12 @@ class PlaceDisplay(object): return ", ".join(names) +def _find_populated_place(places): + populated_place = None + for index, item in enumerate(places): + if int(item[1]) in [PlaceType.HAMLET, PlaceType.VILLAGE, + PlaceType.TOWN, PlaceType.CITY]: + populated_place = index + return populated_place + displayer = PlaceDisplay() diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index 22416818b..6759161bb 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -483,7 +483,7 @@ class GrampsPreferences(ConfigureDialog): self.add_behavior_panel, self.add_famtree_panel, self.add_formats_panel, - self.add_place_panel, + self.add_places_panel, self.add_text_panel, self.add_prefix_panel, self.add_date_panel, @@ -1098,7 +1098,7 @@ class GrampsPreferences(ConfigureDialog): row += 1 return _('Display'), grid - def add_place_panel(self, configdialog): + def add_places_panel(self, configdialog): row = 0 grid = Gtk.Grid() grid.set_border_width(12) @@ -1117,6 +1117,20 @@ class GrampsPreferences(ConfigureDialog): row, 'preferences.place-reverse', stop=3) row += 1 + # Place restriction + obox = Gtk.ComboBoxText() + formats = [_("Full place name"), + _("-> Hamlet/VillageTown/City"), + _("Hamlet/VillageTown/City ->")] + list(map(obox.append_text, formats)) + active = config.get('preferences.place-restrict') + obox.set_active(active) + obox.connect('changed', self.place_restrict_changed) + lwidget = BasicLabel("%s: " % _('Restrict')) + grid.attach(lwidget, 0, row, 1, 1) + grid.attach(obox, 1, row, 2, 1) + row += 1 + self.add_entry(grid, _("Language"), row, 'preferences.place-lang') row += 1 @@ -1178,6 +1192,10 @@ class GrampsPreferences(ConfigureDialog): active = obj.get_active() config.set('behavior.check-for-updates', active) + def place_restrict_changed(self, obj): + active = obj.get_active() + config.set('preferences.place-restrict', active) + def date_format_changed(self, obj): config.set('preferences.date-format', obj.get_active()) OkDialog(_('Change is not immediate'),