Geography: better management when closing database

This commit is contained in:
SNoiraud
2022-03-01 22:12:18 +00:00
committed by Nick Hall
parent 053ed269b3
commit 84d523a109
22 changed files with 825 additions and 845 deletions

View File

@@ -178,7 +178,6 @@ register('export.proxy-order',
register('geography.center-lon', 0.0) register('geography.center-lon', 0.0)
register('geography.lock', False) register('geography.lock', False)
register('geography.center-lat', 0.0) register('geography.center-lat', 0.0)
register('geography.map', "person")
register('geography.map_service', 1) register('geography.map_service', 1)
register('geography.zoom', 0) register('geography.zoom', 0)
register('geography.zoom_when_center', 12) register('geography.zoom_when_center', 12)

View File

@@ -34,10 +34,6 @@ from gi.repository import Gtk
# the print settings to remember between print sessions # the print settings to remember between print sessions
PRINT_SETTINGS = None PRINT_SETTINGS = None
# pylint: disable=no-member
# pylint: disable=maybe-no-member
# pylint: disable=unused-argument
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# CairoPrintSave class # CairoPrintSave class
@@ -132,6 +128,9 @@ class CairoPrintSave:
def on_draw_page(self, operation, context, page_nr): def on_draw_page(self, operation, context, page_nr):
"""Draw a page on a Cairo context. """Draw a page on a Cairo context.
""" """
dummy_op = operation
dummy_ct = context
dummy_pg = page_nr
ctx = context.get_cairo_context() ctx = context.get_cairo_context()
self.drawfunc(self.parent, ctx) self.drawfunc(self.parent, ctx)
@@ -141,6 +140,9 @@ class CairoPrintSave:
default application is set with gir 3.3.2 (typically evince not default application is set with gir 3.3.2 (typically evince not
installed)! installed)!
""" """
dummy_op = operation
dummy_ct = context
dummy_pr = preview
dummy_pa = parent
operation.run(Gtk.PrintOperationAction.PREVIEW, None) operation.run(Gtk.PrintOperationAction.PREVIEW, None)
return False return False

View File

@@ -25,12 +25,13 @@
# standard python modules # standard python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.lib import EventType
import os import os
from gramps.gen.const import HOME_DIR
import gi import gi
gi.require_version('OsmGpsMap', '1.0')
from gi.repository import OsmGpsMap as osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
from gramps.gen.lib import EventType
from gramps.gen.const import HOME_DIR
gi.require_version('OsmGpsMap', '1.0')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -39,8 +40,6 @@ from gi.repository import OsmGpsMap as osmgpsmap
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
GEOGRAPHY_PATH = os.path.join(HOME_DIR, "maps") GEOGRAPHY_PATH = os.path.join(HOME_DIR, "maps")
# pylint: disable=bad-whitespace
ICONS = { ICONS = {
EventType.BIRTH : 'gramps-geo-birth', EventType.BIRTH : 'gramps-geo-birth',
EventType.DEATH : 'gramps-geo-death', EventType.DEATH : 'gramps-geo-death',
@@ -119,4 +118,3 @@ MAP_TYPE = {
VIRTUAL_EARTH_HYBRID : osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID, VIRTUAL_EARTH_HYBRID : osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID,
PERSONAL : None, PERSONAL : None,
} }

View File

@@ -25,15 +25,8 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.datelayer") import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -41,7 +34,7 @@ _LOG = logging.getLogger("maps.datelayer")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk from gi.repository import Gdk
import cairo from gi.repository import GObject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -58,12 +51,17 @@ from gramps.gen.config import config
try: try:
import gi import gi
gi.require_version('OsmGpsMap', '1.0')
from gi.repository import OsmGpsMap as osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
gi.require_version('OsmGpsMap', '1.0')
except: except:
raise raise
# pylint: disable=unused-argument #------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.datelayer")
class DateLayer(GObject.GObject, osmgpsmap.MapLayer): class DateLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -117,6 +115,7 @@ class DateLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
Draw the two extreme dates Draw the two extreme dates
""" """
dummy_map = gpsmap
ctx.select_font_face(self.font, ctx.select_font_face(self.font,
cairo.FONT_SLANT_NORMAL, cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_NORMAL) cairo.FONT_WEIGHT_NORMAL)
@@ -150,7 +149,8 @@ class DateLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
When we press a button. When we press a button.
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(DateLayer) GObject.type_register(DateLayer)

View File

@@ -25,15 +25,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.dummylayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -46,7 +38,7 @@ _LOG = logging.getLogger("maps.dummylayer")
# osmGpsMap # osmGpsMap
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
try: try:
import gi import gi
gi.require_version('OsmGpsMap', '1.0') gi.require_version('OsmGpsMap', '1.0')
@@ -54,7 +46,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument #------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.dummylayer")
class DummyLayer(GObject.GObject, osmgpsmap.MapLayer): class DummyLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -88,7 +85,8 @@ class DummyLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
Someone press a button Someone press a button
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(DummyLayer) GObject.type_register(DummyLayer)

View File

@@ -25,15 +25,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.dummynogps")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -46,7 +38,7 @@ _LOG = logging.getLogger("maps.dummynogps")
# osmGpsMap # osmGpsMap
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
try: try:
import gi import gi
gi.require_version('OsmGpsMap', '1.0') gi.require_version('OsmGpsMap', '1.0')
@@ -54,6 +46,13 @@ try:
except: except:
raise raise
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.dummynogps")
class DummyMapNoGpsPoint(osmgpsmap.Map): class DummyMapNoGpsPoint(osmgpsmap.Map):
""" . """ """ . """
def do_draw_gps_point(self, drawable): def do_draw_gps_point(self, drawable):
@@ -61,4 +60,3 @@ class DummyMapNoGpsPoint(osmgpsmap.Map):
pass pass
GObject.type_register(DummyMapNoGpsPoint) GObject.type_register(DummyMapNoGpsPoint)

View File

@@ -23,31 +23,31 @@
""" """
This module is the base class for all geography view module This module is the base class for all geography view module
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import os import os
import re import re
import time import time
import logging import logging
import gi import gi
from gi.repository import GLib
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import GLib
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import OsmGpsMap as osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.gen.lib import EventType, Place, PlaceRef, PlaceName from gramps.gen.lib import EventType, Place, PlaceRef, PlaceName
from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import displayer as _nd
from gramps.gen.display.place import displayer as _pd from gramps.gen.display.place import displayer as _pd
@@ -68,30 +68,31 @@ from .placeselection import PlaceSelection
from .cairoprint import CairoPrintSave from .cairoprint import CairoPrintSave
from .libkml import Kml from .libkml import Kml
gi.require_version('OsmGpsMap', '1.0') gi.require_version('OsmGpsMap', '1.0')
_ = glocale.translation.sgettext
#------------------------------------------------------------------------ # ------------------------------------------------------------------------
# #
# Set up logging # Set up logging
# #
#------------------------------------------------------------------------ # ------------------------------------------------------------------------
_LOG = logging.getLogger("maps.geography") _LOG = logging.getLogger("maps.geography")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_ = glocale.translation.sgettext
GEOGRAPHY_PATH = os.path.join(HOME_DIR, "maps") GEOGRAPHY_PATH = os.path.join(HOME_DIR, "maps")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Functions and variables # Functions and variables
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
PLACE_REGEXP = re.compile('<span background="green">(.*)</span>') PLACE_REGEXP = re.compile('<span background="green">(.*)</span>')
PLACE_STRING = '<span background="green">%s</span>' PLACE_STRING = '<span background="green">%s</span>'
def _get_sign(value): def _get_sign(value):
""" """
return 1 if we have a negative number, 0 in other case return 1 if we have a negative number, 0 in other case
@@ -101,17 +102,18 @@ def _get_sign(value):
else: else:
return 0 return 0
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
# #
# GeoGraphyView # GeoGraphyView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoGraphyView(OsmGps, NavigationView): class GeoGraphyView(OsmGps, NavigationView):
""" """
View for pedigree tree. View for pedigree tree.
Displays the ancestors of a selected individual. Displays the ancestors of a selected individual.
""" """
#settings in the config file # settings in the config file
CONFIGSETTINGS = ( CONFIGSETTINGS = (
('geography.path', GEOGRAPHY_PATH), ('geography.path', GEOGRAPHY_PATH),
@@ -152,8 +154,8 @@ class GeoGraphyView(OsmGps, NavigationView):
else: else:
self.tile_path_ok = False self.tile_path_ok = False
try: try:
os.makedirs(tile_path, 0o755) # create dir like mkdir -p os.makedirs(tile_path, 0o755) # create dir like mkdir -p
except: except Exception:
from gramps.gui.dialog import WarningDialog from gramps.gui.dialog import WarningDialog
WarningDialog(_("Tile path"), WarningDialog(_("Tile path"),
_("The tile directory doesn't exist anymore:" _("The tile directory doesn't exist anymore:"
@@ -176,6 +178,8 @@ class GeoGraphyView(OsmGps, NavigationView):
self.without = 0 self.without = 0
self.place_list = [] self.place_list = []
self.places_found = [] self.places_found = []
self.place_list_active = []
self.place_list_ref = []
self.select_fct = None self.select_fct = None
self.geo_mainmap = None self.geo_mainmap = None
self.reloadtiles = None self.reloadtiles = None
@@ -208,18 +212,18 @@ class GeoGraphyView(OsmGps, NavigationView):
self.nbplaces = 0 self.nbplaces = 0
self.nbmarkers = 0 self.nbmarkers = 0
self.place_without_coordinates = [] self.place_without_coordinates = []
self.stop = False
def font_changed(self): def font_changed(self):
""" """
The font or the death symbol changed. The font or the death symbol changed.
""" """
self.build_tree() self.goto_handle(None)
def add_bookmark(self, menu): def add_bookmark(self, *obj):
""" """
Add the place to the bookmark Add the place to the bookmark
""" """
dummy_menu = menu
mlist = self.selected_handles() mlist = self.selected_handles()
if mlist: if mlist:
self.bookmarks.add(mlist[0]) self.bookmarks.add(mlist[0])
@@ -291,14 +295,28 @@ class GeoGraphyView(OsmGps, NavigationView):
def clear_view(self): def clear_view(self):
""" """
We have no database.
Clear the map: places, markers, tracks, messages... Clear the map: places, markers, tracks, messages...
""" """
if self.osm is not None: if self.osm is not None:
self.place_list = []
self.remove_all_markers() self.remove_all_markers()
self.remove_all_gps() self.remove_all_gps()
self.remove_all_tracks() self.remove_all_tracks()
self.message_layer.clear_messages() self.message_layer.clear_messages()
self.lifeway_layer.clear_ways()
self.date_layer.clear_dates()
self.message_layer.set_font_attributes(None, None, None)
self.kml_layer.clear()
self.place_list = []
self.place_list_active = []
self.place_list_ref = []
self.sort = []
self.places_found = []
self.place_without_coordinates = []
# In case we have some methods running while no database.
self.stop = True
def change_db(self, dbse): def change_db(self, dbse):
""" """
@@ -308,7 +326,9 @@ class GeoGraphyView(OsmGps, NavigationView):
is no need to store the database, since we will get the value is no need to store the database, since we will get the value
from self.state.db from self.state.db
""" """
dummy_dbse = dbse if dbse.__class__.__name__ == "DummyDb":
return
self.stop = False
if self.active: if self.active:
self.bookmarks.redraw() self.bookmarks.redraw()
if self.osm is not None: if self.osm is not None:
@@ -362,11 +382,11 @@ class GeoGraphyView(OsmGps, NavigationView):
dummy_data = data dummy_data = data
config.set("geography.zoom_when_center", int(entry)) config.set("geography.zoom_when_center", int(entry))
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Map Menu # Map Menu
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
def build_nav_menu(self, osm, event, lat, lon): def build_nav_menu(self, osm, event, lat, lon):
""" """
Builds the menu for actions on the map. Builds the menu for actions on the map.
@@ -421,7 +441,7 @@ class GeoGraphyView(OsmGps, NavigationView):
menu.append(add_item) menu.append(add_item)
map_name = constants.MAP_TITLE[config.get("geography.map_service")] map_name = constants.MAP_TITLE[config.get("geography.map_service")]
title = _("Replace '%(map)s' by =>") % {'map' : map_name} title = _("Replace '%(map)s' by =>") % {'map': map_name}
add_item = Gtk.MenuItem(label=title) add_item = Gtk.MenuItem(label=title)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
@@ -438,7 +458,7 @@ class GeoGraphyView(OsmGps, NavigationView):
changemap.append(changemapitem) changemap.append(changemapitem)
reload_text = _("Reload all visible tiles for '%(map)s'.") % { reload_text = _("Reload all visible tiles for '%(map)s'.") % {
'map' : map_name} 'map': map_name}
self.reloadtiles = Gtk.MenuItem(label=reload_text) self.reloadtiles = Gtk.MenuItem(label=reload_text)
reloadtiles = self.reloadtiles reloadtiles = self.reloadtiles
reloadtiles.connect("activate", self.reload_visible_tiles) reloadtiles.connect("activate", self.reload_visible_tiles)
@@ -447,7 +467,7 @@ class GeoGraphyView(OsmGps, NavigationView):
menu.append(reloadtiles) menu.append(reloadtiles)
clear_text = _("Clear the '%(map)s' tiles cache.") % { clear_text = _("Clear the '%(map)s' tiles cache.") % {
'map' : map_name} 'map': map_name}
self.clearmap = Gtk.MenuItem(label=clear_text) self.clearmap = Gtk.MenuItem(label=clear_text)
clearmap = self.clearmap clearmap = self.clearmap
clearmap.connect("activate", self.clear_map, clearmap.connect("activate", self.clear_map,
@@ -495,11 +515,11 @@ class GeoGraphyView(OsmGps, NavigationView):
config.get("geography.zoom_when_center")) config.get("geography.zoom_when_center"))
self.save_center(lat, lon) self.save_center(lat, lon)
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
# #
# Markers management # Markers management
# #
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
def is_there_a_marker_here(self, event, lat, lon): def is_there_a_marker_here(self, event, lat, lon):
""" """
Is there a marker at this position ? Is there a marker at this position ?
@@ -510,18 +530,18 @@ class GeoGraphyView(OsmGps, NavigationView):
for mark in self.sort: for mark in self.sort:
# as we are not precise with our hand, reduce the precision # as we are not precise with our hand, reduce the precision
# depending on the zoom. # depending on the zoom.
precision = {1 : '%3.0f', 2 : '%3.1f', 3 : '%3.1f', 4 : '%3.1f', precision = {1: '%3.0f', 2: '%3.1f', 3: '%3.1f', 4: '%3.1f',
5 : '%3.2f', 6 : '%3.2f', 7 : '%3.2f', 8 : '%3.3f', 5: '%3.2f', 6: '%3.2f', 7: '%3.2f', 8: '%3.3f',
9 : '%3.3f', 10 : '%3.3f', 11 : '%3.3f', 12 : '%3.3f', 9: '%3.3f', 10: '%3.3f', 11: '%3.3f', 12: '%3.3f',
13 : '%3.3f', 14 : '%3.4f', 15 : '%3.4f', 16 : '%3.4f', 13: '%3.3f', 14: '%3.4f', 15: '%3.4f', 16: '%3.4f',
17 : '%3.4f', 18 : '%3.4f' 17: '%3.4f', 18: '%3.4f'
}.get(config.get("geography.zoom"), '%3.1f') }.get(config.get("geography.zoom"), '%3.1f')
shift = {1 : 5.0, 2 : 5.0, 3 : 3.0, shift = {1: 5.0, 2: 5.0, 3: 3.0,
4 : 1.0, 5 : 0.5, 6 : 0.3, 7 : 0.15, 4: 1.0, 5: 0.5, 6: 0.3, 7: 0.15,
8 : 0.06, 9 : 0.03, 10 : 0.015, 8: 0.06, 9: 0.03, 10: 0.015,
11 : 0.005, 12 : 0.003, 13 : 0.001, 11: 0.005, 12: 0.003, 13: 0.001,
14 : 0.0005, 15 : 0.0003, 16 : 0.0001, 14: 0.0005, 15: 0.0003, 16: 0.0001,
17 : 0.0001, 18 : 0.0001 17: 0.0001, 18: 0.0001
}.get(config.get("geography.zoom"), 5.0) }.get(config.get("geography.zoom"), 5.0)
latp = precision % lat latp = precision % lat
lonp = precision % lon lonp = precision % lon
@@ -584,7 +604,7 @@ class GeoGraphyView(OsmGps, NavigationView):
if event_type is not None: if event_type is not None:
value = self.geo_othermap.get(int(event_type), default_image) value = self.geo_othermap.get(int(event_type), default_image)
if differtype: # in case multiple evts if differtype: # in case multiple evts
value = default_image # we use default icon. value = default_image # we use default icon.
self.marker_layer.add_marker((float(lat), float(lon)), value, self.marker_layer.add_marker((float(lat), float(lon)), value,
count, color=color) count, color=color)
@@ -619,8 +639,7 @@ class GeoGraphyView(OsmGps, NavigationView):
def _append_to_places_list(self, place, evttype, name, lat, def _append_to_places_list(self, place, evttype, name, lat,
longit, descr, year, icontype, longit, descr, year, icontype,
gramps_id, place_id, event_id, family_id, gramps_id, place_id, event_id, family_id,
color=None color=None):
):
""" """
Create a list of places with coordinates. Create a list of places with coordinates.
""" """
@@ -635,8 +654,7 @@ class GeoGraphyView(OsmGps, NavigationView):
self.place_list.append([place, name, evttype, lat, self.place_list.append([place, name, evttype, lat,
longit, descr, year, icontype, longit, descr, year, icontype,
gramps_id, place_id, event_id, family_id, gramps_id, place_id, event_id, family_id,
color color])
])
self.nbmarkers += 1 self.nbmarkers += 1
tfa = float(lat) tfa = float(lat)
tfb = float(longit) tfb = float(longit)
@@ -710,7 +728,7 @@ class GeoGraphyView(OsmGps, NavigationView):
lon = mark[4] lon = mark[4]
icon = mark[7] icon = mark[7]
colour = mark[12] colour = mark[12]
else: # This marker already exists. add info. else: # This marker already exists. add info.
count += 1 count += 1
if icon != mark[7]: if icon != mark[7]:
differtype = True differtype = True
@@ -799,7 +817,7 @@ class GeoGraphyView(OsmGps, NavigationView):
we start at zoom 1 until zoom y ( for this a preference ) we start at zoom 1 until zoom y ( for this a preference )
If all markers are present, continue to zoom. If all markers are present, continue to zoom.
If some markers are missing : return to the zoom - 1 If some markers are missing : return to the zoom - 1
The following is too complex. In some case, all markers are not present. The following is too complex. In some case, all markers are not present
""" """
# Select the center of the map and the zoom # Select the center of the map and the zoom
current = osmgpsmap.MapPoint.new_degrees(self.minlat, self.minlon) current = osmgpsmap.MapPoint.new_degrees(self.minlat, self.minlon)
@@ -839,11 +857,11 @@ class GeoGraphyView(OsmGps, NavigationView):
mnam = _nd.display(mother) if mother else _("Unknown") mnam = _nd.display(mother) if mother else _("Unknown")
return (fnam, mnam) return (fnam, mnam)
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
# #
# KML functionalities # KML functionalities
# #
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
def load_kml_files(self, obj): def load_kml_files(self, obj):
""" """
obj can be an event, a person or a place obj can be an event, a person or a place
@@ -852,7 +870,8 @@ class GeoGraphyView(OsmGps, NavigationView):
if media_list: if media_list:
for media_ref in media_list: for media_ref in media_list:
object_handle = media_ref.get_reference_handle() object_handle = media_ref.get_reference_handle()
media_obj = self.dbstate.db.get_media_from_handle(object_handle) media_obj = self.dbstate.db.get_media_from_handle(
object_handle)
path = media_obj.get_path() path = media_obj.get_path()
dummy_name, extension = os.path.splitext(path) dummy_name, extension = os.path.splitext(path)
if extension == ".kml": if extension == ".kml":
@@ -860,11 +879,11 @@ class GeoGraphyView(OsmGps, NavigationView):
if os.path.isfile(path): if os.path.isfile(path):
self.kml_layer.add_kml(path) self.kml_layer.add_kml(path)
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Printing functionalities # Printing functionalities
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
def printview(self, *obj): def printview(self, *obj):
""" """
Print or save the view that is currently shown Print or save the view that is currently shown
@@ -884,11 +903,11 @@ class GeoGraphyView(OsmGps, NavigationView):
prt = CairoPrintSave(widthpx, heightpx, self.osm.do_draw, self.osm) prt = CairoPrintSave(widthpx, heightpx, self.osm.do_draw, self.osm)
prt.run() prt.run()
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Specific functionalities # Specific functionalities
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
def center_here(self, menu, event, lat, lon, mark): def center_here(self, menu, event, lat, lon, mark):
""" """
Center the map at the marker position Center the map at the marker position
@@ -1062,8 +1081,8 @@ class GeoGraphyView(OsmGps, NavigationView):
def link_place(self, menu, event, lat, lon): def link_place(self, menu, event, lat, lon):
""" """
Link an existing place using longitude and latitude of location centered Link an existing place using longitude and latitude of location
on the map centered on the map
If we have a place history, we must show all places to avoid an empty If we have a place history, we must show all places to avoid an empty
place selection in the PlaceSelection. place selection in the PlaceSelection.
""" """
@@ -1101,8 +1120,8 @@ class GeoGraphyView(OsmGps, NavigationView):
"You should eiher rename the places or merge them.\n\n" "You should eiher rename the places or merge them.\n\n"
"%(bold_start)s" "%(bold_start)s"
"I can't proceed with your request" "I can't proceed with your request"
"%(bold_end)s.\n") % {'bold_start' : '<b>', "%(bold_end)s.\n") % {'bold_start': '<b>',
'bold_end' : '</b>', 'bold_end': '</b>',
'title': '<b>' + ptitle + '</b>', 'title': '<b>' + ptitle + '</b>',
'gid': gids}, 'gid': gids},
parent=self.uistate.window) parent=self.uistate.window)
@@ -1182,8 +1201,8 @@ class GeoGraphyView(OsmGps, NavigationView):
def __link_place(self, parent, plat, plon): def __link_place(self, parent, plat, plon):
""" """
Link an existing place using longitude and latitude of location centered Link an existing place using longitude and latitude of location
on the map centered on the map
""" """
selector = SelectPlace(self.dbstate, self.uistate, []) selector = SelectPlace(self.dbstate, self.uistate, [])
place = selector.run() place = selector.run()
@@ -1201,11 +1220,11 @@ class GeoGraphyView(OsmGps, NavigationView):
except WindowActiveError: except WindowActiveError:
pass pass
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
# #
# Geography preferences # Geography preferences
# #
#------------------------------------------------------------------------- # ------------------------------------------------------------------------
def _get_configure_page_funcs(self): def _get_configure_page_funcs(self):
""" """
The function which is used to create the configuration window. The function which is used to create the configuration window.
@@ -1274,25 +1293,26 @@ class GeoGraphyView(OsmGps, NavigationView):
0, self.path_entry, 0, self.path_entry,
config.get('geography.path'), config.get('geography.path'),
self.set_tilepath, self.select_tilepath) self.set_tilepath, self.select_tilepath)
configdialog.add_text(grid, configdialog.add_text(
_('If you have no more space in your file system.' grid,
' You can remove all tiles placed in the above' _('If you have no more space in your file system.'
' path.\nBe careful! If you have no internet,' ' You can remove all tiles placed in the above'
' you\'ll get no map.'), ' path.\nBe careful! If you have no internet,'
2, line_wrap=False) ' you\'ll get no map.'),
2, line_wrap=False)
configdialog.add_slider(grid, _('Zoom used when centering'), configdialog.add_slider(grid, _('Zoom used when centering'),
3, 'geography.zoom_when_center', 3, 'geography.zoom_when_center', (2, 16))
(2, 16)) configdialog.add_slider(grid,
configdialog.add_slider(grid, _('The maximum number of places to show'), _('The maximum number of places to show'),
4, 'geography.max_places', 4, 'geography.max_places', (1000, 10000))
(1000, 10000)) configdialog.add_checkbox(
configdialog.add_checkbox(grid, grid,
_('Use keypad for shortcuts :\nEither we ' _('Use keypad for shortcuts :\nEither we '
'choose the + and - from the keypad if we ' 'choose the + and - from the keypad if we '
'select this,\nor we use the characters ' 'select this,\nor we use the characters '
'from the keyboard.'), 'from the keyboard.'),
5, 'geography.use-keypad', 5, 'geography.use-keypad',
extra_callback=self.update_shortcuts) extra_callback=self.update_shortcuts)
label = configdialog.add_text( label = configdialog.add_text(
grid, grid,
_('If you want to use a specific map provider,' _('If you want to use a specific map provider,'
@@ -1309,10 +1329,9 @@ class GeoGraphyView(OsmGps, NavigationView):
start = label.get_text().find("http") start = label.get_text().find("http")
end = label.get_text().find("http", start + 1) end = label.get_text().find("http", start + 1)
label.select_region(start, end) label.select_region(start, end)
url = configdialog.add_entry(grid, _("Personal map"), url = configdialog.add_entry(
7, 'geography.personal-map', grid, _("Personal map"),
self.choosen_map, 7, 'geography.personal-map', self.choosen_map,)
)
if config.get('geography.personal-map') != "": if config.get('geography.personal-map') != "":
url.set_text(config.get('geography.personal-map')) url.set_text(config.get('geography.personal-map'))
return _('The map'), grid return _('The map'), grid
@@ -1323,18 +1342,14 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
map_source = obj[0].get_text() map_source = obj[0].get_text()
name = constants.TILES_PATH[constants.PERSONAL] name = constants.TILES_PATH[constants.PERSONAL]
print(self.current_map, constants.PERSONAL,
map_source, config.get('geography.personal-map'))
config.set('geography.personal-map', map_source) config.set('geography.personal-map', map_source)
self.clear_map(None, name) self.clear_map(None, name)
if map_source == "": if map_source == "":
print("reset osm")
config.set("geography.map_service", constants.OPENSTREETMAP) config.set("geography.map_service", constants.OPENSTREETMAP)
self.change_map(self.osm, config.get("geography.map_service")) self.change_map(self.osm, config.get("geography.map_service"))
self.reload_tiles() self.reload_tiles()
return return
if map_source != config.get('geography.personal-map'): if map_source != config.get('geography.personal-map'):
print("set personal")
config.set("geography.map_service", constants.PERSONAL) config.set("geography.map_service", constants.PERSONAL)
self.change_new_map(name, map_source) self.change_new_map(name, map_source)
self.reload_tiles() self.reload_tiles()

View File

@@ -25,22 +25,16 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.kmllayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk
import cairo import cairo
from gi.repository import Gdk
from gi.repository import GObject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -57,14 +51,17 @@ from .libkml import Kml
try: try:
import gi import gi
gi.require_version('OsmGpsMap', '1.0')
from gi.repository import OsmGpsMap as osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
gi.require_version('OsmGpsMap', '1.0')
except: except:
raise raise
# pylint: disable=unused-variable #------------------------------------------------------------------------
# pylint: disable=unused-argument #
# pylint: disable=no-member # Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.kmllayer")
class KmlLayer(GObject.GObject, osmgpsmap.MapLayer): class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -118,7 +115,8 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
color2 = Gdk.color_parse('blue') color2 = Gdk.color_parse('blue')
for polygons in self.polygons: for polygons in self.polygons:
for polygon in polygons: for polygon in polygons:
(name, ptype, color, transparency, points) = polygon (dummy_name, ptype, dummy_color,
dummy_transparency, points) = polygon
map_points = [] map_points = []
for point in points: for point in points:
conv_pt = osmgpsmap.MapPoint.new_degrees(point[0], point[1]) conv_pt = osmgpsmap.MapPoint.new_degrees(point[0], point[1])
@@ -155,7 +153,8 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
ctx.restore() ctx.restore()
for paths in self.paths: for paths in self.paths:
for path in paths: for path in paths:
(name, ptype, color, transparency, points) = path (dummy_name, ptype, dummy_color,
dummy_transparency, points) = path
map_points = [] map_points = []
for point in points: for point in points:
conv_pt = osmgpsmap.MapPoint.new_degrees(point[0], point[1]) conv_pt = osmgpsmap.MapPoint.new_degrees(point[0], point[1])
@@ -185,7 +184,7 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
render the layer render the layer
""" """
pass dummy_map = gpsmap
def do_busy(self): def do_busy(self):
""" """
@@ -197,6 +196,8 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
When we press a button. When we press a button.
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(KmlLayer) GObject.type_register(KmlLayer)

View File

@@ -26,19 +26,17 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
from gi.repository import GObject import logging
import xml.etree.ElementTree as ETree import xml.etree.ElementTree as ETree
from gi.repository import GObject
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Set up logging # Set up logging
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging
_LOG = logging.getLogger("maps.libkml") _LOG = logging.getLogger("maps.libkml")
# pylint: disable=unused-variable
class Kml(GObject.GObject): class Kml(GObject.GObject):
""" """
This is the library used to read kml files This is the library used to read kml files
@@ -72,8 +70,8 @@ class Kml(GObject.GObject):
root = self.tree.getroot() root = self.tree.getroot()
self.tag = root.tag.replace('}kml', '}') self.tag = root.tag.replace('}kml', '}')
_LOG.debug("Tag version of kml file %s is %s", kml_file, self.tag) _LOG.debug("Tag version of kml file %s is %s", kml_file, self.tag)
fname, extension = os.path.splitext(kml_file) fname, dummy_extension = os.path.splitext(kml_file)
fdir, self.kmlfile = os.path.split(fname) dummy_fdir, self.kmlfile = os.path.split(fname)
def set_default(self): def set_default(self):
""" """
@@ -103,7 +101,7 @@ class Kml(GObject.GObject):
self.points = [] self.points = []
for point in attributes.text.split(): for point in attributes.text.split():
try: try:
(longitude, latitude, altitude) = point.split(',') (longitude, latitude, dummy_altitude) = point.split(',')
except: except:
(longitude, latitude) = point.split(',') (longitude, latitude) = point.split(',')
self.points.append((float(latitude), float(longitude))) self.points.append((float(latitude), float(longitude)))

View File

@@ -25,16 +25,10 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
from math import pi
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.lifeway") from math import pi
import cairo
from gi.repository import GObject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -42,7 +36,6 @@ _LOG = logging.getLogger("maps.lifeway")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk from gi.repository import Gdk
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -63,7 +56,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument #------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.lifeway")
class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer): class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -122,16 +120,16 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
for point in lifeway[0]: for point in lifeway[0]:
conv_pt1 = osmgpsmap.MapPoint.new_degrees(point[0], point[1]) conv_pt1 = osmgpsmap.MapPoint.new_degrees(point[0], point[1])
coord_x1, coord_y1 = gpsmap.convert_geographic_to_screen( coord_x1, coord_y1 = gpsmap.convert_geographic_to_screen(
conv_pt1) conv_pt1)
conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0]+rds, conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0]+rds,
point[1]) point[1])
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen( coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(
conv_pt2) conv_pt2)
coy = abs(coord_y2-coord_y1) coy = abs(coord_y2-coord_y1)
conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0], conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0],
point[1]+rds) point[1]+rds)
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen( coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(
conv_pt2) conv_pt2)
cox = abs(coord_x2-coord_x1) cox = abs(coord_x2-coord_x1)
cox = cox if cox > 1.2 else 1.2 cox = cox if cox > 1.2 else 1.2
coy = coy if coy > 1.2 else 1.2 coy = coy if coy > 1.2 else 1.2
@@ -192,7 +190,8 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
When we press a button. When we press a button.
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(LifeWayLayer) GObject.type_register(LifeWayLayer)

