From e5ec6bd7c942d59cf79394fc1e031b3f215c4a28 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Mon, 22 May 2023 14:30:47 +0200 Subject: [PATCH] Add option to control display format of Lat/Lon Add an option in the preferences diplay tab for views. Add the possibility to select a different choice in the reports. Fixes : #11248 --- gramps/gen/plug/report/stdoptions.py | 13 ++++++++ gramps/gen/utils/place.py | 26 +++++++++++++++ gramps/gui/configure.py | 39 +++++++++++++++++++++++ gramps/gui/views/treemodels/placemodel.py | 8 +++-- gramps/plugins/gramplet/placedetails.py | 5 +-- gramps/plugins/webreport/basepage.py | 12 ++++--- gramps/plugins/webreport/narrativeweb.py | 3 ++ gramps/plugins/webreport/person.py | 5 +-- gramps/plugins/webreport/place.py | 16 +++++++--- 9 files changed, 110 insertions(+), 17 deletions(-) diff --git a/gramps/gen/plug/report/stdoptions.py b/gramps/gen/plug/report/stdoptions.py index 3f3f54fa2..638dcd050 100644 --- a/gramps/gen/plug/report/stdoptions.py +++ b/gramps/gen/plug/report/stdoptions.py @@ -37,6 +37,7 @@ from ..menu import EnumeratedListOption, BooleanOption, NumberOption from ...proxy import PrivateProxyDb, LivingProxyDb from ...utils.grampslocale import GrampsLocale from ...const import GRAMPS_LOCALE as glocale +from ...utils.place import coord_formats _ = glocale.translation.sgettext # _T_ is a gramps-defined keyword -- see po/update_po.py and po/genpot.sh @@ -376,3 +377,15 @@ def add_place_format_option(menu, category): place_format.set_help(_("Select the format to display places")) menu.add_option(category, "place_format", place_format) return place_format + +def add_coordinates_format_option(menu, category): + """ + Insert an option for changing the report's coordinates format to a + report-specific format instead of the user's Edit=>Preferences choice + """ + coord_format = EnumeratedListOption(_("Coordinates format"), -1) + for number, fmt in enumerate(coord_formats): + coord_format.add_item(number, fmt) + coord_format.set_help(_("Select the format to display coordinates")) + menu.add_option(category, "coord_format", coord_format) + return coord_format diff --git a/gramps/gen/utils/place.py b/gramps/gen/utils/place.py index 910232df8..82622f22b 100644 --- a/gramps/gen/utils/place.py +++ b/gramps/gen/utils/place.py @@ -72,6 +72,32 @@ if 'N' == South or 'S' == North or 'E' == West or 'W' == East: translate_en_loc['W'] = 'W' # end localisation part +def _T_(value, context=''): # enable deferred translations + return "%s\x04%s" % (context, value) if context else value + +coord_formats = ( + # format #0 'DEG' degree, minutes, seconds notation + _T_("DEG"), + + # format #1 'DEG-:' degree, minutes, seconds notation with : + _T_("DEG-:"), + + # format #2 'D.D4' degree notation, 4 decimals + _T_("D.D4"), + + # format #3 'D.D8' degree notation, 8 decimals (precision like ISO-DMS) + _T_("D.D8"), + + # format #4 'RT90' Output format for the Swedish coordinate system RT90 + _T_("RT90") + + # output display not implemented for the following formats: + + # 'ISO-D' ISO 6709 degree notation i.e. ±DD.DDDD±DDD.DDDD + # 'ISO-DM' ISO 6709 degree, minutes notation + # 'ISO-DMS' ISO 6709 degree, minutes, seconds notation + ) + #------------------ # diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index ea94f1774..2c0467be1 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -57,6 +57,7 @@ from gramps.gen.display.name import NameDisplayError from gramps.gen.display.place import displayer as _pd from gramps.gen.utils.alive import update_constants from gramps.gen.utils.file import media_path +from gramps.gen.utils.place import coord_formats from gramps.gen.utils.keyword import (get_keywords, get_translations, get_translation_from_keyword, get_keyword_from_translation) @@ -1119,6 +1120,23 @@ class GrampsPreferences(ConfigureDialog): config.set('preferences.place-format', obj.get_active()) self.uistate.emit('placeformat-changed') + def cb_coord_fmt_changed(self, obj): + """ + Called when the coordinates format is changed. + """ + config.set('preferences.coord-format', obj.get_active()) + self.uistate.emit('placeformat-changed') # Do we need to add a new signal ? + + def cb_coord_fmt_rebuild(self): + """ + Called to rebuild the coordinates format list. + """ + model = Gtk.ListStore(str) + for fmt in coord_formats: + model.append([fmt]) + self.cformat.set_model(model) + self.cformat.set_active(0) + def cb_pa_sur_changed(self, *args): """ Checkbox patronymic as surname changed, propagate to namedisplayer @@ -1205,6 +1223,27 @@ class GrampsPreferences(ConfigureDialog): hbox.pack_start(self.fmt_btn, False, False, 0) grid.attach(hbox, 2, row, 2, 1) + row += 1 + # Coordinates display format: + self.cformat = Gtk.ComboBox() + self.cformat.set_hexpand(True) + renderer = Gtk.CellRendererText() + self.cformat.pack_start(renderer, True) + self.cformat.add_attribute(renderer, "text", 0) + self.cb_coord_fmt_rebuild() + if not config.is_set('preferences.coord-format'): + config.register('preferences.coord-format', 0) + active = config.get('preferences.coord-format') + self.cformat.set_active(active) + self.cformat.connect('changed', self.cb_coord_fmt_changed) + hbox = Gtk.Box() + lwidget = BasicLabel(_("%s: ") % _('Coordinates format')) + lwidget.set_use_underline(True) + lwidget.set_mnemonic_widget(self.cformat) + hbox.pack_start(self.cformat, True, True, 0) + grid.attach(lwidget, 1, row, 1, 1) + grid.attach(hbox, 2, row, 2, 1) + row += 1 # Display name: self.examplename = Name() diff --git a/gramps/gui/views/treemodels/placemodel.py b/gramps/gui/views/treemodels/placemodel.py index c4b47e09c..0589e7055 100644 --- a/gramps/gui/views/treemodels/placemodel.py +++ b/gramps/gui/views/treemodels/placemodel.py @@ -46,7 +46,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gen.lib import Place, PlaceType from gramps.gen.datehandler import format_time -from gramps.gen.utils.place import conv_lat_lon +from gramps.gen.utils.place import conv_lat_lon, coord_formats from gramps.gen.display.place import displayer as place_displayer from gramps.gen.config import config from .flatbasemodel import FlatBaseModel @@ -140,7 +140,8 @@ class PlaceBaseModel: def column_longitude(self, data): if not data[3]: return '' - value = conv_lat_lon('0', data[3], format='DEG')[1] + value = conv_lat_lon('0', data[3], + format=coord_formats[config.get('preferences.coord-format')])[1] if not value: return _("Error in format") return ("\u202d" + value + "\u202e") if glocale.rtl_locale else value @@ -148,7 +149,8 @@ class PlaceBaseModel: def column_latitude(self, data): if not data[4]: return '' - value = conv_lat_lon(data[4], '0', format='DEG')[0] + value = conv_lat_lon(data[4], '0', + format=coord_formats[config.get('preferences.coord-format')])[0] if not value: return _("Error in format") return ("\u202d" + value + "\u202e") if glocale.rtl_locale else value diff --git a/gramps/plugins/gramplet/placedetails.py b/gramps/plugins/gramplet/placedetails.py index 9a03715ba..63f93afa8 100644 --- a/gramps/plugins/gramplet/placedetails.py +++ b/gramps/plugins/gramplet/placedetails.py @@ -32,10 +32,11 @@ from gi.repository.GLib import markup_escape_text #------------------------------------------------------------------------- from gramps.gen.plug import Gramplet from gramps.gui.widgets import Photo -from gramps.gen.utils.place import conv_lat_lon +from gramps.gen.utils.place import conv_lat_lon, coord_formats from gramps.gen.utils.file import media_path_full from gramps.gen.display.place import displayer as place_displayer from gramps.gen.const import COLON, GRAMPS_LOCALE as glocale +from gramps.gen.config import config _ = glocale.translation.gettext class PlaceDetails(Gramplet): @@ -129,7 +130,7 @@ class PlaceDetails(Gramplet): self.display_separator() lat, lon = conv_lat_lon(place.get_latitude(), place.get_longitude(), - format='DEG') + format=coord_formats[config.get('preferences.coord-format')]) if lat: self.add_row(_('Latitude'), lat) if lon: diff --git a/gramps/plugins/webreport/basepage.py b/gramps/plugins/webreport/basepage.py index 73b2cc445..333da6c62 100644 --- a/gramps/plugins/webreport/basepage.py +++ b/gramps/plugins/webreport/basepage.py @@ -80,7 +80,7 @@ from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback from gramps.gen.datehandler import parser as _dp from gramps.plugins.lib.libhtml import Html, xml_lang from gramps.plugins.lib.libhtmlbackend import HtmlBackend, process_spaces -from gramps.gen.utils.place import conv_lat_lon +from gramps.gen.utils.place import conv_lat_lon, coord_formats from gramps.gen.utils.location import get_main_location from gramps.plugins.webreport.common import (_NAME_STYLE_DEFAULT, HTTP, HTTPS, add_birthdate, CSS, html_escape, @@ -2961,7 +2961,8 @@ class BasePage: tbody += trow data = place.get_latitude() - v_lat, v_lon = conv_lat_lon(data, "0.0", "D.D8") + v_lat, v_lon = conv_lat_lon(data, "0.0", + coord_formats[self.report.options['coord_format']]) if not v_lat: data += self._(":") # We use the same message as in: @@ -2975,11 +2976,12 @@ class BasePage: trow = Html('tr') + ( Html("td", self._("Latitude"), class_="ColumnAttribute", inline=True), - Html("td", data, class_="ColumnValue", inline=True) + Html("td", v_lat, class_="ColumnValue", inline=True) ) tbody += trow data = place.get_longitude() - v_lat, v_lon = conv_lat_lon("0.0", data, "D.D8") + v_lat, v_lon = conv_lat_lon("0.0", data, + coord_formats[self.report.options['coord_format']]) if not v_lon: data += self._(":") # We use the same message as in: @@ -2993,7 +2995,7 @@ class BasePage: trow = Html('tr') + ( Html("td", self._("Longitude"), class_="ColumnAttribute", inline=True), - Html("td", data, class_="ColumnValue", inline=True) + Html("td", v_lon, class_="ColumnValue", inline=True) ) tbody += trow diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index b0b510055..82f7f9bea 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -2532,6 +2532,9 @@ class NavWebOptions(MenuReportOptions): "\nSee OLDER VERSIONS in https://openlayers.org/")) addopt("ol_version", self.__olv) + coord_format = stdoptions.add_coordinates_format_option(menu, + category_name) + def __add_others_options(self, menu): """ Options for the cms tab, web calendar inclusion, PHP ... diff --git a/gramps/plugins/webreport/person.py b/gramps/plugins/webreport/person.py index 92332f6eb..ed82d80bc 100644 --- a/gramps/plugins/webreport/person.py +++ b/gramps/plugins/webreport/person.py @@ -63,7 +63,7 @@ from gramps.gen.display.name import displayer as _nd from gramps.gen.display.place import displayer as _pd from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback from gramps.plugins.lib.libhtml import Html -from gramps.gen.utils.place import conv_lat_lon +from gramps.gen.utils.place import conv_lat_lon, coord_formats from gramps.gen.proxy import LivingProxyDb from gramps.gen.relationship import get_relationship_calculator @@ -794,7 +794,8 @@ class PersonPages(BasePage): miny, maxy = Decimal(miny), Decimal(maxy) midy_ = str(Decimal((miny + maxy) /2)) - midx_, midy_ = conv_lat_lon(midx_, midy_, "D.D8") + midx_, midy_ = conv_lat_lon(midx_, midy_, + coord_formats[self.report.options['coord_format']]) # get the integer span of latitude and longitude dummy_spanx = int(maxx - minx) diff --git a/gramps/plugins/webreport/place.py b/gramps/plugins/webreport/place.py index cd42a1048..8325c63db 100644 --- a/gramps/plugins/webreport/place.py +++ b/gramps/plugins/webreport/place.py @@ -53,7 +53,7 @@ from gramps.gen.lib import (PlaceType, Place, PlaceName, Media) from gramps.gen.plug.report import Bibliography from gramps.gen.mime import is_image_type from gramps.plugins.lib.libhtml import Html -from gramps.gen.utils.place import conv_lat_lon +from gramps.gen.utils.place import conv_lat_lon, coord_formats from gramps.gen.utils.location import get_main_location from gramps.gen.display.place import displayer as _pd @@ -165,7 +165,9 @@ class PlacePages(BasePage): def __output_place(self, ldatec, tbody, first_place, pname, sname, cname, place_handle, letter, bucket_link): - place = self.r_db.get_place_from_handle(place_handle) + place = None + if place_handle: + place = self.r_db.get_place_from_handle(place_handle) if place: if place.get_change_time() > ldatec: ldatec = place.get_change_time() @@ -217,7 +219,7 @@ class PlacePages(BasePage): trow += tcell1, tcell2 if place.lat and place.long: latitude, longitude = conv_lat_lon(place.lat, place.long, - "DEG") + coord_formats[self.report.options['coord_format']]) tcell1 += latitude tcell2 += longitude else: @@ -339,16 +341,20 @@ class PlacePages(BasePage): continue val = self.report.obj_dict[PlaceName][pname] nbelem = len(val) - if nbelem == 4: + if nbelem > 3: place = self.r_db.get_place_from_handle( place_handle) main_location = get_main_location(self.r_db, place) sname = main_location.get(PlaceType.STATE, '') cname = main_location.get(PlaceType.COUNTRY, '') - else: + elif nbelem == 3: cname = val[3] sname = val[2] + else: + val = [""] + cname = "" + sname = "" (ldatec, first_place) \ = self.__output_place(ldatec, trow, first_place,