View File

@@ -25,10 +25,11 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import time
import logging
from math import pi as PI
from gi.repository import GObject from gi.repository import GObject
from gi.repository import Gdk from gi.repository import Gdk
import time
from math import pi as PI
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -36,7 +37,6 @@ from math import pi as PI
# Set up logging # Set up logging
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging
_LOG = logging.getLogger("maps.markerlayer") _LOG = logging.getLogger("maps.markerlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -64,8 +64,6 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer): class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display the markers. This is the layer used to display the markers.
@@ -122,7 +120,7 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
if min_interval <= 0: # This to avoid divide by zero if min_interval <= 0: # This to avoid divide by zero
min_interval = 0.01 min_interval = 0.01
_LOG.debug("%s", time.strftime("start drawing : " _LOG.debug("%s", time.strftime("start drawing : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
for marker in self.markers: for marker in self.markers:
# the icon size in 48, so the standard icon size is 0.6 * 48 = 28.8 # the icon size in 48, so the standard icon size is 0.6 * 48 = 28.8
size = 0.6 size = 0.6
@@ -130,16 +128,16 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
if mark > self.nb_ref_by_places or max_interval > 3: if mark > self.nb_ref_by_places or max_interval > 3:
# at maximum, we'll have an icon size = (0.6 + 0.2) * 48 = 38.4 # at maximum, we'll have an icon size = (0.6 + 0.2) * 48 = 38.4
size += (0.2 * ((mark - self.nb_ref_by_places) size += (0.2 * ((mark - self.nb_ref_by_places)
/ max_interval)) / max_interval))
else: else:
# at minimum, we'll have an icon size = (0.6 - 0.2) * 48 = 19.2 # at minimum, we'll have an icon size = (0.6 - 0.2) * 48 = 19.2
size -= (0.2 * ((self.nb_ref_by_places - mark) size -= (0.2 * ((self.nb_ref_by_places - mark)
/ min_interval)) / min_interval))
conv_pt = osmgpsmap.MapPoint.new_degrees(float(marker[0][0]), conv_pt = osmgpsmap.MapPoint.new_degrees(float(marker[0][0]),
float(marker[0][1])) float(marker[0][1]))
coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt) coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt)
if marker[3] == None: if marker[3] is None:
# We use the standard icons. # We use the standard icons.
ctx.save() ctx.save()
ctx.translate(coord_x, coord_y) ctx.translate(coord_x, coord_y)
@@ -159,7 +157,7 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
draw_marker(ctx, float(coord_x), float(coord_y), draw_marker(ctx, float(coord_x), float(coord_y),
size, marker[3][1]) size, marker[3][1])
_LOG.debug("%s", time.strftime("end drawing : " _LOG.debug("%s", time.strftime("end drawing : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
def do_render(self, gpsmap): def do_render(self, gpsmap):
""" """
@@ -177,11 +175,13 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
When we press a button. When we press a button.
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(MarkerLayer) GObject.type_register(MarkerLayer)
def draw_marker(ctx, x1, y1, size, color): def draw_marker(ctx, x01, y01, size, color):
width = 48.0 * size width = 48.0 * size
height = width / 2 height = width / 2
color = Gdk.color_parse(color) color = Gdk.color_parse(color)
@@ -189,39 +189,39 @@ def draw_marker(ctx, x1, y1, size, color):
float(color.green / 65535.0), float(color.green / 65535.0),
float(color.blue / 65535.0), float(color.blue / 65535.0),
1.0) # transparency 1.0) # transparency
ctx.set_line_width (2.0); ctx.set_line_width(2.0)
ctx.move_to(x1, y1) ctx.move_to(x01, y01)
ctx.line_to((x1 + (height/3)), (y1 - height*2)) ctx.line_to((x01 + (height/3)), (y01 - height*2))
ctx.line_to((x1 - (height/3)), (y1 - height*2)) ctx.line_to((x01 - (height/3)), (y01 - height*2))
ctx.fill() ctx.fill()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5) ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.move_to(x1, y1) ctx.move_to(x01, y01)
ctx.line_to((x1 + (height/3)), (y1 - height*2)) ctx.line_to((x01 + (height/3)), (y01 - height*2))
ctx.line_to((x1 - (height/3)), (y1 - height*2)) ctx.line_to((x01 - (height/3)), (y01 - height*2))
ctx.line_to(x1, y1) ctx.line_to(x01, y01)
ctx.stroke() ctx.stroke()
ctx.save() ctx.save()
ctx.translate(x1 + width/4 - (width/4) , y1 - height*2 - (width/4)) ctx.translate(x01 + width/4 - (width/4), y01 - height*2 - (width/4))
ctx.scale(width / 2., height / 2.) ctx.scale(width / 2., height / 2.)
ctx.arc(0., 0., 1., 0., 2 * PI) ctx.arc(0., 0., 1., 0., 2 * PI)
ctx.fill_preserve() ctx.fill_preserve()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5) ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.set_line_width (2.0); ctx.set_line_width(2.0)
ctx.arc(0., 0., 1., 0., 2 * PI) ctx.arc(0., 0., 1., 0., 2 * PI)
ctx.restore() ctx.restore()
ctx.stroke(); ctx.stroke()
ctx.save() ctx.save()
ctx.set_source_rgba(float(color.red / 65535.0), ctx.set_source_rgba(float(color.red / 65535.0),
float(color.green / 65535.0), float(color.green / 65535.0),
float(color.blue / 65535.0), float(color.blue / 65535.0),
1.0) # transparency 1.0) # transparency
#ctx.translate(x1 + width/4 - 12.0 , y1 - height*2 - 12.0) #ctx.translate(x01 + width/4 - 12.0 , y01 - height*2 - 12.0)
ctx.translate(x1 + width/4 - (width/4) , y1 - height*2 - (width/4)) ctx.translate(x01 + width/4 - (width/4), y01 - height*2 - (width/4))
ctx.scale(width / 2., height / 2.) ctx.scale(width / 2., height / 2.)
ctx.arc(0., 0., 1., 0., 2 * PI) ctx.arc(0., 0., 1., 0., 2 * PI)
ctx.fill_preserve() ctx.fill_preserve()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5) ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.set_line_width (2.0); ctx.set_line_width(2.0)
ctx.arc(0., 0., 1., 0., 2 * PI) ctx.arc(0., 0., 1., 0., 2 * PI)
ctx.restore() ctx.restore()
ctx.stroke(); ctx.stroke()

View File

@@ -25,15 +25,8 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.messagelayer") from gi.repository import GObject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -64,9 +57,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-variable #------------------------------------------------------------------------
# pylint: disable=unused-argument #
# pylint: disable=no-member # Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.messagelayer")
class MessageLayer(GObject.GObject, osmgpsmap.MapLayer): class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -120,8 +116,8 @@ class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
Draw all the messages Draw all the messages
""" """
ctx.save() ctx.save()
font_size = "%s %d" % (self.font, self.size) #font_size = "%s %d" % (self.font, self.size)
font = Pango.FontDescription(font_size) #font = Pango.FontDescription(font_size)
descr = Pango.font_description_from_string(self.font) descr = Pango.font_description_from_string(self.font)
descr.set_size(self.size * Pango.SCALE) descr.set_size(self.size * Pango.SCALE)
color = Gdk.color_parse(self.color) color = Gdk.color_parse(self.color)
@@ -152,7 +148,7 @@ class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
render the layer render the layer
""" """
pass dummy_map = gpsmap
def do_busy(self): def do_busy(self):
""" """
@@ -164,7 +160,8 @@ class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
When we press a button. When we press a button.
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(MessageLayer) GObject.type_register(MessageLayer)

View File

@@ -20,37 +20,41 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import os import os
from math import pi, sin, atanh, floor from math import pi, sin, atanh, floor
#------------------------------------------------------------------------ # ------------------------------------------------------------------------
# #
# Set up logging # Set up logging
# #
#------------------------------------------------------------------------ # ------------------------------------------------------------------------
import time import time
import logging import logging
_LOG = logging.getLogger("maps.osmgps")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.plugins.lib.maps import constants from gramps.plugins.lib.maps import constants
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.const import VERSION_DIR
from gramps.gen.config import config
from gramps.gui.dialog import ErrorDialog
from gramps.gen.constfunc import get_env_var
from .dummylayer import DummyLayer from .dummylayer import DummyLayer
from .dummynogps import DummyMapNoGpsPoint from .dummynogps import DummyMapNoGpsPoint
from .selectionlayer import SelectionLayer from .selectionlayer import SelectionLayer
@@ -59,18 +63,15 @@ from .markerlayer import MarkerLayer
from .datelayer import DateLayer from .datelayer import DateLayer
from .messagelayer import MessageLayer from .messagelayer import MessageLayer
from .kmllayer import KmlLayer from .kmllayer import KmlLayer
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from gramps.gen.config import config
from gramps.gui.dialog import ErrorDialog
from gramps.gen.constfunc import get_env_var
from gramps.gen.const import VERSION_DIR
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# OsmGps # OsmGps
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_LOG = logging.getLogger("maps.osmgps")
_ = glocale.translation.sgettext
try: try:
import gi import gi
@@ -79,10 +80,6 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
# pylint: disable=no-member
# pylint: disable=maybe-no-member
def lon2pixel(zoom, longitude, size): def lon2pixel(zoom, longitude, size):
""" """
pixel_x = (2^zoom * size * longitude) / 2PI + (2^zoom * size) / 2 pixel_x = (2^zoom * size * longitude) / 2PI + (2^zoom * size) / 2
@@ -125,6 +122,7 @@ class OsmGps:
self.current_map = None self.current_map = None
self.places_found = None self.places_found = None
self.uistate = uistate self.uistate = uistate
self.zoom = config.get("geography.zoom")
def build_widget(self): def build_widget(self):
""" """
@@ -182,7 +180,7 @@ class OsmGps:
except: except:
ErrorDialog(_("Can't create " ErrorDialog(_("Can't create "
"tiles cache directory for '%s'.") % "tiles cache directory for '%s'.") %
constants.MAP_TITLE[map_type], constants.MAP_TITLE[map_type],
parent=self.uistate.window) parent=self.uistate.window)
config.set("geography.map_service", map_type) config.set("geography.map_service", map_type)
self.current_map = map_type self.current_map = map_type
@@ -190,12 +188,14 @@ class OsmGps:
if 0: if 0:
self.osm = DummyMapNoGpsPoint() self.osm = DummyMapNoGpsPoint()
else: else:
if http_proxy: if map_type == constants.PERSONAL:
self.osm = osmgpsmap.Map(proxy_uri=http_proxy) self.osm = osmgpsmap.Map(repo_uri=map_source)
else: else:
self.osm = osmgpsmap.Map() self.osm = osmgpsmap.Map(
map_source=constants.MAP_TYPE[map_type])
if http_proxy:
self.osm.set_property("proxy_uri", http_proxy)
self.osm.set_property("tile_cache", tiles_path) self.osm.set_property("tile_cache", tiles_path)
self.osm.set_property("map_source", constants.MAP_TYPE[map_type])
self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True) current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
self.end_selection = None self.end_selection = None
@@ -244,19 +244,21 @@ class OsmGps:
except: except:
ErrorDialog(_("Can't create " ErrorDialog(_("Can't create "
"tiles cache directory for '%s'.") % "tiles cache directory for '%s'.") %
constants.MAP_TITLE[self.current_map], constants.MAP_TITLE[self.current_map],
parent=self.uistate.window) parent=self.uistate.window)
http_proxy = get_env_var('http_proxy') http_proxy = get_env_var('http_proxy')
if 0: if 0:
self.osm = DummyMapNoGpsPoint() self.osm = DummyMapNoGpsPoint()
else: else:
if http_proxy: map_type = int(config.get("geography.map_service"))
self.osm = osmgpsmap.Map(tile_cache=tiles_path, if map_type == constants.PERSONAL:
proxy_uri=http_proxy, self.osm = osmgpsmap.Map(repo_uri=map_source)
repo_uri=map_source)
else: else:
self.osm = osmgpsmap.Map(tile_cache=tiles_path, self.osm = osmgpsmap.Map(
repo_uri=map_source) map_source=constants.MAP_TYPE[map_type])
if http_proxy:
self.osm.set_property("proxy_uri", http_proxy)
self.osm.set_property("tile_cache", tiles_path)
self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True) current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
self.end_selection = None self.end_selection = None
@@ -327,8 +329,9 @@ class OsmGps:
arg is mandatory because this function is also called by arg is mandatory because this function is also called by
the checkbox button the checkbox button
""" """
dummy_arg = arg
config.set('geography.use-keypad', config.set('geography.use-keypad',
self._config.get('geography.use-keypad')) self._config.get('geography.use-keypad'))
if config.get('geography.use-keypad'): if config.get('geography.use-keypad'):
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN, self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN,
Gdk.keyval_from_name("KP_Add")) Gdk.keyval_from_name("KP_Add"))
@@ -446,6 +449,7 @@ class OsmGps:
""" """
save the zoom and the position save the zoom and the position
""" """
dummy_zoom = zoom
config.set("geography.zoom", self.osm.props.zoom) config.set("geography.zoom", self.osm.props.zoom)
self.save_center(self.osm.props.latitude, self.osm.props.longitude) self.save_center(self.osm.props.latitude, self.osm.props.longitude)
@@ -462,7 +466,7 @@ class OsmGps:
if layer: if layer:
self.osm.layer_remove(layer) self.osm.layer_remove(layer)
self.selection_layer = self.add_selection_layer() self.selection_layer = self.add_selection_layer()
if self.end_selection == None: if self.end_selection is None:
self.selection_layer.add_rectangle(self.begin_selection, self.selection_layer.add_rectangle(self.begin_selection,
current) current)
else: else:
@@ -498,6 +502,8 @@ class OsmGps:
""" """
Zoom when in zone selection Zoom when in zone selection
""" """
dummy_osm = osm
dummy_evt = event
if self.end_selection is not None: if self.end_selection is not None:
self._autozoom() self._autozoom()
return True return True
@@ -542,28 +548,28 @@ class OsmGps:
return mark_selected return mark_selected
oldplace = "" oldplace = ""
_LOG.debug("%s", time.strftime("start is_there_a_place_here : " _LOG.debug("%s", time.strftime("start is_there_a_place_here : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
for mark in self.places_found: for mark in self.places_found:
# as we are not precise with our hand, reduce the precision # as we are not precise with our hand, reduce the precision
# depending on the zoom. # depending on the zoom.
if mark[0] != oldplace: if mark[0] != oldplace:
oldplace = mark[0] oldplace = mark[0]
precision = { precision = {
1 : '%3.0f', 2 : '%3.1f', 3 : '%3.1f', 1 : '%3.0f', 2 : '%3.1f', 3 : '%3.1f',
4 : '%3.1f', 5 : '%3.2f', 6 : '%3.2f', 4 : '%3.1f', 5 : '%3.2f', 6 : '%3.2f',
7 : '%3.2f', 8 : '%3.3f', 9 : '%3.3f', 7 : '%3.2f', 8 : '%3.3f', 9 : '%3.3f',
10 : '%3.3f', 11 : '%3.3f', 12 : '%3.3f', 10 : '%3.3f', 11 : '%3.3f', 12 : '%3.3f',
13 : '%3.3f', 14 : '%3.4f', 15 : '%3.4f', 13 : '%3.3f', 14 : '%3.4f', 15 : '%3.4f',
16 : '%3.4f', 17 : '%3.4f', 18 : '%3.4f' 16 : '%3.4f', 17 : '%3.4f', 18 : '%3.4f'
}.get(config.get("geography.zoom"), '%3.1f') }.get(config.get("geography.zoom"), '%3.1f')
shift = { shift = {
1 : 5.0, 2 : 5.0, 3 : 3.0, 1 : 5.0, 2 : 5.0, 3 : 3.0,
4 : 1.0, 5 : 0.5, 6 : 0.3, 7 : 0.15, 4 : 1.0, 5 : 0.5, 6 : 0.3, 7 : 0.15,
8 : 0.06, 9 : 0.03, 10 : 0.015, 8 : 0.06, 9 : 0.03, 10 : 0.015,
11 : 0.005, 12 : 0.003, 13 : 0.001, 11 : 0.005, 12 : 0.003, 13 : 0.001,
14 : 0.0005, 15 : 0.0003, 16 : 0.0001, 14 : 0.0005, 15 : 0.0003, 16 : 0.0001,
17 : 0.0001, 18 : 0.0001 17 : 0.0001, 18 : 0.0001
}.get(config.get("geography.zoom"), 5.0) }.get(config.get("geography.zoom"), 5.0)
latp = precision % lat latp = precision % lat
lonp = precision % lon lonp = precision % lon
mlatp = precision % float(mark[1]) mlatp = precision % float(mark[1])
@@ -578,7 +584,7 @@ class OsmGps:
if latok and lonok: if latok and lonok:
mark_selected.append(mark) mark_selected.append(mark)
_LOG.debug("%s", time.strftime(" end is_there_a_place_here : " _LOG.debug("%s", time.strftime(" end is_there_a_place_here : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
return mark_selected return mark_selected
def build_nav_menu(self, osm, event, lat, lon): def build_nav_menu(self, osm, event, lat, lon):

View File

@@ -25,46 +25,38 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
import re import re
import math import math
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.placeselection")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gi import gi
from gi.repository import Gtk from gi.repository import Gtk
try:
gi.require_version('GeocodeGlib', '1.0')
from gi.repository import GeocodeGlib
GEOCODEGLIB = True
except:
GEOCODEGLIB = False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.errors import WindowActiveError from gramps.gen.errors import WindowActiveError
from gramps.gui.managedwindow import ManagedWindow from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.dialog import WarningDialog from gramps.gui.dialog import WarningDialog
from .osmgps import OsmGps
from gramps.gen.utils.location import get_main_location from gramps.gen.utils.location import get_main_location
from gramps.gen.lib import PlaceType from gramps.gen.lib import PlaceType
from gramps.gen.utils.place import conv_lat_lon from gramps.gen.utils.place import conv_lat_lon
from gramps.gen.display.place import displayer as _pd from gramps.gen.display.place import displayer as _pd
from .osmgps import OsmGps
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
try:
gi.require_version('GeocodeGlib', '1.0')
from gi.repository import GeocodeGlib
GEOCODEGLIB = True
except:
GEOCODEGLIB = False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -76,8 +68,13 @@ PLACE_STRING = '<span background="green">%s</span>'
GEOCODE_REGEXP = re.compile('<span background="red">(.*)</span>') GEOCODE_REGEXP = re.compile('<span background="red">(.*)</span>')
GEOCODE_STRING = '<span background="red">%s</span>' GEOCODE_STRING = '<span background="red">%s</span>'
# pylint: disable=unused-argument #------------------------------------------------------------------------
# pylint: disable=no-member #
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.placeselection")
_ = glocale.translation.sgettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -162,8 +159,8 @@ class PlaceSelection(ManagedWindow, OsmGps):
self.label2 = Gtk.Label() self.label2 = Gtk.Label()
self.label2.set_markup('<span background="green" foreground="black"' self.label2.set_markup('<span background="green" foreground="black"'
'>%s</span>' % '>%s</span>' %
_('The green values in the row correspond ' _('The green values in the row correspond '
'to the current place values.')) 'to the current place values.'))
self.label2.set_valign(Gtk.Align.END) self.label2.set_valign(Gtk.Align.END)
self.window.vbox.pack_start(self.label2, False, True, 0) self.window.vbox.pack_start(self.label2, False, True, 0)
self.window.set_default_size(400, 300) self.window.set_default_size(400, 300)
@@ -249,7 +246,7 @@ class PlaceSelection(ManagedWindow, OsmGps):
place = self.dbstate.db.get_place_from_gramps_id(gramps_id) place = self.dbstate.db.get_place_from_gramps_id(gramps_id)
place_name = place.name.get_value() place_name = place.name.get_value()
parent_list = place.get_placeref_list() parent_list = place.get_placeref_list()
while len(parent_list) > 0: while parent_list:
place = self.dbstate.db.get_place_from_handle(parent_list[0].ref) place = self.dbstate.db.get_place_from_handle(parent_list[0].ref)
parent_list = place.get_placeref_list() parent_list = place.get_placeref_list()
if int(place.get_type()) == PlaceType.COUNTY: if int(place.get_type()) == PlaceType.COUNTY:
@@ -280,7 +277,7 @@ class PlaceSelection(ManagedWindow, OsmGps):
# place # place
for entry in self.place_list: for entry in self.place_list:
if (math.hypot(lat-float(entry[3]), if (math.hypot(lat-float(entry[3]),
lon-float(entry[4])) <= rds) == True: lon-float(entry[4])) <= rds):
# Do we already have this place ? avoid duplicates # Do we already have this place ? avoid duplicates
(country, state, county, (country, state, county,
place, other) = self.get_location(entry[9]) place, other) = self.get_location(entry[9])
@@ -291,7 +288,7 @@ class PlaceSelection(ManagedWindow, OsmGps):
latn = place.get_latitude() latn = place.get_latitude()
lonn = place.get_longitude() lonn = place.get_longitude()
if latn and lonn: if latn and lonn:
latn, ignore = conv_lat_lon(latn, "0", "D.D8") latn, dummy_ignore = conv_lat_lon(latn, "0", "D.D8")
if not latn: if not latn:
if not self.warning: if not self.warning:
self.close() self.close()
@@ -301,7 +298,7 @@ class PlaceSelection(ManagedWindow, OsmGps):
WarningDialog(warn1, warn2, parent=self.uistate.window) WarningDialog(warn1, warn2, parent=self.uistate.window)
self.warning = True self.warning = True
continue continue
ignore, lonn = conv_lat_lon("0", lonn, "D.D8") dummy_ignore, lonn = conv_lat_lon("0", lonn, "D.D8")
if not lonn: if not lonn:
if not self.warning: if not self.warning:
self.close() self.close()
@@ -312,7 +309,7 @@ class PlaceSelection(ManagedWindow, OsmGps):
self.warning = True self.warning = True
continue continue
if (math.hypot(lat-float(latn), if (math.hypot(lat-float(latn),
lon-float(lonn)) <= rds) == True: lon-float(lonn)) <= rds):
(country, state, county, (country, state, county,
place, other) = self.get_location(place.get_gramps_id()) place, other) = self.get_location(place.get_gramps_id())
if not [country, state, county, if not [country, state, county,
@@ -324,9 +321,13 @@ class PlaceSelection(ManagedWindow, OsmGps):
""" """
get location values and call the real function : add_place, edit_place get location values and call the real function : add_place, edit_place
""" """
dummy_obj = obj
dummy_col = column
dummy_fct = function
#TODO : self.plist unsubscriptable
self.function(self.plist[index], self.lat, self.lon) self.function(self.plist[index], self.lat, self.lon)
def untag_text(text, tag): def untag_text(self, text, tag):
""" """
suppress the green or red color tag. suppress the green or red color tag.
if tag = 0 : PLACE_REGEXP if tag = 0 : PLACE_REGEXP

View File

@@ -26,15 +26,7 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from math import pi from math import pi
from gi.repository import GObject
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.selectionlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -47,7 +39,7 @@ _LOG = logging.getLogger("maps.selectionlayer")
# osmGpsMap # osmGpsMap
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import GObject
try: try:
import gi import gi
gi.require_version('OsmGpsMap', '1.0') gi.require_version('OsmGpsMap', '1.0')
@@ -55,7 +47,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument #------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
_LOG = logging.getLogger("maps.selectionlayer")
class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer): class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
@@ -87,9 +84,9 @@ class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
for circle in self.circles: for circle in self.circles:
top_left = osmgpsmap.MapPoint.new_degrees(circle[1] + circle[0], top_left = osmgpsmap.MapPoint.new_degrees(circle[1] + circle[0],
circle[2] - circle[0]) circle[2] - circle[0])
bottom_right = osmgpsmap.MapPoint.new_degrees(circle[1] - circle[0], bottom_right = osmgpsmap.MapPoint.new_degrees(circle[1] - circle[0],
circle[2] + circle[0]) circle[2] + circle[0])
center = osmgpsmap.MapPoint.new_degrees(circle[1], circle[2]) center = osmgpsmap.MapPoint.new_degrees(circle[1], circle[2])
crd_x, crd_y = gpsmap.convert_geographic_to_screen(top_left) crd_x, crd_y = gpsmap.convert_geographic_to_screen(top_left)
crd_x2, crd_y2 = gpsmap.convert_geographic_to_screen(bottom_right) crd_x2, crd_y2 = gpsmap.convert_geographic_to_screen(bottom_right)
@@ -141,7 +138,8 @@ class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
Someone press a button Someone press a button
""" """
dummy_map = gpsmap
dummy_evt = gdkeventbutton
return False return False
GObject.type_register(SelectionLayer) GObject.type_register(SelectionLayer)

View File

@@ -23,31 +23,29 @@
""" """
Geography for two persons Geography for two persons
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
import operator import operator
from gi.repository import Gtk
from math import hypot from math import hypot
from html import escape from html import escape
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geoclose")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gtk
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import EventRoleType, EventType from gramps.gen.lib import EventRoleType, EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer, get_date from gramps.gen.datehandler import displayer, get_date
@@ -59,13 +57,14 @@ from gramps.plugins.lib.maps import constants
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
from gramps.gui.selectors import SelectorFactory from gramps.gui.selectors import SelectorFactory
from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback) from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback)
from gramps.gui.uimanager import ActionGroup
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_LOG = logging.getLogger("GeoGraphy.geoclose")
_ = glocale.translation.gettext
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -185,11 +184,12 @@ _UI_DEF = [
# pylint: disable=no-member # pylint: disable=no-member
# pylint: disable=unused-argument # pylint: disable=unused-argument
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoClose(GeoGraphyView): class GeoClose(GeoGraphyView):
""" """
The view used to render person map. The view used to render person map.
@@ -219,9 +219,9 @@ class GeoClose(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Have they been able to meet?"), GeoGraphyView.__init__(self, _("Have they been able to meet?"),
pdata, dbstate, uistate, pdata, dbstate, uistate,
PersonBookmarks, PersonBookmarks,
nav_group) nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -316,16 +316,16 @@ class GeoClose(GeoGraphyView):
if self.refperson: if self.refperson:
color = self._config.get('geography.color1') color = self._config.get('geography.color1')
self.message_layer.add_message( self.message_layer.add_message(
_("Reference : %(name)s ( %(birth)s - %(death)s )") % { _("Reference : %(name)s ( %(birth)s - %(death)s )") % {
'name': _nd.display(self.refperson), 'name': _nd.display(self.refperson),
'birth': self.birth(self.refperson), 'birth': self.birth(self.refperson),
'death': self.death(self.refperson)}) 'death': self.death(self.refperson)})
if indiv1: if indiv1:
self.message_layer.add_message( self.message_layer.add_message(
_("The other : %(name)s ( %(birth)s - %(death)s )") % { _("The other : %(name)s ( %(birth)s - %(death)s )") % {
'name': _nd.display(indiv1), 'name': _nd.display(indiv1),
'birth': self.birth(indiv1), 'birth': self.birth(indiv1),
'death': self.death(indiv1)}) 'death': self.death(indiv1)})
else: else:
self.message_layer.add_message(_("The other person is unknown")) self.message_layer.add_message(_("The other person is unknown"))
self._createmap(self.refperson, color, self.place_list_ref, True) self._createmap(self.refperson, color, self.place_list_ref, True)
@@ -334,7 +334,7 @@ class GeoClose(GeoGraphyView):
self.add_bookmark_from_popup(None, self.refperson_bookmark) self.add_bookmark_from_popup(None, self.refperson_bookmark)
else: else:
self.message_layer.add_message( self.message_layer.add_message(
_("You must choose one reference person.")) _("You must choose one reference person."))
self.message_layer.add_message(_("Go to the person view and select " self.message_layer.add_message(_("Go to the person view and select "
"the people you want to compare. " "the people you want to compare. "
"Return to this view and use the" "Return to this view and use the"
@@ -436,8 +436,9 @@ class GeoClose(GeoGraphyView):
points.append((startlat, startlon)) points.append((startlat, startlon))
self.lifeway_layer.add_way(points, color) self.lifeway_layer.add_way(points, color)
if reference: if reference:
self.lifeway_layer.add_way_ref(points, 'orange', self.lifeway_layer.add_way_ref(
float(self._config.get("geography.maximum_meeting_zone")) / 10) points, 'orange',
float(self._config.get("geography.maximum_meeting_zone")) / 10)
return False return False
def possible_meeting(self, place_list_ref, place_list_active): def possible_meeting(self, place_list_ref, place_list_active):
@@ -449,11 +450,13 @@ class GeoClose(GeoGraphyView):
for ref in place_list_ref: for ref in place_list_ref:
for act in place_list_active: for act in place_list_active:
if (hypot(float(act[3])-float(ref[3]), if (hypot(float(act[3])-float(ref[3]),
float(act[4])-float(ref[4])) <= radius) == True: float(act[4])-float(ref[4])) <= radius):
# we are in the meeting zone # we are in the meeting zone
self.add_marker(None, None, act[3], act[4], act[7], True, 1) self.add_marker(None, None, act[3], act[4], act[7],
True, 1)
self.all_place_list.append(act) self.all_place_list.append(act)
self.add_marker(None, None, ref[3], ref[4], ref[7], True, 1) self.add_marker(None, None, ref[3], ref[4], ref[7],
True, 1)
self.all_place_list.append(ref) self.all_place_list.append(ref)
def _createmap(self, person, color, place_list, reference): def _createmap(self, person, color, place_list, reference):
@@ -479,11 +482,11 @@ class GeoClose(GeoGraphyView):
role = event_ref.get_role() role = event_ref.get_role()
try: try:
date = event.get_date_object().to_calendar(self.cal) date = event.get_date_object().to_calendar(self.cal)
except: except Exception:
continue continue
eyear = str("%04d" % date.get_year()) + \ eyear = str("%04d" % date.get_year()) + \
str("%02d" % date.get_month()) + \ str("%02d" % date.get_month()) + \
str("%02d" % date.get_day()) str("%02d" % date.get_day())
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle(place_handle) place = dbstate.db.get_place_from_handle(place_handle)
@@ -495,8 +498,8 @@ class GeoClose(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
# contains non null string. # contains non null string.
@@ -509,11 +512,10 @@ class GeoClose(GeoGraphyView):
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
role role)
)
else: else:
self._append_to_places_without_coord( self._append_to_places_without_coord(
place.gramps_id, descr) place.gramps_id, descr)
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
descr1 = " - " descr1 = " - "
for family_hdl in family_list: for family_hdl in family_list:
@@ -535,35 +537,35 @@ class GeoClose(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle( event = dbstate.db.get_event_from_handle(
event_ref.ref) event_ref.ref)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle( place = dbstate.db.get_place_from_handle(
place_handle) place_handle)
if place: if place:
longitude = place.get_longitude() longitude = place.get_longitude()
latitude = place.get_latitude() latitude = place.get_latitude()
latitude, longitude = conv_lat_lon( latitude, longitude = conv_lat_lon(
latitude, longitude, "D.D8") latitude, longitude, "D.D8")
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
eyear = str( eyear = str(
"%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
if longitude and latitude: if longitude and latitude:
self._append_to_places_list(descr, self._append_to_places_list(
evt, _nd.display(person), descr,
latitude, longitude, evt, _nd.display(person),
descr1, eyear, latitude, longitude,
event.get_type(), descr1, eyear,
person.gramps_id, event.get_type(),
place.gramps_id, person.gramps_id,
event.gramps_id, place.gramps_id,
role event.gramps_id,
) role)
else: else:
self._append_to_places_without_coord(place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
@@ -650,7 +652,7 @@ class GeoClose(GeoGraphyView):
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem( add_item = Gtk.MenuItem(
label=_("Choose and bookmark the new reference person")) label=_("Choose and bookmark the new reference person"))
add_item.connect("activate", self.select_person) add_item.connect("activate", self.select_person)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
@@ -672,18 +674,17 @@ class GeoClose(GeoGraphyView):
grid.set_border_width(12) grid.set_border_width(12)
grid.set_column_spacing(6) grid.set_column_spacing(6)
grid.set_row_spacing(6) grid.set_row_spacing(6)
configdialog.add_text(grid, configdialog.add_text(
_('The meeting zone probability radius.\n' grid,
'The colored zone is approximative.\n' _('The meeting zone probability radius.\n'
'The meeting zone is only shown for the reference person.\n' 'The colored zone is approximative.\n'
'The value 9 means about 42 miles or 67 kms.\n' 'The meeting zone is only shown for the reference person.\n'
'The value 1 means about 4.6 miles or 7.5 kms.\n' 'The value 9 means about 42 miles or 67 kms.\n'
'The value is in tenth of degree.'), 'The value 1 means about 4.6 miles or 7.5 kms.\n'
1, line_wrap=False) 'The value is in tenth of degree.'),
self.config_meeting_slider = configdialog.add_slider(grid, 1, line_wrap=False)
"", self.config_meeting_slider = configdialog.add_slider(
2, 'geography.maximum_meeting_zone', grid, "", 2, 'geography.maximum_meeting_zone', (1, 9))
(1, 9))
return _('The selection parameters'), grid return _('The selection parameters'), grid
def config_connect(self): def config_connect(self):
@@ -691,11 +692,10 @@ class GeoClose(GeoGraphyView):
used to monitor changes in the ini file used to monitor changes in the ini file
""" """
self._config.connect('geography.maximum_meeting_zone', self._config.connect('geography.maximum_meeting_zone',
self.cb_update_meeting_radius) self.cb_update_meeting_radius)
def cb_update_meeting_radius(self, client, cnxn_id, entry, data): def cb_update_meeting_radius(self, client, cnxn_id, entry, data):
""" """
Called when the radius change Called when the radius change
""" """
self.goto_handle(handle=None) self.goto_handle(handle=None)

View File

@@ -23,31 +23,28 @@
""" """
Geography for events Geography for events
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import operator import operator
from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab
from gi.repository import Gtk
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geoevents")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.lib import EventType from gramps.gen.lib import EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer from gramps.gen.datehandler import displayer
@@ -58,11 +55,14 @@ from gramps.gui.views.bookmarks import EventBookmarks
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
from gramps.gui.utils import ProgressMeter from gramps.gui.utils import ProgressMeter
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
KEY_TAB = Gdk.KEY_Tab
_LOG = logging.getLogger("GeoGraphy.geoevents")
_ = glocale.translation.gettext
_UI_DEF = [''' _UI_DEF = ['''
<placeholder id="CommonGo"> <placeholder id="CommonGo">
@@ -78,7 +78,7 @@ _UI_DEF = ['''
</section> </section>
</placeholder> </placeholder>
''', ''',
''' '''
<section id='CommonEdit' groups='RW'> <section id='CommonEdit' groups='RW'>
<item> <item>
<attribute name="action">win.PrintView</attribute> <attribute name="action">win.PrintView</attribute>
@@ -86,7 +86,7 @@ _UI_DEF = ['''
</item> </item>
</section> </section>
''', ''',
''' '''
<section id="AddEditBook"> <section id="AddEditBook">
<item> <item>
<attribute name="action">win.AddBook</attribute> <attribute name="action">win.AddBook</attribute>
@@ -98,13 +98,14 @@ _UI_DEF = ['''
</item> </item>
</section> </section>
''' % _('Organize Bookmarks'), # Following are the Toolbar items ''' % _('Organize Bookmarks'), # Following are the Toolbar items
''' '''
<placeholder id='CommonNavigation'> <placeholder id='CommonNavigation'>
<child groups='RO'> <child groups='RO'>
<object class="GtkToolButton"> <object class="GtkToolButton">
<property name="icon-name">go-previous</property> <property name="icon-name">go-previous</property>
<property name="action-name">win.Back</property> <property name="action-name">win.Back</property>
<property name="tooltip_text" translatable="yes">Go to the previous object in the history</property> <property name="tooltip_text"
translatable="yes">Go to the previous object in the history</property>
<property name="label" translatable="yes">_Back</property> <property name="label" translatable="yes">_Back</property>
<property name="use-underline">True</property> <property name="use-underline">True</property>
</object> </object>
@@ -116,7 +117,8 @@ _UI_DEF = ['''
<object class="GtkToolButton"> <object class="GtkToolButton">
<property name="icon-name">go-next</property> <property name="icon-name">go-next</property>
<property name="action-name">win.Forward</property> <property name="action-name">win.Forward</property>
<property name="tooltip_text" translatable="yes">Go to the next object in the history</property> <property name="tooltip_text"
translatable="yes">Go to the next object in the history</property>
<property name="label" translatable="yes">_Forward</property> <property name="label" translatable="yes">_Forward</property>
<property name="use-underline">True</property> <property name="use-underline">True</property>
</object> </object>
@@ -126,13 +128,14 @@ _UI_DEF = ['''
</child> </child>
</placeholder> </placeholder>
''', ''',
''' '''
<placeholder id='BarCommonEdit'> <placeholder id='BarCommonEdit'>
<child groups='RO'> <child groups='RO'>
<object class="GtkToolButton"> <object class="GtkToolButton">
<property name="icon-name">document-print</property> <property name="icon-name">document-print</property>
<property name="action-name">win.PrintView</property> <property name="action-name">win.PrintView</property>
<property name="tooltip_text" translatable="yes">Print or save the Map</property> <property name="tooltip_text"
translatable="yes">Print or save the Map</property>
<property name="label" translatable="yes">Print...</property> <property name="label" translatable="yes">Print...</property>
<property name="use-underline">True</property> <property name="use-underline">True</property>
</object> </object>
@@ -147,11 +150,12 @@ _UI_DEF = ['''
# pylint: disable=no-member # pylint: disable=no-member
# pylint: disable=maybe-no-member # pylint: disable=maybe-no-member
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoEvents(GeoGraphyView): class GeoEvents(GeoGraphyView):
""" """
The view used to render events map. The view used to render events map.
@@ -160,9 +164,9 @@ class GeoEvents(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
self.window_name = _('Events places map') self.window_name = _('Events places map')
GeoGraphyView.__init__(self, self.window_name, GeoGraphyView.__init__(self, self.window_name,
pdata, dbstate, uistate, pdata, dbstate, uistate,
EventBookmarks, EventBookmarks,
nav_group) nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -272,9 +276,8 @@ class GeoEvents(GeoGraphyView):
person_list = [ person_list = [
dbstate.db.get_person_from_handle(ref_handle) dbstate.db.get_person_from_handle(ref_handle)
for (ref_type, ref_handle) in for (ref_type, ref_handle) in
dbstate.db.find_backlink_handles(event.handle) dbstate.db.find_backlink_handles(event.handle)
if ref_type == 'Person' if ref_type == 'Person']
]
if person_list: if person_list:
for person in person_list: for person in person_list:
if descr2 == "": if descr2 == "":
@@ -287,24 +290,22 @@ class GeoEvents(GeoGraphyView):
family_list = [ family_list = [
dbstate.db.get_family_from_handle(ref_handle) dbstate.db.get_family_from_handle(ref_handle)
for (ref_type, ref_handle) in for (ref_type, ref_handle) in
dbstate.db.find_backlink_handles(event.handle) dbstate.db.find_backlink_handles(event.handle)
if ref_type == 'Family' if ref_type == 'Family']
]
if family_list: if family_list:
for family in family_list: for family in family_list:
father = mother = None father = mother = None
hdle = family.get_father_handle() hdle = family.get_father_handle()
if hdle: if hdle:
father = dbstate.db.get_person_from_handle( father = dbstate.db.get_person_from_handle(
hdle) hdle)
hdle = family.get_mother_handle() hdle = family.get_mother_handle()
if hdle: if hdle:
mother = dbstate.db.get_person_from_handle( mother = dbstate.db.get_person_from_handle(
hdle) hdle)
descr2 = ("%(father)s - %(mother)s") % { descr2 = ("%(father)s - %(mother)s") % {
'father': _nd.display(father) if father is not None else "?", 'father': _nd.display(father) if father is not None else "?",
'mother': _nd.display(mother) if mother is not None else "?" 'mother': _nd.display(mother) if mother is not None else "?"}
}
else: else:
descr2 = _("incomplete or unreferenced event ?") descr2 = _("incomplete or unreferenced event ?")
self._append_to_places_list(descr1, None, self._append_to_places_list(descr1, None,
@@ -313,11 +314,10 @@ class GeoEvents(GeoGraphyView):
descr2, descr2,
eventyear, eventyear,
event.get_type(), event.get_type(),
None, # person.gramps_id None, # person.gramps_id
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
None None)
)
def _createmap(self, obj): def _createmap(self, obj):
""" """
@@ -354,7 +354,7 @@ class GeoEvents(GeoGraphyView):
progress.step() progress.step()
progress.close() progress.close()
elif self.generic_filter: elif self.generic_filter:
user=self.uistate.viewmanager.user user = self.uistate.viewmanager.user
events_list = self.generic_filter.apply(dbstate.db, user=user) events_list = self.generic_filter.apply(dbstate.db, user=user)
progress = ProgressMeter(self.window_name, progress = ProgressMeter(self.window_name,
can_cancel=False, can_cancel=False,
@@ -371,14 +371,12 @@ class GeoEvents(GeoGraphyView):
event = dbstate.db.get_event_from_handle(obj) event = dbstate.db.get_event_from_handle(obj)
self._createmap_for_one_event(event) self._createmap_for_one_event(event)
self.message_layer.add_message( self.message_layer.add_message(
_("Right click on the map and select 'show all events'" _("Right click on the map and select 'show all events'"
" to show all known events with coordinates. " " to show all known events with coordinates. "
"You can use the history to navigate on the map. " "You can use the history to navigate on the map. "
"You can use filtering.")) "You can use filtering."))
self.sort = sorted(self.place_list, self.sort = sorted(self.place_list, key=operator.itemgetter(3, 4, 6))
key=operator.itemgetter(3, 4, 6) if self.nbmarkers > 500: # performance issue. Is it the good value ?
)
if self.nbmarkers > 500: # performance issue. Is it the good value ?
self.no_show_places_in_status_bar = True self.no_show_places_in_status_bar = True
self._create_markers() self._create_markers()

View File

@@ -23,47 +23,46 @@
""" """
Geography for two families Geography for two families
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
import operator import operator
from gi.repository import Gtk
from math import hypot from math import hypot
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geofamilyclose")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gtk
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import EventRoleType, EventType from gramps.gen.lib import EventRoleType, EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer from gramps.gen.datehandler import displayer
from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import displayer as _nd
from gramps.gen.display.place import displayer as _pd from gramps.gen.display.place import displayer as _pd
from gramps.gen.utils.place import conv_lat_lon from gramps.gen.utils.place import conv_lat_lon
from gramps.gui.views.navigationview import NavigationView
from gramps.gui.views.bookmarks import FamilyBookmarks from gramps.gui.views.bookmarks import FamilyBookmarks
from gramps.plugins.lib.maps import constants from gramps.plugins.lib.maps import constants
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
from gramps.gui.selectors import SelectorFactory from gramps.gui.selectors import SelectorFactory
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_ = glocale.translation.gettext
_LOG = logging.getLogger("GeoGraphy.geofamilyclose")
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -184,11 +183,11 @@ _UI_DEF = [
# pylint: disable=unused-variable # pylint: disable=unused-variable
# pylint: disable=unused-argument # pylint: disable=unused-argument
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoFamClose(GeoGraphyView): class GeoFamClose(GeoGraphyView):
""" """
The view used to render family's map. The view used to render family's map.
@@ -362,11 +361,11 @@ class GeoFamClose(GeoGraphyView):
self.add_bookmark_from_popup(None, self.reffamily_bookmark) self.add_bookmark_from_popup(None, self.reffamily_bookmark)
else: else:
self.message_layer.add_message( self.message_layer.add_message(
_("You must choose one reference family.")) _("You must choose one reference family."))
self.message_layer.add_message( self.message_layer.add_message(
_("Go to the family view and select " _("Go to the family view and select "
"the families you want to compare. " "the families you want to compare. "
"Return to this view and use the history.")) "Return to this view and use the history."))
if family is not None: if family is not None:
self._possible_family_meeting(self.reffamily, family) self._possible_family_meeting(self.reffamily, family)
self.uistate.modify_statusbar(self.dbstate) self.uistate.modify_statusbar(self.dbstate)
@@ -429,9 +428,9 @@ class GeoFamClose(GeoGraphyView):
points.append((startlat, startlon)) points.append((startlat, startlon))
self.lifeway_layer.add_way(points, color) self.lifeway_layer.add_way(points, color)
if reference: if reference:
self.lifeway_layer.add_way_ref(points, 'orange', self.lifeway_layer.add_way_ref(
float( points, 'orange', float(
self._config.get("geography.maximum_meeting_zone")) / 10) self._config.get("geography.maximum_meeting_zone")) / 10)
return False return False
def _place_list_for_person(self, person): def _place_list_for_person(self, person):
@@ -455,11 +454,13 @@ class GeoFamClose(GeoGraphyView):
for ref in self.place_list_ref: for ref in self.place_list_ref:
for act in self.place_list_active: for act in self.place_list_active:
if (hypot(float(act[3])-float(ref[3]), if (hypot(float(act[3])-float(ref[3]),
float(act[4])-float(ref[4])) <= radius) == True: float(act[4])-float(ref[4])) <= radius):
# we are in the meeting zone # we are in the meeting zone
self.add_marker(None, None, act[3], act[4], act[7], True, 1) self.add_marker(None, None, act[3], act[4], act[7],
True, 1)
self.all_place_list.append(act) self.all_place_list.append(act)
self.add_marker(None, None, ref[3], ref[4], ref[7], True, 1) self.add_marker(None, None, ref[3], ref[4], ref[7],
True, 1)
self.all_place_list.append(ref) self.all_place_list.append(ref)
def _expose_persone_to_family(self, ref_person, family): def _expose_persone_to_family(self, ref_person, family):
@@ -470,16 +471,16 @@ class GeoFamClose(GeoGraphyView):
dbstate = self.dbstate dbstate = self.dbstate
try: try:
person = dbstate.db.get_person_from_handle( person = dbstate.db.get_person_from_handle(
family.get_father_handle()) family.get_father_handle())
except: except Exception:
return return
if person is None: # family without father ? if person is None: # family without father ?
person = dbstate.db.get_person_from_handle( person = dbstate.db.get_person_from_handle(
family.get_mother_handle()) family.get_mother_handle())
if person is not None: if person is not None:
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
if len(family_list) > 0: if len(family_list) > 0:
fhandle = family_list[0] # first is primary fhandle = family_list[0] # first is primary
fam = dbstate.db.get_family_from_handle(fhandle) fam = dbstate.db.get_family_from_handle(fhandle)
father = mother = None father = mother = None
handle = fam.get_father_handle() handle = fam.get_father_handle()
@@ -510,10 +511,10 @@ class GeoFamClose(GeoGraphyView):
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle( person = dbstate.db.get_person_from_handle(
reference.get_father_handle()) reference.get_father_handle())
except: except Exception:
return return
if person is None: # family without father ? if person is None: # family without father ?
handle = reference.get_mother_handle() handle = reference.get_mother_handle()
if handle: if handle:
person = dbstate.db.get_person_from_handle(handle) person = dbstate.db.get_person_from_handle(handle)
@@ -540,13 +541,13 @@ class GeoFamClose(GeoGraphyView):
child_ref_list = fam.get_child_ref_list() child_ref_list = fam.get_child_ref_list()
if child_ref_list: if child_ref_list:
for child_ref in child_ref_list: for child_ref in child_ref_list:
child = dbstate.db.get_person_from_handle(child_ref.ref) child = dbstate.db.get_person_from_handle(
child_ref.ref)
if child: if child:
self._expose_persone_to_family(child, family) self._expose_persone_to_family(child, family)
else: else:
self._expose_persone_to_family(person, family) self._expose_persone_to_family(person, family)
def _createmap_for_one_person(self, person, color, place_list, reference): def _createmap_for_one_person(self, person, color, place_list, reference):
""" """
Create all markers for each people's event in the database which has Create all markers for each people's event in the database which has
@@ -563,7 +564,7 @@ class GeoFamClose(GeoGraphyView):
role = event_ref.get_role() role = event_ref.get_role()
try: try:
date = event.get_date_object().to_calendar(self.cal) date = event.get_date_object().to_calendar(self.cal)
except: except Exception:
continue continue
eyear = str("%04d" % date.get_year()) + \ eyear = str("%04d" % date.get_year()) + \
str("%02d" % date.get_month()) + \ str("%02d" % date.get_month()) + \
@@ -579,8 +580,8 @@ class GeoFamClose(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
# contains non null string. # contains non null string.
@@ -593,17 +594,16 @@ class GeoFamClose(GeoGraphyView):
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
role role)
)
else: else:
self._append_to_places_without_coord( self._append_to_places_without_coord(
place.gramps_id, descr) place.gramps_id, descr)
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
descr1 = " - " descr1 = " - "
for family_hdl in family_list: for family_hdl in family_list:
family = self.dbstate.db.get_family_from_handle(family_hdl) family = self.dbstate.db.get_family_from_handle(family_hdl)
if family is not None: if family is not None:
fhandle = family_list[0] # first is primary fhandle = family_list[0] # first is primary
father = mother = None father = mother = None
fam = dbstate.db.get_family_from_handle(fhandle) fam = dbstate.db.get_family_from_handle(fhandle)
handle = fam.get_father_handle() handle = fam.get_father_handle()
@@ -619,36 +619,36 @@ class GeoFamClose(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle( event = dbstate.db.get_event_from_handle(
event_ref.ref) event_ref.ref)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle( place = dbstate.db.get_place_from_handle(
place_handle) place_handle)
if place: if place:
longitude = place.get_longitude() longitude = place.get_longitude()
latitude = place.get_latitude() latitude = place.get_latitude()
latitude, longitude = conv_lat_lon( latitude, longitude = conv_lat_lon(
latitude, longitude, "D.D8") latitude, longitude, "D.D8")
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType( evt = EventType(
event.get_type()) event.get_type())
eyear = str( eyear = str(
"%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
if longitude and latitude: if longitude and latitude:
self._append_to_places_list(descr, self._append_to_places_list(
evt, _nd.display(person), descr, evt,
latitude, longitude, _nd.display(person),
descr1, eyear, latitude, longitude,
event.get_type(), descr1, eyear,
person.gramps_id, event.get_type(),
place.gramps_id, person.gramps_id,
event.gramps_id, place.gramps_id,
role event.gramps_id,
) role)
else: else:
self._append_to_places_without_coord(place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
@@ -668,11 +668,10 @@ class GeoFamClose(GeoGraphyView):
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle( person = dbstate.db.get_person_from_handle(
family.get_father_handle()) family.get_father_handle())
except: except Exception:
return return
family_id = family.gramps_id if person is None: # family without father ?
if person is None: # family without father ?
handle = family.get_mother_handle() handle = family.get_mother_handle()
if handle: if handle:
person = dbstate.db.get_person_from_handle(handle) person = dbstate.db.get_person_from_handle(handle)
@@ -691,8 +690,8 @@ class GeoFamClose(GeoGraphyView):
father = dbstate.db.get_person_from_handle(handle) father = dbstate.db.get_person_from_handle(handle)
if father: if father:
comment = _("Father : %(id)s : %(name)s") % { comment = _("Father : %(id)s : %(name)s") % {
'id': father.gramps_id, 'id': father.gramps_id,
'name': _nd.display(father)} 'name': _nd.display(father)}
self._createmap_for_one_person(father, color, self._createmap_for_one_person(father, color,
place_list, reference) place_list, reference)
handle = fam.get_mother_handle() handle = fam.get_mother_handle()
@@ -700,8 +699,8 @@ class GeoFamClose(GeoGraphyView):
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
comment = _("Mother : %(id)s : %(name)s") % { comment = _("Mother : %(id)s : %(name)s") % {
'id': mother.gramps_id, 'id': mother.gramps_id,
'name': _nd.display(mother)} 'name': _nd.display(mother)}
self._createmap_for_one_person(mother, color, self._createmap_for_one_person(mother, color,
place_list, reference) place_list, reference)
index = 0 index = 0
@@ -715,16 +714,14 @@ class GeoFamClose(GeoGraphyView):
": %(name)s") % { ": %(name)s") % {
'id' : child.gramps_id, 'id' : child.gramps_id,
'index' : index, 'index' : index,
'name' : _nd.display(child) 'name' : _nd.display(child)}
}
self._createmap_for_one_person(child, color, self._createmap_for_one_person(child, color,
place_list, place_list,
reference) reference)
else: else:
comment = _("Person : %(id)s %(name)s has no family.") % { comment = _("Person : %(id)s %(name)s has no family.") % {
'id' : person.gramps_id, 'id' : person.gramps_id,
'name' : _nd.display(person) 'name' : _nd.display(person)}
}
self._createmap_for_one_person(person, color, self._createmap_for_one_person(person, color,
place_list, reference) place_list, reference)
@@ -838,7 +835,7 @@ class GeoFamClose(GeoGraphyView):
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem( add_item = Gtk.MenuItem(
label=_("Choose and bookmark the new reference family")) label=_("Choose and bookmark the new reference family"))
add_item.connect("activate", self.select_family) add_item.connect("activate", self.select_family)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
@@ -860,18 +857,18 @@ class GeoFamClose(GeoGraphyView):
grid.set_border_width(12) grid.set_border_width(12)
grid.set_column_spacing(6) grid.set_column_spacing(6)
grid.set_row_spacing(6) grid.set_row_spacing(6)
configdialog.add_text(grid, configdialog.add_text(
_('The meeting zone probability radius.\n' grid,
'The colored zone is approximative.\n' _('The meeting zone probability radius.\n'
'The meeting zone is only shown for the reference family.\n' 'The colored zone is approximative.\n'
'The value 9 means about 42 miles or 67 kms.\n' 'The meeting zone is only shown for the reference family.\n'
'The value 1 means about 4.6 miles or 7.5 kms.\n' 'The value 9 means about 42 miles or 67 kms.\n'
'The value is in tenth of degree.'), 'The value 1 means about 4.6 miles or 7.5 kms.\n'
1, line_wrap=False) 'The value is in tenth of degree.'),
self.config_meeting_slider = configdialog.add_slider(grid, 1, line_wrap=False)
"", self.config_meeting_slider = configdialog.add_slider(
2, 'geography.maximum_meeting_zone', grid, "",
(1, 9)) 2, 'geography.maximum_meeting_zone', (1, 9))
return _('The selection parameters'), grid return _('The selection parameters'), grid
def config_connect(self): def config_connect(self):
@@ -879,11 +876,10 @@ class GeoFamClose(GeoGraphyView):
used to monitor changes in the ini file used to monitor changes in the ini file
""" """
self._config.connect('geography.maximum_meeting_zone', self._config.connect('geography.maximum_meeting_zone',
self.cb_update_meeting_radius) self.cb_update_meeting_radius)
def cb_update_meeting_radius(self, client, cnxn_id, entry, data): def cb_update_meeting_radius(self, client, cnxn_id, entry, data):
""" """
Called when the radius change Called when the radius change
""" """
self.goto_handle(handle=None) self.goto_handle(handle=None)

View File

@@ -23,31 +23,28 @@
""" """
Geography for one family Geography for one family
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import operator import operator
from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab
from gi.repository import Gtk
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geofamily")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.lib import EventRoleType, EventType from gramps.gen.lib import EventRoleType, EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer from gramps.gen.datehandler import displayer
@@ -57,11 +54,14 @@ from gramps.gen.utils.place import conv_lat_lon
from gramps.gui.views.bookmarks import FamilyBookmarks from gramps.gui.views.bookmarks import FamilyBookmarks
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_LOG = logging.getLogger("GeoGraphy.geofamily")
KEY_TAB = Gdk.KEY_Tab
_ = glocale.translation.gettext
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -150,11 +150,11 @@ _UI_DEF = [
# pylint: disable=unused-variable # pylint: disable=unused-variable
# pylint: disable=unused-argument # pylint: disable=unused-argument
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoFamily(GeoGraphyView): class GeoFamily(GeoGraphyView):
""" """
The view used to render family map. The view used to render family map.
@@ -162,9 +162,9 @@ class GeoFamily(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _('Family places map'), GeoGraphyView.__init__(self, _('Family places map'),
pdata, dbstate, uistate, pdata, dbstate, uistate,
FamilyBookmarks, FamilyBookmarks,
nav_group) nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -218,7 +218,10 @@ class GeoFamily(GeoGraphyView):
""" """
if self.osm is None: if self.osm is None:
return return
self.build_tree() if self.uistate.get_active('Family'):
self._createmap(self.uistate.get_active('Family'))
else:
self._createmap(self.uistate.get_active('Person'))
def build_tree(self): def build_tree(self):
""" """
@@ -226,12 +229,7 @@ class GeoFamily(GeoGraphyView):
all handling of visibility is now in rebuild_trees, see that for more all handling of visibility is now in rebuild_trees, see that for more
information. information.
""" """
if not self.dbstate.is_open(): pass
return
if self.uistate.get_active('Family'):
self._createmap(self.uistate.get_active('Family'))
else:
self._createmap(self.uistate.get_active('Person'))
def _createpersonmarkers(self, dbstate, person, comment, fam_id): def _createpersonmarkers(self, dbstate, person, comment, fam_id):
""" """
@@ -258,15 +256,16 @@ class GeoFamily(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
# contains non null string. # contains non null string.
if longitude and latitude: if longitude and latitude:
if not self._present_in_places_list(2, if not self._present_in_places_list(
str(descr1 + descr + str(evt))): 2, str(descr1 + descr + str(evt))):
self._append_to_places_list(descr, self._append_to_places_list(
descr,
str(descr1 + descr + str(evt)), str(descr1 + descr + str(evt)),
_nd.display(person), _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -275,11 +274,10 @@ class GeoFamily(GeoGraphyView):
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
fam_id fam_id)
)
else: else:
self._append_to_places_without_coord( self._append_to_places_without_coord(
place.gramps_id, descr) place.gramps_id, descr)
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
for family_hdl in family_list: for family_hdl in family_list:
family = self.dbstate.db.get_family_from_handle(family_hdl) family = self.dbstate.db.get_family_from_handle(family_hdl)
@@ -287,13 +285,13 @@ class GeoFamily(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle( event = dbstate.db.get_event_from_handle(
event_ref.ref) event_ref.ref)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle( place = dbstate.db.get_place_from_handle(
place_handle) place_handle)
if place: if place:
longitude = place.get_longitude() longitude = place.get_longitude()
latitude = place.get_latitude() latitude = place.get_latitude()
@@ -311,19 +309,20 @@ class GeoFamily(GeoGraphyView):
eyear = event.get_date_object().to_calendar(self.cal).get_year() eyear = event.get_date_object().to_calendar(self.cal).get_year()
if longitude and latitude: if longitude and latitude:
if not self._present_in_places_list( if not self._present_in_places_list(
2, str(descr1 + descr + str(evt))): 2, str(descr1 +
descr + str(evt))):
self._append_to_places_list( self._append_to_places_list(
descr, descr,
str(descr1 + descr + str(evt)), str(descr1 + descr + str(
_nd.display(person), evt)),
latitude, longitude, _nd.display(person),
role, eyear, latitude, longitude,
event.get_type(), role, eyear,
person.gramps_id, event.get_type(),
place.gramps_id, person.gramps_id,
event.gramps_id, place.gramps_id,
family.gramps_id event.gramps_id,
) family.gramps_id)
else: else:
self._append_to_places_without_coord(place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
@@ -342,24 +341,24 @@ class GeoFamily(GeoGraphyView):
mother = self.dbstate.db.get_person_from_handle(hdl) mother = self.dbstate.db.get_person_from_handle(hdl)
if father and mother: if father and mother:
label = _("%(gramps_id)s : %(father)s and %(mother)s") % { label = _("%(gramps_id)s : %(father)s and %(mother)s") % {
'father' : _nd.display(father), 'father': _nd.display(father),
'mother' : _nd.display(mother), 'mother': _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id': family.gramps_id,
} }
elif father: elif father:
label = "%(gramps_id)s : %(father)s" % { label = "%(gramps_id)s : %(father)s" % {
'father' : _nd.display(father), 'father': _nd.display(father),
'gramps_id' : family.gramps_id, 'gramps_id': family.gramps_id,
} }
elif mother: elif mother:
label = "%(gramps_id)s : %(mother)s" % { label = "%(gramps_id)s : %(mother)s" % {
'mother' : _nd.display(mother), 'mother': _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id': family.gramps_id,
} }
else: else:
# No translation for bare gramps_id # No translation for bare gramps_id
label = "%(gramps_id)s :" % { label = "%(gramps_id)s :" % {
'gramps_id' : family.gramps_id, 'gramps_id': family.gramps_id,
} }
return label return label
@@ -369,7 +368,7 @@ class GeoFamily(GeoGraphyView):
""" """
dbstate = self.dbstate dbstate = self.dbstate
self.message_layer.add_message( self.message_layer.add_message(
_("Family places for %s") % self.family_label(family)) _("Family places for %s") % self.family_label(family))
person = None person = None
if family: if family:
handle = family.get_father_handle() handle = family.get_father_handle()
@@ -378,7 +377,7 @@ class GeoFamily(GeoGraphyView):
else: else:
return return
family_id = family.gramps_id family_id = family.gramps_id
if person is None: # family without father ? if person is None: # family without father ?
handle = family.get_mother_handle() handle = family.get_mother_handle()
if handle: if handle:
person = dbstate.db.get_person_from_handle(handle) person = dbstate.db.get_person_from_handle(handle)
@@ -389,7 +388,7 @@ class GeoFamily(GeoGraphyView):
if person is not None: if person is not None:
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
if len(family_list) > 0: if len(family_list) > 0:
fhandle = family_list[0] # first is primary fhandle = family_list[0] # first is primary
fam = dbstate.db.get_family_from_handle(fhandle) fam = dbstate.db.get_family_from_handle(fhandle)
father = mother = None father = mother = None
handle = fam.get_father_handle() handle = fam.get_father_handle()
@@ -397,8 +396,8 @@ class GeoFamily(GeoGraphyView):
father = dbstate.db.get_person_from_handle(handle) father = dbstate.db.get_person_from_handle(handle)
if father: if father:
comment = _("Father : %(id)s : %(name)s") % { comment = _("Father : %(id)s : %(name)s") % {
'id': father.gramps_id, 'id': father.gramps_id,
'name': _nd.display(father)} 'name': _nd.display(father)}
self._createpersonmarkers(dbstate, father, self._createpersonmarkers(dbstate, father,
comment, family_id) comment, family_id)
handle = fam.get_mother_handle() handle = fam.get_mother_handle()
@@ -406,30 +405,29 @@ class GeoFamily(GeoGraphyView):
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
comment = _("Mother : %(id)s : %(name)s") % { comment = _("Mother : %(id)s : %(name)s") % {
'id': mother.gramps_id, 'id': mother.gramps_id,
'name': _nd.display(mother)} 'name': _nd.display(mother)}
self._createpersonmarkers(dbstate, mother, self._createpersonmarkers(dbstate, mother,
comment, family_id) comment, family_id)
index = 0 index = 0
child_ref_list = fam.get_child_ref_list() child_ref_list = fam.get_child_ref_list()
if child_ref_list: if child_ref_list:
for child_ref in child_ref_list: for child_ref in child_ref_list:
child = dbstate.db.get_person_from_handle(child_ref.ref) child = dbstate.db.get_person_from_handle(
child_ref.ref)
if child: if child:
index += 1 index += 1
comment = _("Child : %(id)s - %(index)d " comment = _("Child : %(id)s - %(index)d "
": %(name)s") % { ": %(name)s") % {
'id' : child.gramps_id, 'id': child.gramps_id,
'index' : index, 'index': index,
'name' : _nd.display(child) 'name': _nd.display(child)}
}
self._createpersonmarkers(dbstate, child, self._createpersonmarkers(dbstate, child,
comment, family_id) comment, family_id)
else: else:
comment = _("Person : %(id)s %(name)s has no family.") % { comment = _("Person : %(id)s %(name)s has no family.") % {
'id' : person.gramps_id, 'id': person.gramps_id,
'name' : _nd.display(person) 'name': _nd.display(person)}
}
self._createpersonmarkers(dbstate, person, comment, family_id) self._createpersonmarkers(dbstate, person, comment, family_id)
def _createmap(self, handle): def _createmap(self, handle):

View File

@@ -23,31 +23,30 @@
""" """
Geography for one person and all his descendant Geography for one person and all his descendant
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
import operator import operator
# -------------------------------------------------------------------------
#
# set up logging
#
# -------------------------------------------------------------------------
import logging
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GLib from gi.repository import GLib
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger("GeoGraphy.geomoves")
#-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import EventRoleType, EventType from gramps.gen.lib import EventRoleType, EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer from gramps.gen.datehandler import displayer
@@ -58,11 +57,14 @@ from gramps.gui.views.bookmarks import PersonBookmarks
from gramps.plugins.lib.maps import constants from gramps.plugins.lib.maps import constants
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_LOG = logging.getLogger("GeoGraphy.geomoves")
_ = glocale.translation.gettext
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -171,11 +173,11 @@ _UI_DEF = [
# pylint: disable=unused-argument # pylint: disable=unused-argument
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GeoView : GeoMoves # GeoView : GeoMoves
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoMoves(GeoGraphyView): class GeoMoves(GeoGraphyView):
""" """
The view used to render all places visited by one person and all The view used to render all places visited by one person and all
@@ -206,17 +208,16 @@ class GeoMoves(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Descendance of the active person."), GeoGraphyView.__init__(self, _("Descendance of the active person."),
pdata, dbstate, uistate, pdata, dbstate, uistate, PersonBookmarks,
PersonBookmarks, nav_group)
nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
self.place_without_coordinates = [] self.place_without_coordinates = []
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0 self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
self.started = False
self.minyear = 9999 self.minyear = 9999
self.maxyear = 0 self.maxyear = 0
self.started = False
self.nbplaces = 0 self.nbplaces = 0
self.nbmarkers = 0 self.nbmarkers = 0
self.sort = [] self.sort = []
@@ -249,7 +250,7 @@ class GeoMoves(GeoGraphyView):
def get_viewtype_stock(self): def get_viewtype_stock(self):
"""Type of view in category """Type of view in category
""" """
return 'geo-show-family' return 'geo-show-family-down'
def additional_ui(self): def additional_ui(self):
""" """
@@ -280,6 +281,10 @@ class GeoMoves(GeoGraphyView):
self.remove_all_markers() self.remove_all_markers()
self.lifeway_layer.clear_ways() self.lifeway_layer.clear_ways()
self.date_layer.clear_dates() self.date_layer.clear_dates()
self.message_layer.clear_messages()
self.message_layer.set_font_attributes(None, None, None)
self.places_found = []
self.place_without_coordinates = []
active = self.get_active() active = self.get_active()
if active: if active:
person = self.dbstate.db.get_person_from_handle(active) person = self.dbstate.db.get_person_from_handle(active)
@@ -334,6 +339,8 @@ class GeoMoves(GeoGraphyView):
Create all markers for each people's event in the database which has Create all markers for each people's event in the database which has
a lat/lon. a lat/lon.
""" """
if self.stop: # no more database. stop to work
return
self.place_list = [] self.place_list = []
dbstate = self.dbstate dbstate = self.dbstate
if person is not None: if person is not None:
@@ -361,8 +368,8 @@ class GeoMoves(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
# contains non null string. # contains non null string.
@@ -375,11 +382,10 @@ class GeoMoves(GeoGraphyView):
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
role role)
)
else: else:
self._append_to_places_without_coord( self._append_to_places_without_coord(
place.gramps_id, descr) place.gramps_id, descr)
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
descr1 = " - " descr1 = " - "
for family_hdl in family_list: for family_hdl in family_list:
@@ -401,38 +407,36 @@ class GeoMoves(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle( event = dbstate.db.get_event_from_handle(
event_ref.ref) event_ref.ref)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle( place = dbstate.db.get_place_from_handle(
place_handle) place_handle)
if place: if place:
longitude = place.get_longitude() longitude = place.get_longitude()
latitude = place.get_latitude() latitude = place.get_latitude()
latitude, longitude = conv_lat_lon( latitude, longitude = conv_lat_lon(
latitude, longitude, "D.D8") latitude, longitude, "D.D8")
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType( evt = EventType(event.get_type())
event.get_type())
eyear = str( eyear = str(
"%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
if longitude and latitude: if longitude and latitude:
self._append_to_places_list( self._append_to_places_list(
descr, descr,
evt, evt,
person.gramps_id, person.gramps_id,
latitude, longitude, latitude, longitude,
descr1, eyear, descr1, eyear,
event.get_type(), event.get_type(),
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
role role)
)
else: else:
self._append_to_places_without_coord(place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
@@ -460,11 +464,13 @@ class GeoMoves(GeoGraphyView):
""" """
Create all markers for one family : all event's places with a lat/lon. Create all markers for one family : all event's places with a lat/lon.
""" """
if self.stop: # no more database. stop to work
return
dbstate = self.dbstate dbstate = self.dbstate
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle( person = dbstate.db.get_person_from_handle(
family.get_father_handle()) family.get_father_handle())
except: except:
return return
family_id = family.gramps_id family_id = family.gramps_id
@@ -509,6 +515,8 @@ class GeoMoves(GeoGraphyView):
""" """
if maximum generation is not reached, show next level. if maximum generation is not reached, show next level.
""" """
if self.stop: # no more database. stop to work
return
if level < curlevel: if level < curlevel:
return return
self._prepare_for_one_family(family, level, curlevel+1) self._prepare_for_one_family(family, level, curlevel+1)
@@ -525,7 +533,11 @@ class GeoMoves(GeoGraphyView):
except: except:
self.markers_by_level[curlevel] = [] self.markers_by_level[curlevel] = []
self.markers_by_level[curlevel].append(person) self.markers_by_level[curlevel].append(person)
if self.stop: # no more database. stop to work
return
for family in person.get_family_handle_list(): for family in person.get_family_handle_list():
if self.stop: # no more database. stop to work
return
fam = self.dbstate.db.get_family_from_handle(family) fam = self.dbstate.db.get_family_from_handle(family)
self._createmap_for_one_level(fam, level, curlevel) self._createmap_for_one_level(fam, level, curlevel)
if person not in self.markers_by_level[curlevel]: if person not in self.markers_by_level[curlevel]:
@@ -558,7 +570,7 @@ class GeoMoves(GeoGraphyView):
if not person: if not person:
return return
self.message_layer.add_message( self.message_layer.add_message(
_("All descendance for %s") % _nd.display(person)) _("All descendance for %s") % _nd.display(person))
color = Gdk.color_parse(self._config.get('geography.color_base')) color = Gdk.color_parse(self._config.get('geography.color_base'))
GLib.timeout_add(int(self._config.get("geography.generation_interval")), GLib.timeout_add(int(self._config.get("geography.generation_interval")),
self.animate_moves, 0, person, color) self.animate_moves, 0, person, color)
@@ -567,6 +579,8 @@ class GeoMoves(GeoGraphyView):
""" """
Animate all moves for one generation. Animate all moves for one generation.
""" """
if self.stop: # no more database. stop to work
return
self.markers_by_level = dict() self.markers_by_level = dict()
self._createmap_for_next_level(person, index, 0) self._createmap_for_next_level(person, index, 0)
try: try:
@@ -619,19 +633,19 @@ class GeoMoves(GeoGraphyView):
if level == index: if level == index:
pidx += 1 pidx += 1
self._createmap_for_one_person(plxp, color) self._createmap_for_one_person(plxp, color)
color.red = (float(color.red - (index)*3000)%65535) color.red = (float(color.red - (index)*3000) % 65535)
if index % 2: if index % 2:
color.green = float((color.green + (index)*3000)%65535) color.green = float((color.green + (index)*3000) % 65535)
else: else:
color.blue = float((color.blue + (index)*3000)%65535) color.blue = float((color.blue + (index)*3000) % 65535)
self._createmap_for_one_person(person, color) self._createmap_for_one_person(person, color)
if index < int(self._config.get("geography.maximum_generations")): if index < int(self._config.get("geography.maximum_generations")):
time_to_wait = int( time_to_wait = int(
self._config.get("geography.generation_interval")) self._config.get("geography.generation_interval"))
self._create_markers() self._create_markers()
# process next generation in a few milliseconds # process next generation in a few milliseconds
GLib.timeout_add(int(time_to_wait), self.animate_moves, GLib.timeout_add(int(time_to_wait), self.animate_moves,
index+1, person, color) index+1, person, color)
else: else:
self.started = False self.started = False
return False return False
@@ -649,7 +663,7 @@ class GeoMoves(GeoGraphyView):
# Be sure all markers are sorted by place then dates. # Be sure all markers are sorted by place then dates.
for mark in sorted(marks, key=operator.itemgetter(0, 6)): for mark in sorted(marks, key=operator.itemgetter(0, 6)):
if mark[10] in events: if mark[10] in events:
continue # avoid duplicate events continue # avoid duplicate events
else: else:
events.append(mark[10]) events.append(mark[10])
if mark[0] != oldplace: if mark[0] != oldplace:
@@ -730,19 +744,20 @@ class GeoMoves(GeoGraphyView):
grid.set_column_spacing(6) grid.set_column_spacing(6)
grid.set_row_spacing(6) grid.set_row_spacing(6)
configdialog.add_text(grid, configdialog.add_text(grid,
_('The maximum number of generations.\n'), _('The maximum number of generations.\n'),
1, line_wrap=False) 1, line_wrap=False)
configdialog.add_slider(grid, configdialog.add_slider(grid,
"", "",
2, 'geography.maximum_generations', 2, 'geography.maximum_generations',
(1, 20)) (1, 20))
configdialog.add_text(grid, configdialog.add_text(grid,
_('Time in milliseconds between drawing two generations.\n'), _('Time in milliseconds between drawing two'
3, line_wrap=False) ' generations.\n'),
3, line_wrap=False)
configdialog.add_slider(grid, configdialog.add_slider(grid,
"", "",
4, 'geography.generation_interval', 4, 'geography.generation_interval',
(500, 3000)) (500, 3000))
return _('The parameters for moves'), grid return _('The parameters for moves'), grid
def config_connect(self): def config_connect(self):
@@ -750,11 +765,10 @@ class GeoMoves(GeoGraphyView):
used to monitor changes in the ini file used to monitor changes in the ini file
""" """
self._config.connect('geography.maximum_generations', self._config.connect('geography.maximum_generations',
self._maximum_generations) self._maximum_generations)
def _maximum_generations(self, client, cnxn_id, entry, data): def _maximum_generations(self, client, cnxn_id, entry, data):
""" """
Called when the number of nomber of generations change Called when the number of nomber of generations change
""" """
self.goto_handle(handle=None) self.goto_handle(handle=None)

View File

@@ -23,32 +23,29 @@
""" """
Geography for one person Geography for one person
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import operator import operator
from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab
from gi.repository import Gtk
from gi.repository import GLib
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geoperson")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import GLib
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.lib import EventRoleType, EventType from gramps.gen.lib import EventRoleType, EventType
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.datehandler import displayer from gramps.gen.datehandler import displayer
@@ -59,11 +56,14 @@ from gramps.gui.views.bookmarks import PersonBookmarks
from gramps.plugins.lib.maps import constants from gramps.plugins.lib.maps import constants
from gramps.plugins.lib.maps.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
_LOG = logging.getLogger("GeoGraphy.geoperson")
KEY_TAB = Gdk.KEY_Tab
_ = glocale.translation.gettext
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -172,11 +172,11 @@ _UI_DEF = [
# pylint: disable=unused-variable # pylint: disable=unused-variable
# pylint: disable=unused-argument # pylint: disable=unused-argument
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoPerson(GeoGraphyView): class GeoPerson(GeoGraphyView):
""" """
The view used to render person map. The view used to render person map.
@@ -210,9 +210,9 @@ class GeoPerson(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Person places map"), GeoGraphyView.__init__(self, _("Person places map"),
pdata, dbstate, uistate, pdata, dbstate, uistate,
PersonBookmarks, PersonBookmarks,
nav_group) nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -278,17 +278,15 @@ class GeoPerson(GeoGraphyView):
all handling of visibility is now in rebuild_trees, see that for more all handling of visibility is now in rebuild_trees, see that for more
information. information.
""" """
if not self.dbstate.is_open(): pass
return
active = self.get_active()
self._createmap(None)
self.uistate.modify_statusbar(self.dbstate)
def animate(self, menu, marks, index, stepyear): def animate(self, menu, marks, index, stepyear):
""" """
Create all movements for the people's event. Create all movements for the people's event.
Yes, you can see the person moving. Yes, you can see the person moving.
""" """
if self.stop: # no more database. stop to work
return
if len(marks) == 0: if len(marks) == 0:
self.already_started = False self.already_started = False
return False return False
@@ -309,7 +307,7 @@ class GeoPerson(GeoGraphyView):
max_lon_lat = float(self._config.get("geography.maximum_lon_lat")) / 10 max_lon_lat = float(self._config.get("geography.maximum_lon_lat")) / 10
if stepyear < 9000: if stepyear < 9000:
if ((abs(float(endlat) - float(startlat)) > max_lon_lat) or if ((abs(float(endlat) - float(startlat)) > max_lon_lat) or
(abs(float(endlon) - float(startlon)) > max_lon_lat)): (abs(float(endlon) - float(startlon)) > max_lon_lat)):
self.large_move = True self.large_move = True
stepyear = 9000 stepyear = 9000
else: else:
@@ -348,8 +346,8 @@ class GeoPerson(GeoGraphyView):
# in this case, stepyear is >= 9000 # in this case, stepyear is >= 9000
# large move means longitude or latitude differences greater than # large move means longitude or latitude differences greater than
# geography.maximum_lon_lat degrees. # geography.maximum_lon_lat degrees.
GLib.timeout_add(int(self._config.get("geography.speed")), self.animate, GLib.timeout_add(int(self._config.get("geography.speed")),
menu, marks, i, stepyear) self.animate, menu, marks, i, stepyear)
return False return False
def _createmap(self, active): def _createmap(self, active):
@@ -383,7 +381,7 @@ class GeoPerson(GeoGraphyView):
# For each event, if we have a place, set a marker. # For each event, if we have a place, set a marker.
self.load_kml_files(person) self.load_kml_files(person)
self.message_layer.add_message( self.message_layer.add_message(
_("Person places for %s") % _nd.display(person)) _("Person places for %s") % _nd.display(person))
for event_ref in person.get_event_ref_list(): for event_ref in person.get_event_ref_list():
if not event_ref: if not event_ref:
continue continue
@@ -391,7 +389,7 @@ class GeoPerson(GeoGraphyView):
self.load_kml_files(event) self.load_kml_files(event)
role = event_ref.get_role() role = event_ref.get_role()
eyear = str( eyear = str(
"%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
@@ -405,8 +403,8 @@ class GeoPerson(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
self.load_kml_files(place) self.load_kml_files(place)
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
@@ -420,16 +418,15 @@ class GeoPerson(GeoGraphyView):
person.gramps_id, person.gramps_id,
place.gramps_id, place.gramps_id,
event.gramps_id, event.gramps_id,
role role)
)
else: else:
self._append_to_places_without_coord( self._append_to_places_without_coord(
place.gramps_id, descr) place.gramps_id, descr)
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
for family_hdl in family_list: for family_hdl in family_list:
family = self.dbstate.db.get_family_from_handle(family_hdl) family = self.dbstate.db.get_family_from_handle(family_hdl)
if family is not None: if family is not None:
fhandle = family_list[0] # first is primary fhandle = family_list[0] # first is primary
fam = dbstate.db.get_family_from_handle(fhandle) fam = dbstate.db.get_family_from_handle(fhandle)
father = mother = None father = mother = None
handle = fam.get_father_handle() handle = fam.get_father_handle()
@@ -446,14 +443,14 @@ class GeoPerson(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle( event = dbstate.db.get_event_from_handle(
event_ref.ref) event_ref.ref)
self.load_kml_files(event) self.load_kml_files(event)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle( place = dbstate.db.get_place_from_handle(
place_handle) place_handle)
if place: if place:
longitude = place.get_longitude() longitude = place.get_longitude()
latitude = place.get_latitude() latitude = place.get_latitude()
@@ -464,21 +461,21 @@ class GeoPerson(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType(event.get_type()) evt = EventType(event.get_type())
eyear = str( eyear = str(
"%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
self.load_kml_files(place) self.load_kml_files(place)
if longitude and latitude: if longitude and latitude:
self._append_to_places_list(descr, self._append_to_places_list(
evt, _nd.display(person), descr,
latitude, longitude, evt, _nd.display(person),
descr1, eyear, latitude, longitude,
event.get_type(), descr1, eyear,
person.gramps_id, event.get_type(),
place.gramps_id, person.gramps_id,
event.gramps_id, place.gramps_id,
role event.gramps_id,
) role)
else: else:
self._append_to_places_without_coord(place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
@@ -605,27 +602,21 @@ class GeoPerson(GeoGraphyView):
grid.set_border_width(12) grid.set_border_width(12)
grid.set_column_spacing(6) grid.set_column_spacing(6)
grid.set_row_spacing(6) grid.set_row_spacing(6)
configdialog.add_text(grid, configdialog.add_text(
_('Animation speed in milliseconds (big value means slower)'), grid,
1, line_wrap=False) _('Animation speed in milliseconds (big value means slower)'),
configdialog.add_slider(grid, 1, line_wrap=False)
"", configdialog.add_slider(grid, "", 2, 'geography.speed', (100, 1000))
2, 'geography.speed',
(100, 1000))
configdialog.add_text( configdialog.add_text(
grid, grid,
_('How many steps between two markers when we are on large move ?'), _('How many steps between two markers when we are on large move ?'),
3, line_wrap=False) 3, line_wrap=False)
configdialog.add_slider(grid, configdialog.add_slider(grid, "", 4, 'geography.steps', (10, 100))
"", configdialog.add_text(
4, 'geography.steps', grid,
(10, 100)) _('The minimum latitude/longitude to select large move.\n'
configdialog.add_text(grid, 'The value is in tenth of degree.'),
_('The minimum latitude/longitude to select large move.\n' 5, line_wrap=False)
'The value is in tenth of degree.'), configdialog.add_slider(grid, "", 6, 'geography.maximum_lon_lat',
5, line_wrap=False) (5, 50))
configdialog.add_slider(grid,
"",
6, 'geography.maximum_lon_lat',
(5, 50))
return _('The animation parameters'), grid return _('The animation parameters'), grid

View File

@@ -23,33 +23,30 @@
""" """
Geography for places Geography for places
""" """
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import time import time
import operator import operator
from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab
from gi.repository import Gtk
from collections import defaultdict from collections import defaultdict
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# set up logging # set up logging
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("GeoGraphy.geoplaces")
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.lib import EventType from gramps.gen.lib import EventType
from gramps.gen.lib import PlaceType from gramps.gen.lib import PlaceType
from gramps.gen.config import config from gramps.gen.config import config
@@ -60,11 +57,14 @@ from gramps.plugins.lib.maps.geography import GeoGraphyView
from gramps.plugins.lib.maps import constants from gramps.plugins.lib.maps import constants
from gramps.gui.utils import ProgressMeter from gramps.gui.utils import ProgressMeter
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
# #
# Constants # Constants
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
KEY_TAB = Gdk.KEY_Tab
_ = glocale.translation.gettext
_LOG = logging.getLogger("GeoGraphy.geoplaces")
_UI_DEF = [ _UI_DEF = [
''' '''
@@ -154,11 +154,12 @@ _UI_DEF = [
# pylint: disable=unused-variable # pylint: disable=unused-variable
# pylint: disable=unused-argument # pylint: disable=unused-argument
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
# #
# GeoView # GeoView
# #
#------------------------------------------------------------------------- # -------------------------------------------------------------------------
class GeoPlaces(GeoGraphyView): class GeoPlaces(GeoGraphyView):
""" """
The view used to render places map. The view used to render places map.
@@ -207,9 +208,9 @@ class GeoPlaces(GeoGraphyView):
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
self.window_name = _('Places map') self.window_name = _('Places map')
GeoGraphyView.__init__(self, self.window_name, GeoGraphyView.__init__(self, self.window_name,
pdata, dbstate, uistate, pdata, dbstate, uistate,
PlaceBookmarks, PlaceBookmarks,
nav_group) nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -270,7 +271,11 @@ class GeoPlaces(GeoGraphyView):
if self.osm is None: if self.osm is None:
return return
self.places_found = [] self.places_found = []
self.build_tree() active = self.uistate.get_active('Place')
if active:
self._createmap(active)
else:
self._createmap(None)
def show_all_places(self, menu, event, lat, lon): def show_all_places(self, menu, event, lat, lon):
""" """
@@ -286,13 +291,7 @@ class GeoPlaces(GeoGraphyView):
all handling of visibility is now in rebuild_trees, see that for more all handling of visibility is now in rebuild_trees, see that for more
information. information.
""" """
if not self.dbstate.is_open(): pass
return
active = self.uistate.get_active('Place')
if active:
self._createmap(active)
else:
self._createmap(None)
def _create_one_place(self, place): def _create_one_place(self, place):
""" """
@@ -316,18 +315,17 @@ class GeoPlaces(GeoGraphyView):
try: try:
colour = (str(place.get_type()), colour = (str(place.get_type()),
self.plc_custom_color[str(place.get_type())]) self.plc_custom_color[str(place.get_type())])
except: except Exception:
colour = self.plc_color[PlaceType.CUSTOM + 1] colour = self.plc_color[PlaceType.CUSTOM + 1]
self._append_to_places_list(descr, None, "", self._append_to_places_list(descr, None, "",
latitude, longitude, latitude, longitude,
None, None, None, None,
EventType.UNKNOWN, EventType.UNKNOWN,
None, # person.gramps_id None, # person.gramps_id
place.gramps_id, place.gramps_id,
None, # event.gramps_id None, # event.gramps_id
None, # family.gramps_id None, # family.gramps_id
color=colour color=colour)
)
def _createmap(self, place_x): def _createmap(self, place_x):
""" """
@@ -386,7 +384,7 @@ class GeoPlaces(GeoGraphyView):
# base "villes de france" : 38101 places : # base "villes de france" : 38101 places :
# createmap : 8'50"; create_markers : 0'07" with pixbuf optimization # createmap : 8'50"; create_markers : 0'07" with pixbuf optimization
# base "villes de france" : 38101 places : # base "villes de france" : 38101 places :
# gramps 3.4 python 2.7 (draw_markers are estimated when moving the map) # gramps 3.4 python 2.7 (draw_markers is estimated when moving the map)
# 38101 places: createmap: 04'32"; # 38101 places: createmap: 04'32";
# create_markers: 0'04"; draw markers: N/A :: 0'03" # create_markers: 0'04"; draw markers: N/A :: 0'03"
# 65598 places: createmap: 10'03"; # 65598 places: createmap: 10'03";
@@ -397,13 +395,13 @@ class GeoPlaces(GeoGraphyView):
# 65598 places: createmap: 08'48"; # 65598 places: createmap: 08'48";
# create_markers: 0'01"; draw markers: 0'07" # create_markers: 0'01"; draw markers: 0'07"
_LOG.debug("%s", time.strftime("start createmap : " _LOG.debug("%s", time.strftime("start createmap : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
self.custom_places() self.custom_places()
if self.show_all: if self.show_all:
self.show_all = False self.show_all = False
try: try:
places_handle = dbstate.db.get_place_handles() places_handle = dbstate.db.get_place_handles()
except: except Exception:
return return
progress = ProgressMeter(self.window_name, progress = ProgressMeter(self.window_name,
can_cancel=False, can_cancel=False,
@@ -416,7 +414,7 @@ class GeoPlaces(GeoGraphyView):
progress.step() progress.step()
progress.close() progress.close()
elif self.generic_filter: elif self.generic_filter:
user=self.uistate.viewmanager.user user = self.uistate.viewmanager.user
place_list = self.generic_filter.apply(dbstate.db, user=user) place_list = self.generic_filter.apply(dbstate.db, user=user)
progress = ProgressMeter(self.window_name, progress = ProgressMeter(self.window_name,
can_cancel=False, can_cancel=False,
@@ -430,55 +428,53 @@ class GeoPlaces(GeoGraphyView):
progress.close() progress.close()
# reset completely the filter. It will be recreated next time. # reset completely the filter. It will be recreated next time.
self.generic_filter = None self.generic_filter = None
elif place_x != None: elif place_x is not None:
place = dbstate.db.get_place_from_handle(place_x) place = dbstate.db.get_place_from_handle(place_x)
self._create_one_place(place) self._create_one_place(place)
self.message_layer.add_message( self.message_layer.add_message(
_("Right click on the map and select 'show all places'" _("Right click on the map and select 'show all places'"
" to show all known places with coordinates. " " to show all known places with coordinates. "
"You can change the markers color depending on place type. " "You can change the markers color depending on place type. "
"You can use filtering.")) "You can use filtering."))
if place.get_latitude() != "" and place.get_longitude() != "": if place.get_latitude() != "" and place.get_longitude() != "":
latitude, longitude = conv_lat_lon(place.get_latitude(), latitude, longitude = conv_lat_lon(place.get_latitude(),
place.get_longitude(), place.get_longitude(),
"D.D8") "D.D8")
if latitude and longitude: if latitude and longitude:
zwc = int(config.get("geography.zoom_when_center"))
self.osm.set_center_and_zoom(float(latitude), self.osm.set_center_and_zoom(float(latitude),
float(longitude), float(longitude),
int(config.get( zwc)
"geography.zoom_when_center")))
else: else:
self.message_layer.add_message( self.message_layer.add_message(
_("Right click on the map and select 'show all places'" _("Right click on the map and select 'show all places'"
" to show all known places with coordinates. " " to show all known places with coordinates. "
"You can use the history to navigate on the map. " "You can use the history to navigate on the map. "
"You can change the markers color depending on place type. " "You can change the markers color depending on place type. "
"You can use filtering.")) "You can use filtering."))
_LOG.debug(" stop createmap.") _LOG.debug(" stop createmap.")
_LOG.debug("%s", time.strftime("begin sort : " _LOG.debug("%s", time.strftime("begin sort : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
self.sort = sorted(self.place_list, self.sort = sorted(self.place_list, key=operator.itemgetter(0))
key=operator.itemgetter(0)
)
_LOG.debug("%s", time.strftime(" end sort : " _LOG.debug("%s", time.strftime(" end sort : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
if self.nbmarkers > 500: # performance issue. Is it the good value ? if self.nbmarkers > 500: # performance issue. Is it the good value ?
self.message_layer.add_message( self.message_layer.add_message(
_("The place name in the status bar is disabled.")) _("The place name in the status bar is disabled."))
self.no_show_places_in_status_bar = True self.no_show_places_in_status_bar = True
if self.nbplaces >= self._config.get("geography.max_places"): if self.nbplaces >= self._config.get("geography.max_places"):
self.message_layer.set_font_attributes(None, None, "red") self.message_layer.set_font_attributes(None, None, "red")
self.message_layer.add_message( self.message_layer.add_message(
_("The maximum number of places is reached (%d).") % _("The maximum number of places is reached (%d).") %
self._config.get("geography.max_places")) self._config.get("geography.max_places"))
self.message_layer.add_message( self.message_layer.add_message(
_("Some information are missing.")) _("Some information are missing."))
self.message_layer.add_message( self.message_layer.add_message(
_("Please, use filtering to reduce this number.")) _("Please, use filtering to reduce this number."))
self.message_layer.add_message( self.message_layer.add_message(
_("You can modify this value in the geography option.")) _("You can modify this value in the geography option."))
self.message_layer.add_message( self.message_layer.add_message(
_("In this case, it may take time to show all markers.")) _("In this case, it may take time to show all markers."))
self._create_markers() self._create_markers()
@@ -589,82 +585,59 @@ class GeoPlaces(GeoGraphyView):
grid.set_border_width(12) grid.set_border_width(12)
grid.set_column_spacing(6) grid.set_column_spacing(6)
grid.set_row_spacing(6) grid.set_row_spacing(6)
configdialog.add_color(grid, configdialog.add_color(grid, _("Unknown"),
_("Unknown"), 1, 'geography.color.unknown', col=1)
1, 'geography.color.unknown', col=1) configdialog.add_color(grid, _("Custom"),
configdialog.add_color(grid, 2, 'geography.color.custom', col=1)
_("Custom"), configdialog.add_color(grid, _("Locality"),
2, 'geography.color.custom', col=1) 3, 'geography.color.locality', col=1)
configdialog.add_color(grid, configdialog.add_color(grid, _("Street"),
_("Locality"), 4, 'geography.color.street', col=1)
3, 'geography.color.locality', col=1) configdialog.add_color(grid, _("Neighborhood"),
configdialog.add_color(grid, 5, 'geography.color.neighborhood', col=1)
_("Street"), configdialog.add_color(grid, _("Borough"),
4, 'geography.color.street', col=1) 6, 'geography.color.borough', col=1)
configdialog.add_color(grid, configdialog.add_color(grid, _("Village"),
_("Neighborhood"), 7, 'geography.color.village', col=1)
5, 'geography.color.neighborhood', col=1) configdialog.add_color(grid, _("Hamlet"),
configdialog.add_color(grid, 8, 'geography.color.hamlet', col=1)
_("Borough"), configdialog.add_color(grid, _("Farm"),
6, 'geography.color.borough', col=1) 9, 'geography.color.farm', col=1)
configdialog.add_color(grid, configdialog.add_color(grid, _("Building"),
_("Village"), 10, 'geography.color.building', col=1)
7, 'geography.color.village', col=1) configdialog.add_color(grid, _("Number"),
configdialog.add_color(grid, 11, 'geography.color.number', col=1)
_("Hamlet"), configdialog.add_color(grid, _("Country"),
8, 'geography.color.hamlet', col=1) 1, 'geography.color.country', col=4)
configdialog.add_color(grid, configdialog.add_color(grid, _("State"),
_("Farm"), 2, 'geography.color.state', col=4)
9, 'geography.color.farm', col=1) configdialog.add_color(grid, _("County"),
configdialog.add_color(grid, 3, 'geography.color.county', col=4)
_("Building"), configdialog.add_color(grid, _("Province"),
10, 'geography.color.building', col=1) 4, 'geography.color.province', col=4)
configdialog.add_color(grid, configdialog.add_color(grid, _("Region"),
_("Number"), 5, 'geography.color.region', col=4)
11, 'geography.color.number', col=1) configdialog.add_color(grid, _("Department"),
configdialog.add_color(grid, 6, 'geography.color.department', col=4)
_("Country"), configdialog.add_color(grid, _("District"),
1, 'geography.color.country', col=4) 7, 'geography.color.district', col=4)
configdialog.add_color(grid, configdialog.add_color(grid, _("Parish"),
_("State"), 8, 'geography.color.parish', col=4)
2, 'geography.color.state', col=4) configdialog.add_color(grid, _("City"),
configdialog.add_color(grid, 9, 'geography.color.city', col=4)
_("County"), configdialog.add_color(grid, _("Town"),
3, 'geography.color.county', col=4) 10, 'geography.color.town', col=4)
configdialog.add_color(grid, configdialog.add_color(grid, _("Municipality"),
_("Province"), 11, 'geography.color.municipality', col=4)
4, 'geography.color.province', col=4)
configdialog.add_color(grid,
_("Region"),
5, 'geography.color.region', col=4)
configdialog.add_color(grid,
_("Department"),
6, 'geography.color.department', col=4)
configdialog.add_color(grid,
_("District"),
7, 'geography.color.district', col=4)
configdialog.add_color(grid,
_("Parish"),
8, 'geography.color.parish', col=4)
configdialog.add_color(grid,
_("City"),
9, 'geography.color.city', col=4)
configdialog.add_color(grid,
_("Town"),
10, 'geography.color.town', col=4)
configdialog.add_color(grid,
_("Municipality"),
11, 'geography.color.municipality', col=4)
self.custom_places() self.custom_places()
if len(self.plc_custom_color) > 0: if len(self.plc_custom_color) > 0:
configdialog.add_text(grid, _("Custom places name"), 12) configdialog.add_text(grid, _("Custom places name"), 12)
start = 13 start = 13
for color in self.plc_custom_color.keys(): for color in self.plc_custom_color.keys():
cust_col = 'geography.color.' + color.lower() cust_col = 'geography.color.' + color.lower()
row = start if start % 2 else start -1 row = start if start % 2 else start - 1
column = 1 if start %2 else 4 column = 1 if start % 2 else 4
configdialog.add_color(grid, color, configdialog.add_color(grid, color, row, cust_col, col=column)
row, cust_col, col=column)
start += 1 start += 1
return _('The places marker color'), grid return _('The places marker color'), grid
@@ -679,7 +652,7 @@ class GeoPlaces(GeoGraphyView):
cust_col = 'geography.color.' + str(place.get_type()).lower() cust_col = 'geography.color.' + str(place.get_type()).lower()
try: try:
color = self._config.get(cust_col) color = self._config.get(cust_col)
except: except Exception:
color = '#008b00' color = '#008b00'
self._config.register(cust_col, color) self._config.register(cust_col, color)
if str(place.get_type()) not in self.plc_custom_color.keys(): if str(place.get_type()) not in self.plc_custom_color.keys():