Geography : pylint up to 9.2 for all modules.

This commit is contained in:
SNoiraud
2016-05-01 18:55:14 +02:00
parent 9d5322103e
commit 780a4be62c
23 changed files with 877 additions and 702 deletions

View File

@@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2010-2012 Serge Noiraud # Copyright (C) 2010-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@@ -2,7 +2,7 @@
# #
# Copyright (C) 2001-2007 Donald N. Allingham, Martin Hawlisch # Copyright (C) 2001-2007 Donald N. Allingham, Martin Hawlisch
# Copyright (C) 2009 Douglas S. Blank # Copyright (C) 2009 Douglas S. Blank
# Copyright (C) 2009 Serge Noiraud # Copyright (C) 2009-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -23,9 +23,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk from gi.repository import Gtk
import cairo
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@@ -38,13 +36,18 @@ _ = glocale.translation.gettext
# 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
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class CairoPrintSave(): class CairoPrintSave(object):
"""Act as an abstract document that can render onto a cairo context. """
Act as an abstract document that can render onto a cairo context.
It can render the model onto cairo context pages, according to the received It can render the model onto cairo context pages, according to the received
page style. page style.
@@ -64,9 +67,11 @@ class CairoPrintSave():
self.heightpx = heightpx self.heightpx = heightpx
self.drawfunc = drawfunc self.drawfunc = drawfunc
self.parent = parent self.parent = parent
self.preview = None
def run(self): def run(self):
"""Create the physical output from the meta document. """
Create the physical output from the meta document.
""" """
global PRINT_SETTINGS global PRINT_SETTINGS
@@ -79,7 +84,8 @@ class CairoPrintSave():
page_setup = Gtk.PageSetup() page_setup = Gtk.PageSetup()
if PRINT_SETTINGS is None: if PRINT_SETTINGS is None:
PRINT_SETTINGS = Gtk.PrintSettings() PRINT_SETTINGS = Gtk.PrintSettings()
page_setup = Gtk.print_run_page_setup_dialog(None, page_setup, PRINT_SETTINGS) page_setup = Gtk.print_run_page_setup_dialog(None, page_setup,
PRINT_SETTINGS)
paper_size_used = page_setup.get_paper_size() paper_size_used = page_setup.get_paper_size()
if self.widthpx > self.heightpx: if self.widthpx > self.heightpx:
szw = self.widthpx szw = self.widthpx
@@ -89,12 +95,13 @@ class CairoPrintSave():
szw = self.heightpx szw = self.heightpx
height_used = paper_size_used.get_height(Gtk.Unit.POINTS) height_used = paper_size_used.get_height(Gtk.Unit.POINTS)
width_used = paper_size_used.get_width(Gtk.Unit.POINTS) width_used = paper_size_used.get_width(Gtk.Unit.POINTS)
coefx = szw / height_used # width and height depends on the selected page (A4, A3, ...) coefx = szw / height_used # width and height depends on the selected
# page (A4, A3, ...)
coefy = szh / width_used coefy = szh / width_used
if coefx < coefy: if coefx < coefy:
self.scale = 100.0 / coefy self.scale = 100.0 / coefy
else: else:
self.scale = 100.0 / coefx self.scale = 100.0 / coefx
PRINT_SETTINGS.set_scale(self.scale) PRINT_SETTINGS.set_scale(self.scale)
if self.widthpx > self.heightpx: if self.widthpx > self.heightpx:
page_setup.set_orientation(Gtk.PageOrientation.LANDSCAPE) page_setup.set_orientation(Gtk.PageOrientation.LANDSCAPE)
@@ -127,13 +134,14 @@ 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.
""" """
cr = context.get_cairo_context() ctx = context.get_cairo_context()
self.drawfunc(self.parent, cr) self.drawfunc(self.parent, ctx)
def on_preview(self, operation, preview, context, parent): def on_preview(self, operation, preview, context, parent):
"""Implement custom print preview functionality. """Implement custom print preview functionality.
We provide a dummy holder here, because on_preview crashes if no We provide a dummy holder here, because on_preview crashes if no
default application is set with gir 3.3.2 (typically evince not installed)! default application is set with gir 3.3.2 (typically evince not
installed)!
""" """
operation.run(Gtk.PrintOperationAction.PREVIEW, None) operation.run(Gtk.PrintOperationAction.PREVIEW, None)
return False return False

View File

@@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2010-2012 Serge Noiraud # Copyright (C) 2010-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@ 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',
@@ -63,7 +65,7 @@ YAHOO_STREET = 14
YAHOO_SATELLITE = 15 YAHOO_SATELLITE = 15
YAHOO_HYBRID = 16 YAHOO_HYBRID = 16
tiles_path = { TILES_PATH = {
OPENSTREETMAP : "openstreetmap", OPENSTREETMAP : "openstreetmap",
OPENSTREETMAP_RENDERER : "openstreetmaprenderer", OPENSTREETMAP_RENDERER : "openstreetmaprenderer",
OPENAERIALMAP : "openaerialmap", OPENAERIALMAP : "openaerialmap",
@@ -82,7 +84,7 @@ tiles_path = {
YAHOO_HYBRID : "yahoohybrid", YAHOO_HYBRID : "yahoohybrid",
} }
map_title = { MAP_TITLE = {
OPENSTREETMAP : "OpenStreetMap", OPENSTREETMAP : "OpenStreetMap",
OPENSTREETMAP_RENDERER : "OpenStreetMap renderer", OPENSTREETMAP_RENDERER : "OpenStreetMap renderer",
OPENAERIALMAP : "OpenAerialMap", OPENAERIALMAP : "OpenAerialMap",
@@ -101,22 +103,16 @@ map_title = {
YAHOO_HYBRID : "Yahoo hybrid", YAHOO_HYBRID : "Yahoo hybrid",
} }
map_type = { MAP_TYPE = {
OPENSTREETMAP : osmgpsmap.MapSource_t.OPENSTREETMAP, OPENSTREETMAP : osmgpsmap.MapSource_t.OPENSTREETMAP,
#OPENSTREETMAP_RENDERER : osmgpsmap.MapSource_t.OPENSTREETMAP_RENDERER,
#OPENAERIALMAP : osmgpsmap.MapSource_t.OPENAERIALMAP,
MAPS_FOR_FREE : osmgpsmap.MapSource_t.MAPS_FOR_FREE, MAPS_FOR_FREE : osmgpsmap.MapSource_t.MAPS_FOR_FREE,
OPENCYCLEMAP : osmgpsmap.MapSource_t.OPENCYCLEMAP, OPENCYCLEMAP : osmgpsmap.MapSource_t.OPENCYCLEMAP,
OSM_PUBLIC_TRANSPORT : osmgpsmap.MapSource_t.OSM_PUBLIC_TRANSPORT, OSM_PUBLIC_TRANSPORT : osmgpsmap.MapSource_t.OSM_PUBLIC_TRANSPORT,
#OSMC_TRAILS : osmgpsmap.MapSource_t.OSMC_TRAILS,
GOOGLE_STREET : osmgpsmap.MapSource_t.GOOGLE_STREET, GOOGLE_STREET : osmgpsmap.MapSource_t.GOOGLE_STREET,
GOOGLE_SATELLITE : osmgpsmap.MapSource_t.GOOGLE_SATELLITE, GOOGLE_SATELLITE : osmgpsmap.MapSource_t.GOOGLE_SATELLITE,
GOOGLE_HYBRID : osmgpsmap.MapSource_t.GOOGLE_HYBRID, GOOGLE_HYBRID : osmgpsmap.MapSource_t.GOOGLE_HYBRID,
VIRTUAL_EARTH_STREET : osmgpsmap.MapSource_t.VIRTUAL_EARTH_STREET, VIRTUAL_EARTH_STREET : osmgpsmap.MapSource_t.VIRTUAL_EARTH_STREET,
VIRTUAL_EARTH_SATELLITE : osmgpsmap.MapSource_t.VIRTUAL_EARTH_SATELLITE, VIRTUAL_EARTH_SATELLITE : osmgpsmap.MapSource_t.VIRTUAL_EARTH_SATELLITE,
VIRTUAL_EARTH_HYBRID : osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID, VIRTUAL_EARTH_HYBRID : osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID,
#YAHOO_STREET : osmgpsmap.MapSource_t.YAHOO_STREET,
#YAHOO_SATELLITE : osmgpsmap.MapSource_t.YAHOO_SATELLITE,
#YAHOO_HYBRID : osmgpsmap.MapSource_t.YAHOO_HYBRID,
} }

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,10 +25,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
import operator
from math import *
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -43,15 +40,14 @@ _LOG = logging.getLogger("maps.datelayer")
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -66,9 +62,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
class DateLayer(GObject.GObject, osmgpsmap.MapLayer): class DateLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display the two extreme dates on the top left of the view This is the layer used to display the two extreme dates
on the top left of the view
""" """
def __init__(self): def __init__(self):
""" """

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,7 +25,6 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -55,7 +54,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
class DummyLayer(GObject.GObject, osmgpsmap.MapLayer): class DummyLayer(GObject.GObject, osmgpsmap.MapLayer):
"""
This is the class for the Dummy layer.
"""
def __init__(self): def __init__(self):
""" """
Initialize the dummy layer Initialize the dummy layer

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,7 +25,6 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -56,7 +55,9 @@ except:
raise raise
class DummyMapNoGpsPoint(osmgpsmap.Map): class DummyMapNoGpsPoint(osmgpsmap.Map):
""" . """
def do_draw_gps_point(self, drawable): def do_draw_gps_point(self, drawable):
""" . """
pass pass
GObject.type_register(DummyMapNoGpsPoint) GObject.type_register(DummyMapNoGpsPoint)

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,12 +28,9 @@
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
import os import os
import sys
import re import re
from gi.repository import GObject
import time import time
from gi.repository import GLib from gi.repository import GLib
from math import pi
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -41,22 +38,19 @@ from math import pi
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GdkPixbuf
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.lib import EventType, Place, PlaceType, 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
from gramps.gui.views.navigationview import NavigationView from gramps.gui.views.navigationview import NavigationView
from gramps.gen.utils.libformatting import FormattingHelper from gramps.gen.utils.libformatting import FormattingHelper
from gramps.gen.errors import WindowActiveError from gramps.gen.errors import WindowActiveError
from gramps.gen.const import HOME_DIR, IMAGE_DIR from gramps.gen.const import HOME_DIR
from gramps.gui.managedwindow import ManagedWindow
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gui.editors import EditPlace, EditEvent, EditFamily, EditPerson from gramps.gui.editors import EditPlace, EditEvent, EditFamily, EditPerson
from gramps.gui.selectors.selectplace import SelectPlace from gramps.gui.selectors.selectplace import SelectPlace
@@ -94,6 +88,11 @@ GEOGRAPHY_PATH = os.path.join(HOME_DIR, "maps")
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>'
# pylint: disable=unused-argument
# pylint: disable=unused-variable
# pylint: disable=no-member
# pylint: disable=maybe-no-member
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
@@ -134,6 +133,7 @@ class GeoGraphyView(OsmGps, NavigationView):
NavigationView.__init__(self, title, pdata, dbstate, uistate, NavigationView.__init__(self, title, pdata, dbstate, uistate,
bm_type, nav_group) bm_type, nav_group)
OsmGps.__init__(self)
self.dbstate = dbstate self.dbstate = dbstate
self.dbstate.connect('database-changed', self.change_db) self.dbstate.connect('database-changed', self.change_db)
self.default_text = "Enter location here!" self.default_text = "Enter location here!"
@@ -141,9 +141,8 @@ class GeoGraphyView(OsmGps, NavigationView):
self.centerlat = config.get("geography.center-lat") self.centerlat = config.get("geography.center-lat")
self.zoom = config.get("geography.zoom") self.zoom = config.get("geography.zoom")
self.lock = config.get("geography.lock") self.lock = config.get("geography.lock")
if config.get('geography.path') == "" : if config.get('geography.path') == "":
config.set('geography.path', GEOGRAPHY_PATH ) config.set('geography.path', GEOGRAPHY_PATH)
OsmGps.__init__(self)
self.format_helper = FormattingHelper(self.dbstate) self.format_helper = FormattingHelper(self.dbstate)
self.centerlat = self.centerlon = 0.0 self.centerlat = self.centerlon = 0.0
@@ -159,23 +158,41 @@ class GeoGraphyView(OsmGps, NavigationView):
None, 0) None, 0)
self.geo_altmap = theme.load_surface('gramps-geo-altmap', 48, 1, self.geo_altmap = theme.load_surface('gramps-geo-altmap', 48, 1,
None, 0) None, 0)
if ( config.get('geography.map_service') in if (config.get('geography.map_service') in
( constants.OPENSTREETMAP, (constants.OPENSTREETMAP,
constants.MAPS_FOR_FREE, constants.MAPS_FOR_FREE,
constants.OPENCYCLEMAP, constants.OPENCYCLEMAP,
constants.OSM_PUBLIC_TRANSPORT, constants.OSM_PUBLIC_TRANSPORT,
)): )):
default_image = self.geo_mainmap default_image = self.geo_mainmap
else: else:
default_image = self.geo_altmap default_image = self.geo_altmap
self.geo_othermap = {} self.geo_othermap = {}
for ident in ( EventType.BIRTH, for ident in (EventType.BIRTH,
EventType.DEATH, EventType.DEATH,
EventType.MARRIAGE ): EventType.MARRIAGE):
icon = constants.ICONS.get(int(ident)) icon = constants.ICONS.get(int(ident))
self.geo_othermap[ident] = theme.load_surface(icon, 48, 1, None, 0) self.geo_othermap[ident] = theme.load_surface(icon, 48, 1, None, 0)
self.maxyear = 0
self.minyear = 9999
self.maxlat = 0.0
self.minlat = 0.0
self.maxlon = 0.0
self.minlon = 0.0
self.longt = 0.0
self.latit = 0.0
self.itemoption = None
self.menu = None
self.mark = None
self.path_entry = None
self.changemap = None
self.clearmap = None
self.nbplaces = 0
def add_bookmark(self, menu): def add_bookmark(self, menu):
"""
Add the place to the bookmark
"""
mlist = self.selected_handles() mlist = self.selected_handles()
if mlist: if mlist:
self.bookmarks.add(mlist[0]) self.bookmarks.add(mlist[0])
@@ -188,6 +205,9 @@ class GeoGraphyView(OsmGps, NavigationView):
def add_bookmark_from_popup(self, menu, handle): def add_bookmark_from_popup(self, menu, handle):
"""
Add the place to the bookmark from the popup menu
"""
if handle: if handle:
self.uistate.set_active(handle, self.navigation_type()) self.uistate.set_active(handle, self.navigation_type())
self.bookmarks.add(handle) self.bookmarks.add(handle)
@@ -320,7 +340,7 @@ class GeoGraphyView(OsmGps, NavigationView):
else: else:
title = _('Add cross hair') title = _('Add cross hair')
add_item = Gtk.MenuItem(label=title) add_item = Gtk.MenuItem(label=title)
add_item.connect("activate", self.config_crosshair, event, lat , lon) add_item.connect("activate", self.config_crosshair, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
@@ -330,27 +350,27 @@ class GeoGraphyView(OsmGps, NavigationView):
title = _('Lock zoom and position') title = _('Lock zoom and position')
add_item = Gtk.MenuItem(label=title) add_item = Gtk.MenuItem(label=title)
add_item.connect("activate", self.config_zoom_and_position, add_item.connect("activate", self.config_zoom_and_position,
event, lat , lon) event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Add place")) add_item = Gtk.MenuItem(label=_("Add place"))
add_item.connect("activate", self.add_place, event, lat , lon) add_item.connect("activate", self.add_place, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Link place")) add_item = Gtk.MenuItem(label=_("Link place"))
add_item.connect("activate", self.link_place, event, lat , lon) add_item.connect("activate", self.link_place, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Add place from kml")) add_item = Gtk.MenuItem(label=_("Add place from kml"))
add_item.connect("activate", self.add_place_from_kml, event, lat , lon) add_item.connect("activate", self.add_place_from_kml, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Center here")) add_item = Gtk.MenuItem(label=_("Center here"))
add_item.connect("activate", self.set_center, event, lat , lon) add_item.connect("activate", self.set_center, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
@@ -361,7 +381,7 @@ class GeoGraphyView(OsmGps, NavigationView):
add_item.show() add_item.show()
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 =>") % { title = _("Replace '%(map)s' by =>") % {
'map' : map_name 'map' : map_name
} }
@@ -375,10 +395,10 @@ class GeoGraphyView(OsmGps, NavigationView):
changemap.show() changemap.show()
add_item.set_submenu(changemap) add_item.set_submenu(changemap)
# show in the map menu all available providers # show in the map menu all available providers
for map in constants.map_type: for my_map in constants.MAP_TYPE:
changemapitem = Gtk.MenuItem(label=constants.map_title[map]) changemapitem = Gtk.MenuItem(label=constants.MAP_TITLE[my_map])
changemapitem.show() changemapitem.show()
changemapitem.connect("activate", self.change_map, map) changemapitem.connect("activate", self.change_map, my_map)
changemap.append(changemapitem) changemap.append(changemapitem)
clear_text = _("Clear the '%(map)s' tiles cache.") % { clear_text = _("Clear the '%(map)s' tiles cache.") % {
@@ -386,7 +406,9 @@ class GeoGraphyView(OsmGps, NavigationView):
} }
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, constants.tiles_path[config.get("geography.map_service")]) clearmap.connect("activate", self.clear_map,
constants.TILES_PATH[config.get(
"geography.map_service")])
clearmap.show() clearmap.show()
menu.append(clearmap) menu.append(clearmap)
@@ -402,7 +424,7 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
import shutil import shutil
path = "%s%c%s" % ( config.get('geography.path'), os.sep, the_map ) path = "%s%c%s" % (config.get('geography.path'), os.sep, the_map)
shutil.rmtree(path) shutil.rmtree(path)
def add_specific_menu(self, menu, event, lat, lon): def add_specific_menu(self, menu, event, lat, lon):
@@ -450,22 +472,21 @@ class GeoGraphyView(OsmGps, NavigationView):
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[3]) mlatp = precision % float(mark[3])
mlonp = precision % float(mark[4]) mlonp = precision % float(mark[4])
latok = lonok = False latok = lonok = False
_LOG.debug(" compare latitude : %s with %s (precision = %s)" _LOG.debug(" compare latitude : %s with %s (precision = %s)"
" place='%s'" % (float(mark[3]), lat, precision, " place='%s'", float(mark[3]), lat, precision, mark[0])
mark[0]))
_LOG.debug("compare longitude : %s with %s (precision = %s)" _LOG.debug("compare longitude : %s with %s (precision = %s)"
" zoom=%d" % (float(mark[4]), lon, precision, " zoom=%d", float(mark[4]), lon, precision,
config.get("geography.zoom"))) config.get("geography.zoom"))
if (float(mlatp) >= (float(latp) - shift) ) and \ if (float(mlatp) >= (float(latp) - shift)) and \
(float(mlatp) <= (float(latp) + shift) ): (float(mlatp) <= (float(latp) + shift)):
latok = True latok = True
if (float(mlonp) >= (float(lonp) - shift) ) and \ if (float(mlonp) >= (float(lonp) - shift)) and \
(float(mlonp) <= (float(lonp) + shift) ): (float(mlonp) <= (float(lonp) + shift)):
lonok = True lonok = True
if latok and lonok: if latok and lonok:
mark_selected.append(mark) mark_selected.append(mark)
@@ -499,8 +520,8 @@ class GeoGraphyView(OsmGps, NavigationView):
Add a new marker Add a new marker
""" """
mapservice = config.get('geography.map_service') mapservice = config.get('geography.map_service')
if ( mapservice in ( constants.OPENSTREETMAP, if (mapservice in (constants.OPENSTREETMAP,
constants.OPENSTREETMAP_RENDERER )): constants.OPENSTREETMAP_RENDERER)):
default_image = self.geo_mainmap default_image = self.geo_mainmap
else: else:
default_image = self.geo_altmap default_image = self.geo_altmap
@@ -544,7 +565,8 @@ class GeoGraphyView(OsmGps, NavigationView):
Create a list of places with coordinates. Create a list of places with coordinates.
""" """
found = any(p[0] == place for p in self.places_found) found = any(p[0] == place for p in self.places_found)
if not found and self.nbplaces < self._config.get("geography.max_places"): if not found and (self.nbplaces <
self._config.get("geography.max_places")):
# We only show the first "geography.max_places". # We only show the first "geography.max_places".
# over 3000 or 4000 places, the geography become unusable. # over 3000 or 4000 places, the geography become unusable.
# In this case, filter the places ... # In this case, filter the places ...
@@ -590,19 +612,19 @@ class GeoGraphyView(OsmGps, NavigationView):
self.remove_all_markers() self.remove_all_markers()
self.remove_all_gps() self.remove_all_gps()
self.remove_all_tracks() self.remove_all_tracks()
if ( self.current_map is not None and if (self.current_map is not None and
self.current_map != config.get("geography.map_service") ): self.current_map != config.get("geography.map_service")):
self.change_map(self.osm, config.get("geography.map_service")) self.change_map(self.osm, config.get("geography.map_service"))
last = "" last = ""
current = "" current = ""
differtype = False differtype = False
savetype = None #savetype = None
lat = 0.0 lat = 0.0
lon = 0.0 lon = 0.0
icon = None icon = None
count = 0 count = 0
self.uistate.set_busy_cursor(True) self.uistate.set_busy_cursor(True)
_LOG.debug("%s" % time.strftime("start create_marker : " _LOG.debug("%s", time.strftime("start create_marker : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
for mark in self.sort: for mark in self.sort:
current = ([mark[3], mark[4]]) current = ([mark[3], mark[4]])
@@ -626,10 +648,10 @@ class GeoGraphyView(OsmGps, NavigationView):
count += 1 count += 1
if icon != mark[7]: if icon != mark[7]:
differtype = True differtype = True
if ( lat != 0.0 and lon != 0.0 ): if lat != 0.0 and lon != 0.0:
self.add_marker(None, None, lat, lon, icon, differtype, count) self.add_marker(None, None, lat, lon, icon, differtype, count)
self._set_center_and_zoom() self._set_center_and_zoom()
_LOG.debug("%s" % time.strftime(" stop create_marker : " _LOG.debug("%s", time.strftime(" stop create_marker : "
"%a %d %b %Y %H:%M:%S", time.gmtime())) "%a %d %b %Y %H:%M:%S", time.gmtime()))
self.uistate.set_busy_cursor(False) self.uistate.set_busy_cursor(False)
@@ -646,17 +668,17 @@ class GeoGraphyView(OsmGps, NavigationView):
pt2 = bbox[1] pt2 = bbox[1]
s_bbox_lat2 = pt2.rlat + 10.0 s_bbox_lat2 = pt2.rlat + 10.0
s_bbox_lon2 = pt2.rlon + 10.0 s_bbox_lon2 = pt2.rlon + 10.0
result = ( s_bbox_lat1 > s_lat > s_bbox_lat2 ) and \ result = ((s_bbox_lat1 > s_lat > s_bbox_lat2) and
( s_bbox_lon1 < s_lon < s_bbox_lon2 ) (s_bbox_lon1 < s_lon < s_bbox_lon2))
return result return result
def _autozoom_in(self, lvl, p1lat, p1lon, p2lat, p2lon): def _autozoom_in(self, lvl, p1lat, p1lon, p2lat, p2lon):
""" """
We zoom in until at least one marker missing. We zoom in until at least one marker missing.
""" """
if ( ( self._visible_marker(p1lat, p1lon) if ((self._visible_marker(p1lat, p1lon)
and self._visible_marker(p2lat, p2lon) ) and self._visible_marker(p2lat, p2lon))
and lvl < 18 ): and lvl < 18):
lvl += 1 lvl += 1
self.osm.set_zoom(lvl) self.osm.set_zoom(lvl)
GLib.timeout_add(int(50), self._autozoom_in, lvl, GLib.timeout_add(int(50), self._autozoom_in, lvl,
@@ -669,9 +691,9 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
We zoom out until all markers visible. We zoom out until all markers visible.
""" """
if ( not ( self._visible_marker(p1lat, p1lon) if (not (self._visible_marker(p1lat, p1lon)
and self._visible_marker(p2lat, p2lon) ) and self._visible_marker(p2lat, p2lon))
and lvl > 1 ): and lvl > 1):
lvl -= 1 lvl -= 1
self.osm.set_zoom(lvl) self.osm.set_zoom(lvl)
GLib.timeout_add(int(50), self._autozoom_out, lvl, GLib.timeout_add(int(50), self._autozoom_out, lvl,
@@ -691,8 +713,8 @@ class GeoGraphyView(OsmGps, NavigationView):
level_start = self.osm.props.zoom level_start = self.osm.props.zoom
p1lat, p1lon = self.begin_selection.get_degrees() p1lat, p1lon = self.begin_selection.get_degrees()
p2lat, p2lon = self.end_selection.get_degrees() p2lat, p2lon = self.end_selection.get_degrees()
lat = p1lat + ( p2lat - p1lat ) / 2 lat = p1lat + (p2lat - p1lat) / 2
lon = p1lon + ( p2lon - p1lon ) / 2 lon = p1lon + (p2lon - p1lon) / 2
# We center the map on the center of the region # We center the map on the center of the region
self.osm.set_center(lat, lon) self.osm.set_center(lat, lon)
self.save_center(lat, lon) self.save_center(lat, lon)
@@ -733,7 +755,7 @@ class GeoGraphyView(OsmGps, NavigationView):
maxlat = abs(abs(self.minlat) + abs(self.maxlat)) maxlat = abs(abs(self.minlat) + abs(self.maxlat))
latit = longt = 0.0 latit = longt = 0.0
for mark in self.sort: for mark in self.sort:
if ( signminlat == signmaxlat ): if signminlat == signmaxlat:
if signminlat == 1: if signminlat == 1:
latit = self.minlat+self.centerlat latit = self.minlat+self.centerlat
else: else:
@@ -742,7 +764,7 @@ class GeoGraphyView(OsmGps, NavigationView):
latit = self.maxlat-self.centerlat latit = self.maxlat-self.centerlat
else: else:
latit = self.minlat+self.centerlat latit = self.minlat+self.centerlat
if ( signminlon == signmaxlon ): if signminlon == signmaxlon:
if signminlon == 1: if signminlon == 1:
longt = self.minlon+self.centerlon longt = self.minlon+self.centerlon
else: else:
@@ -759,7 +781,7 @@ class GeoGraphyView(OsmGps, NavigationView):
if config.get("geography.lock"): if config.get("geography.lock"):
self.osm.set_center_and_zoom(config.get("geography.center-lat"), self.osm.set_center_and_zoom(config.get("geography.center-lat"),
config.get("geography.center-lon"), config.get("geography.center-lon"),
config.get("geography.zoom") ) config.get("geography.zoom"))
else: else:
self._autozoom() self._autozoom()
self.save_center(self.latit, self.longt) self.save_center(self.latit, self.longt)
@@ -789,7 +811,7 @@ class GeoGraphyView(OsmGps, NavigationView):
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
fnam = _nd.display(father) if father else _("Unknown") fnam = _nd.display(father) if father else _("Unknown")
mnam = _nd.display(mother) if mother else _("Unknown") mnam = _nd.display(mother) if mother else _("Unknown")
return ( fnam, mnam ) return (fnam, mnam)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -884,7 +906,7 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
Edit the selected person at the marker position Edit the selected person at the marker position
""" """
_LOG.debug("edit_person : %s" % mark[8]) _LOG.debug("edit_person : %s", mark[8])
# need to add code here to edit the person. # need to add code here to edit the person.
person = self.dbstate.db.get_person_from_gramps_id(mark[8]) person = self.dbstate.db.get_person_from_gramps_id(mark[8])
try: try:
@@ -896,7 +918,7 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
Edit the selected family at the marker position Edit the selected family at the marker position
""" """
_LOG.debug("edit_family : %s" % mark[11]) _LOG.debug("edit_family : %s", mark[11])
family = self.dbstate.db.get_family_from_gramps_id(mark[11]) family = self.dbstate.db.get_family_from_gramps_id(mark[11])
try: try:
EditFamily(self.dbstate, self.uistate, [], family) EditFamily(self.dbstate, self.uistate, [], family)
@@ -907,7 +929,7 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
Edit the selected event at the marker position Edit the selected event at the marker position
""" """
_LOG.debug("edit_event : %s" % mark[10]) _LOG.debug("edit_event : %s", mark[10])
event = self.dbstate.db.get_event_from_gramps_id(mark[10]) event = self.dbstate.db.get_event_from_gramps_id(mark[10])
try: try:
EditEvent(self.dbstate, self.uistate, [], event) EditEvent(self.dbstate, self.uistate, [], event)
@@ -933,8 +955,8 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
# Ask for the kml file # Ask for the kml file
filter = Gtk.FileFilter() filtering = Gtk.FileFilter()
filter.add_pattern("*.kml") filtering.add_pattern("*.kml")
kml = Gtk.FileChooserDialog( kml = Gtk.FileChooserDialog(
_("Select a kml file used to add places"), _("Select a kml file used to add places"),
action=Gtk.FileChooserAction.OPEN, action=Gtk.FileChooserAction.OPEN,
@@ -943,7 +965,7 @@ class GeoGraphyView(OsmGps, NavigationView):
_('_Apply'), Gtk.ResponseType.OK)) _('_Apply'), Gtk.ResponseType.OK))
mpath = HOME_DIR mpath = HOME_DIR
kml.set_current_folder(os.path.dirname(mpath)) kml.set_current_folder(os.path.dirname(mpath))
kml.set_filter(filter) kml.set_filter(filtering)
status = kml.run() status = kml.run()
if status == Gtk.ResponseType.OK: if status == Gtk.ResponseType.OK:
@@ -1167,20 +1189,27 @@ class GeoGraphyView(OsmGps, NavigationView):
(1000, 10000)) (1000, 10000))
configdialog.add_checkbox(grid, configdialog.add_checkbox(grid,
_('Use keypad for shortcuts :\n' _('Use keypad for shortcuts :\n'
'Either we choose the + and - from the keypad if we select this,\n' 'Either we choose the + and - from the keypad if we '
'select this,\n'
'or we use the characters from the keyboard.'), 'or we use the characters from the keyboard.'),
5, 'geography.use-keypad', 5, 'geography.use-keypad',
extra_callback=self.update_shortcuts) extra_callback=self.update_shortcuts)
return _('The map'), grid return _('The map'), grid
def set_tilepath(self, *obj): def set_tilepath(self, *obj):
"""
Save the tile path in the config section.
"""
if self.path_entry.get_text().strip(): if self.path_entry.get_text().strip():
config.set('geography.path', self.path_entry.get_text()) config.set('geography.path', self.path_entry.get_text())
else: else:
config.set('geography.path', GEOGRAPHY_PATH ) config.set('geography.path', GEOGRAPHY_PATH)
def select_tilepath(self, *obj): def select_tilepath(self, *obj):
f = Gtk.FileChooserDialog( """
Call a file chooser selection box to select the tile path.
"""
selected_dir = Gtk.FileChooserDialog(
_("Select tile cache directory for offline mode"), _("Select tile cache directory for offline mode"),
action=Gtk.FileChooserAction.SELECT_FOLDER, action=Gtk.FileChooserAction.SELECT_FOLDER,
parent=self.uistate.window, parent=self.uistate.window,
@@ -1191,12 +1220,11 @@ class GeoGraphyView(OsmGps, NavigationView):
mpath = config.get('geography.path') mpath = config.get('geography.path')
if not mpath: if not mpath:
mpath = HOME_DIR mpath = HOME_DIR
f.set_current_folder(os.path.dirname(mpath)) selected_dir.set_current_folder(os.path.dirname(mpath))
status = f.run() status = selected_dir.run()
if status == Gtk.ResponseType.OK: if status == Gtk.ResponseType.OK:
val = f.get_filename() val = selected_dir.get_filename()
if val: if val:
self.path_entry.set_text(val) self.path_entry.set_text(val)
f.destroy() selected_dir.destroy()

View File

@@ -20,18 +20,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id: dummynogps.py 20708 2012-11-27 04:31:14Z paul-franklin $
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os,sys
from gi.repository import GObject from gi.repository import GObject
import operator
from math import *
import xml.etree.ElementTree as ETree
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -47,7 +41,6 @@ _LOG = logging.getLogger("maps.kmllayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk from gi.repository import Gdk
import cairo import cairo
from gi.repository import Pango, PangoCairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -69,14 +62,20 @@ try:
except: except:
raise raise
# pylint: disable=unused-variable
# pylint: disable=unused-argument
# pylint: disable=no-member
class KmlLayer(GObject.GObject, osmgpsmap.MapLayer): class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display kml files over the map This is the layer used to display kml files over the map
* Allowed : points, paths and polygons. * Allowed : points, paths and polygons.
* One point : name, (latitude, longitude) * One point : name, (latitude, longitude)
* One path : name, type, color, transparency, [ (latitude, longitude), (latitude, longitude), ...] * One path : name, type, color, transparency,
* One polygon : name, type, color, transparency, [ (latitude, longitude), (latitude, longitude), ...] * [ (latitude, longitude), (latitude, longitude), ...]
* One polygon : name, type, color, transparency,
* [ (latitude, longitude), (latitude, longitude), ...]
""" """
def __init__(self): def __init__(self):
""" """
@@ -89,6 +88,7 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
self.name = "" self.name = ""
self.type = "" self.type = ""
self.points = [] self.points = []
self.kml = None
def clear(self): def clear(self):
""" """
@@ -122,7 +122,8 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
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])
coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt) (coord_x,
coord_y) = gpsmap.convert_geographic_to_screen(conv_pt)
map_points.append((coord_x, coord_y)) map_points.append((coord_x, coord_y))
first = True first = True
ctx.save() ctx.save()
@@ -137,9 +138,11 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
for idx_pt in range(0, len(map_points)): for idx_pt in range(0, len(map_points)):
if first: if first:
first = False first = False
ctx.move_to(map_points[idx_pt][0], map_points[idx_pt][1]) ctx.move_to(map_points[idx_pt][0],
map_points[idx_pt][1])
else: else:
ctx.line_to(map_points[idx_pt][0], map_points[idx_pt][1]) ctx.line_to(map_points[idx_pt][0],
map_points[idx_pt][1])
ctx.close_path() ctx.close_path()
if ptype == "Polygon": if ptype == "Polygon":
ctx.stroke() ctx.stroke()
@@ -156,7 +159,8 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
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])
coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt) (coord_x,
coord_y) = gpsmap.convert_geographic_to_screen(conv_pt)
map_points.append((coord_x, coord_y)) map_points.append((coord_x, coord_y))
first = True first = True
ctx.save() ctx.save()
@@ -169,9 +173,11 @@ class KmlLayer(GObject.GObject, osmgpsmap.MapLayer):
for idx_pt in range(0, len(map_points)): for idx_pt in range(0, len(map_points)):
if first: if first:
first = False first = False
ctx.move_to(map_points[idx_pt][0], map_points[idx_pt][1]) ctx.move_to(map_points[idx_pt][0],
map_points[idx_pt][1])
else: else:
ctx.line_to(map_points[idx_pt][0], map_points[idx_pt][1]) ctx.line_to(map_points[idx_pt][0],
map_points[idx_pt][1])
ctx.stroke() ctx.stroke()
ctx.restore() ctx.restore()

View File

@@ -25,10 +25,8 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os,sys import os
from gi.repository import GObject from gi.repository import GObject
import operator
from math import *
import xml.etree.ElementTree as ETree import xml.etree.ElementTree as ETree
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -39,6 +37,8 @@ import xml.etree.ElementTree as ETree
import 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
@@ -46,7 +46,8 @@ class Kml(GObject.GObject):
* One point : name, (latitude, longitude) * One point : name, (latitude, longitude)
* One path : name, [ (latitude, longitude), (latitude, longitude), ...] * One path : name, [ (latitude, longitude), (latitude, longitude), ...]
* One polygon : name, type, color, [ (latitude, longitude), (latitude, longitude), ...] * One polygon : name, type, color,
* [ (latitude, longitude), (latitude, longitude), ...]
* Some kml files use the altitude. We don't use it. * Some kml files use the altitude. We don't use it.
@@ -54,7 +55,8 @@ class Kml(GObject.GObject):
def __init__(self, kml_file): def __init__(self, kml_file):
""" """
Initialize the library Initialize the library
The access right and validity of the kmlfile must be verified before this method. The access right and validity of the kmlfile must be verified
before this method.
""" """
GObject.GObject.__init__(self) GObject.GObject.__init__(self)
self.tag = "" self.tag = ""
@@ -68,8 +70,8 @@ class Kml(GObject.GObject):
self.polygons = [] self.polygons = []
self.tree = ETree.parse(kml_file) self.tree = ETree.parse(kml_file)
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, extension = os.path.splitext(kml_file)
fdir, self.kmlfile = os.path.split(fname) fdir, self.kmlfile = os.path.split(fname)
@@ -110,49 +112,50 @@ class Kml(GObject.GObject):
""" """
Get all the coordinates for this marker Get all the coordinates for this marker
""" """
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'coordinates': if sub_attribute.tag == self.tag + 'coordinates':
self.get_coordinates(subAttribute) self.get_coordinates(sub_attribute)
def get_polygon_outer_boundary(self, attributes): def get_polygon_outer_boundary(self, attributes):
""" """
This function get the coordinates used to draw a filled polygon. This function get the coordinates used to draw a filled polygon.
""" """
self.type = 'OuterPolygon' self.type = 'OuterPolygon'
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'LinearRing': if sub_attribute.tag == self.tag + 'LinearRing':
self.get_linear_ring(subAttribute) self.get_linear_ring(sub_attribute)
def get_polygon_inner_boundary(self, attributes): def get_polygon_inner_boundary(self, attributes):
""" """
This function get the coordinates used to draw a hole inside a filled polygon. This function get the coordinates used to draw a hole inside
a filled polygon.
""" """
self.type = 'InnerPolygon' self.type = 'InnerPolygon'
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'LinearRing': if sub_attribute.tag == self.tag + 'LinearRing':
self.get_linear_ring(subAttribute) self.get_linear_ring(sub_attribute)
def get_polygon(self, attributes): def get_polygon(self, attributes):
""" """
Get all the coordinates for the polygon Get all the coordinates for the polygon
""" """
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'outerBoundaryIs': if sub_attribute.tag == self.tag + 'outerBoundaryIs':
self.get_polygon_outer_boundary(subAttribute) self.get_polygon_outer_boundary(sub_attribute)
self.polygons.append((self.name, self.polygons.append((self.name,
self.type, self.type,
self.color, self.color,
self.transparency, self.transparency,
self.points)) self.points))
if subAttribute.tag == self.tag + 'innerBoundaryIs': if sub_attribute.tag == self.tag + 'innerBoundaryIs':
self.get_polygon_inner_boundary(subAttribute) self.get_polygon_inner_boundary(sub_attribute)
self.polygons.append((self.name, self.polygons.append((self.name,
self.type, self.type,
self.color, self.color,
self.transparency, self.transparency,
self.points)) self.points))
if subAttribute.tag == self.tag + 'LinearRing': if sub_attribute.tag == self.tag + 'LinearRing':
self.get_linear_ring(subAttribute) self.get_linear_ring(sub_attribute)
self.type = 'Polygon' self.type = 'Polygon'
self.polygons.append((self.name, self.polygons.append((self.name,
self.type, self.type,
@@ -165,18 +168,18 @@ class Kml(GObject.GObject):
Get all the coordinates for this marker Get all the coordinates for this marker
""" """
self.type = 'Point' self.type = 'Point'
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'coordinates': if sub_attribute.tag == self.tag + 'coordinates':
self.get_coordinates(subAttribute) self.get_coordinates(sub_attribute)
def get_path(self, attributes): def get_path(self, attributes):
""" """
Get all the coordinates for this marker Get all the coordinates for this marker
""" """
self.type = 'Path' self.type = 'Path'
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'coordinates': if sub_attribute.tag == self.tag + 'coordinates':
self.get_coordinates(subAttribute) self.get_coordinates(sub_attribute)
self.paths.append((self.name, self.paths.append((self.name,
self.type, self.type,
self.color, self.color,
@@ -184,45 +187,48 @@ class Kml(GObject.GObject):
self.points)) self.points))
def get_multi_geometry(self, attributes): def get_multi_geometry(self, attributes):
for subAttribute in attributes: """
if subAttribute.tag == self.tag + 'Polygon': Do we have some sub structures ?
self.polygon(subAttribute) """
if subAttribute.tag == self.tag + 'LineString': for sub_attribute in attributes:
self.get_path(subAttribute) if sub_attribute.tag == self.tag + 'Polygon':
self.get_polygon(sub_attribute)
if sub_attribute.tag == self.tag + 'LineString':
self.get_path(sub_attribute)
def add_kml(self): def add_kml(self):
""" """
Add a kml file. Add a kml file.
""" """
lineStrings = self.tree.findall('.//' + self.tag + 'Placemark') line_strings = self.tree.findall('.//' + self.tag + 'Placemark')
for attributes in lineStrings: for attributes in line_strings:
self.points = [] self.points = []
self.set_default() self.set_default()
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'name': if sub_attribute.tag == self.tag + 'name':
self.name = subAttribute.text self.name = sub_attribute.text
if subAttribute.tag == self.tag + 'Polygon': if sub_attribute.tag == self.tag + 'Polygon':
self.get_polygon(subAttribute) self.get_polygon(sub_attribute)
if subAttribute.tag == self.tag + 'LineString': if sub_attribute.tag == self.tag + 'LineString':
self.get_path(subAttribute) self.get_path(sub_attribute)
if subAttribute.tag == self.tag + 'MultiGeometry': if sub_attribute.tag == self.tag + 'MultiGeometry':
self.get_multi_geometry(subAttribute) self.get_multi_geometry(sub_attribute)
return (self.paths, self.polygons) return (self.paths, self.polygons)
def add_points(self): def add_points(self):
""" """
Add points or markers Add points or markers
""" """
lineStrings = self.tree.findall('.//' + self.tag + 'Placemark') line_strings = self.tree.findall('.//' + self.tag + 'Placemark')
self.markers = [] self.markers = []
for attributes in lineStrings: for attributes in line_strings:
self.points = [] self.points = []
self.set_default() self.set_default()
for subAttribute in attributes: for sub_attribute in attributes:
if subAttribute.tag == self.tag + 'name': if sub_attribute.tag == self.tag + 'name':
self.name = subAttribute.text self.name = sub_attribute.text
if subAttribute.tag == self.tag + 'Point': if sub_attribute.tag == self.tag + 'Point':
self.get_point(subAttribute) self.get_point(sub_attribute)
self.markers.append((self.name, self.points)) self.markers.append((self.name, self.points))
return self.markers return self.markers

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,9 +25,8 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
from math import * from math import pi
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -42,15 +41,14 @@ _LOG = logging.getLogger("maps.lifeway")
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -65,6 +63,8 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer): class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display tracks or the life way for one or several This is the layer used to display tracks or the life way for one or several
@@ -93,7 +93,7 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
alpha is the transparence alpha is the transparence
radius is the size of the track. radius is the size of the track.
""" """
if isinstance(color,str): if isinstance(color, str):
color = Gdk.color_parse(color) color = Gdk.color_parse(color)
self.lifeways_ref.append((points, color, radius)) self.lifeways_ref.append((points, color, radius))
@@ -101,7 +101,7 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
Add a track or life way. Add a track or life way.
""" """
if isinstance(color,str): if isinstance(color, str):
color = Gdk.color_parse(color) color = Gdk.color_parse(color)
self.lifeways.append((points, color)) self.lifeways.append((points, color))
@@ -121,24 +121,29 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
rds = float(lifeway[2]) rds = float(lifeway[2])
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(conv_pt1) coord_x1, coord_y1 = gpsmap.convert_geographic_to_screen(
conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0]+rds, point[1]) conv_pt1)
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(conv_pt2) conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0]+rds,
point[1])
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(
conv_pt2)
coy = abs(coord_y2-coord_y1) coy = abs(coord_y2-coord_y1)
conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0], point[1]+rds) conv_pt2 = osmgpsmap.MapPoint.new_degrees(point[0],
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(conv_pt2) point[1]+rds)
coord_x2, coord_y2 = gpsmap.convert_geographic_to_screen(
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
coz = abs( 1.0 / float(cox) * float(coy) ) coz = abs(1.0 / float(cox) * float(coy))
coz = coz if coz > 1.2 else 1.2 coz = coz if coz > 1.2 else 1.2
ctx.save() ctx.save()
ctx.scale(1.0,coz) ctx.scale(1.0, coz)
ctx.move_to(coord_x1, coord_y1) ctx.move_to(coord_x1, coord_y1)
ctx.translate(coord_x1, coord_y1/coz) ctx.translate(coord_x1, coord_y1/coz)
ctx.arc(0.0, 0.0, cox, 0.0, 2*pi) ctx.arc(0.0, 0.0, cox, 0.0, 2*pi)
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.set_line_width(2.0) ctx.set_line_width(2.0)
ctx.arc(0.0, 0.0, cox, 0.0, 2*pi) ctx.arc(0.0, 0.0, cox, 0.0, 2*pi)
ctx.stroke() ctx.stroke()
@@ -164,7 +169,7 @@ class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
else: else:
ctx.line_to(map_points[idx_pt][0], map_points[idx_pt][1]) ctx.line_to(map_points[idx_pt][0], map_points[idx_pt][1])
ctx.stroke() ctx.stroke()
if len(map_points) == 1 : # We have only one point if len(map_points) == 1: # We have only one point
crdx = map_points[0][0] crdx = map_points[0][0]
crdy = map_points[0][1] crdy = map_points[0][1]
ctx.move_to(crdx, crdy) ctx.move_to(crdx, crdy)

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,9 +25,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
from math import *
import time import time
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -37,15 +35,12 @@ import time
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger("maps.markerlayer") _LOG = logging.getLogger("maps.markerlayer")
#_LOG = logging.getLogger("GeoGraphy.markerlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gtk
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -66,6 +61,8 @@ 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.
@@ -121,7 +118,7 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
max_interval = 0.01 max_interval = 0.01
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:
ctx.save() ctx.save()
@@ -131,28 +128,28 @@ class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
if mark > self.nb_ref_by_places: if mark > self.nb_ref_by_places:
# at maximum, we'll have an icon size = (0.6 + 0.3) * 48 = 43.2 # at maximum, we'll have an icon size = (0.6 + 0.3) * 48 = 43.2
size += (0.3 * ((mark - self.nb_ref_by_places) size += (0.3 * ((mark - self.nb_ref_by_places)
/ max_interval) ) / max_interval))
else: else:
# at minimum, we'll have an icon size = (0.6 - 0.3) * 48 = 14.4 # at minimum, we'll have an icon size = (0.6 - 0.3) * 48 = 14.4
size -= (0.3 * ((self.nb_ref_by_places - mark) size -= (0.3 * ((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)
ctx.translate(coord_x, coord_y) ctx.translate(coord_x, coord_y)
ctx.scale( size, size) ctx.scale(size, size)
# below, we try to place exactly the marker depending on its size. # below, we try to place exactly the marker depending on its size.
# Normaly, the left top corner of the image is set to the coordinates. # The left top corner of the image is set to the coordinates.
# The tip of the pin which should be at the marker position is at # The tip of the pin which should be at the marker position is at
# 3/18 of the width and to the height of the image. # 3/18 of the width and to the height of the image.
# So we shift the image position. # So we shift the image position.
posY = - int( 48 * size + 0.5 ) - 10 pos_y = - int(48 * size + 0.5) - 10
posX = - int(( 48 * size ) / 6 + 0.5 ) - 10 pos_x = - int((48 * size) / 6 + 0.5) - 10
ctx.set_source_surface(marker[1], posX, posY) ctx.set_source_surface(marker[1], pos_x, pos_y)
ctx.paint() ctx.paint()
ctx.restore() ctx.restore()
_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):

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,10 +25,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from gi.repository import GObject from gi.repository import GObject
import operator
from math import *
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -44,7 +41,6 @@ _LOG = logging.getLogger("maps.messagelayer")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk from gi.repository import Gdk
import cairo
from gi.repository import Pango, PangoCairo from gi.repository import Pango, PangoCairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -66,6 +62,10 @@ try:
except: except:
raise raise
# pylint: disable=unused-variable
# pylint: disable=unused-argument
# pylint: disable=no-member
class MessageLayer(GObject.GObject, osmgpsmap.MapLayer): class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display messages over the map This is the layer used to display messages over the map

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -26,7 +26,6 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
from gi.repository import GObject
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -78,7 +77,14 @@ try:
except: except:
raise raise
class OsmGps(): # pylint: disable=unused-argument
# pylint: disable=no-member
# pylint: disable=maybe-no-member
class OsmGps(object):
"""
This class is used to create a map
"""
def __init__(self): def __init__(self):
""" """
Initialize the map Initialize the map
@@ -111,7 +117,7 @@ class OsmGps():
os.makedirs(cache_path, 0o755) # create dir like mkdir -p os.makedirs(cache_path, 0o755) # create dir like mkdir -p
except: except:
ErrorDialog(_("Can't create tiles cache directory %s") % ErrorDialog(_("Can't create tiles cache directory %s") %
cache_path ) cache_path)
return self.vbox return self.vbox
self.change_map(None, config.get("geography.map_service")) self.change_map(None, config.get("geography.map_service"))
@@ -127,13 +133,13 @@ class OsmGps():
self.vbox.remove(self.osm) self.vbox.remove(self.osm)
self.osm.destroy() self.osm.destroy()
tiles_path = os.path.join(config.get('geography.path'), tiles_path = os.path.join(config.get('geography.path'),
constants.tiles_path[map_type]) constants.TILES_PATH[map_type])
if not os.path.isdir(tiles_path): if not os.path.isdir(tiles_path):
try: try:
os.makedirs(tiles_path, 0o755) # create dir like mkdir -p os.makedirs(tiles_path, 0o755) # create dir like mkdir -p
except: except:
ErrorDialog(_("Can't create tiles cache directory for '%s'.") % ErrorDialog(_("Can't create tiles cache directory for '%s'.") %
constants.map_title[map_type]) constants.MAP_TITLE[map_type])
config.set("geography.map_service", map_type) config.set("geography.map_service", map_type)
self.current_map = map_type self.current_map = map_type
http_proxy = get_env_var('http_proxy') http_proxy = get_env_var('http_proxy')
@@ -143,12 +149,14 @@ class OsmGps():
if http_proxy: if http_proxy:
self.osm = osmgpsmap.Map(tile_cache=tiles_path, self.osm = osmgpsmap.Map(tile_cache=tiles_path,
proxy_uri=http_proxy, proxy_uri=http_proxy,
map_source=constants.map_type[map_type]) map_source=constants.MAP_TYPE[
map_type])
else: else:
self.osm = osmgpsmap.Map(tile_cache=tiles_path, self.osm = osmgpsmap.Map(tile_cache=tiles_path,
map_source=constants.map_type[map_type]) 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
self.osm.layer_add(current_map) self.osm.layer_add(current_map)
self.osm.layer_add(DummyLayer()) self.osm.layer_add(DummyLayer())
@@ -158,11 +166,11 @@ class OsmGps():
self.marker_layer = self.add_marker_layer() self.marker_layer = self.add_marker_layer()
self.date_layer = self.add_date_layer() self.date_layer = self.add_date_layer()
self.message_layer = self.add_message_layer() self.message_layer = self.add_message_layer()
self.cross_map = osmgpsmap.MapOsd( show_crosshair=False) self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
self.set_crosshair(config.get("geography.show_cross")) self.set_crosshair(config.get("geography.show_cross"))
self.osm.set_center_and_zoom(config.get("geography.center-lat"), self.osm.set_center_and_zoom(config.get("geography.center-lat"),
config.get("geography.center-lon"), config.get("geography.center-lon"),
config.get("geography.zoom") ) config.get("geography.zoom"))
self.osm.connect('button_release_event', self.map_clicked) self.osm.connect('button_release_event', self.map_clicked)
self.osm.connect('button_press_event', self.map_clicked) self.osm.connect('button_press_event', self.map_clicked)
@@ -176,21 +184,30 @@ class OsmGps():
def update_shortcuts(self, arg): def update_shortcuts(self, arg):
""" """
connect the keyboard or the keypad for shortcuts connect the keyboard or the keypad for shortcuts
arg is mandatory because this function is also called by the checkbox button arg is mandatory because this function is also called by
the checkbox button
""" """
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, Gdk.keyval_from_name("KP_Add")) self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN,
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT, Gdk.keyval_from_name("KP_Subtract")) Gdk.keyval_from_name("KP_Add"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT,
Gdk.keyval_from_name("KP_Subtract"))
else: else:
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN, Gdk.keyval_from_name("plus")) self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMIN,
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT, Gdk.keyval_from_name("minus")) Gdk.keyval_from_name("plus"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.ZOOMOUT,
Gdk.keyval_from_name("minus"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.UP, Gdk.keyval_from_name("Up")) self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.UP,
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.DOWN, Gdk.keyval_from_name("Down")) Gdk.keyval_from_name("Up"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.LEFT, Gdk.keyval_from_name("Left")) self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.DOWN,
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.RIGHT, Gdk.keyval_from_name("Right")) Gdk.keyval_from_name("Down"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.LEFT,
Gdk.keyval_from_name("Left"))
self.osm.set_keyboard_shortcut(osmgpsmap.MapKey_t.RIGHT,
Gdk.keyval_from_name("Right"))
# For shortcuts work, we must grab the focus # For shortcuts work, we must grab the focus
self.osm.grab_focus() self.osm.grab_focus()
@@ -296,7 +313,8 @@ class OsmGps():
""" """
Moving during selection Moving during selection
""" """
current = osmmap.convert_screen_to_geographic(int(event.x), int(event.y)) current = osmmap.convert_screen_to_geographic(int(event.x),
int(event.y))
lat, lon = current.get_degrees() lat, lon = current.get_degrees()
if self.zone_selection: if self.zone_selection:
# We draw a rectangle to show the selected region. # We draw a rectangle to show the selected region.
@@ -324,17 +342,17 @@ class OsmGps():
""" """
Save the longitude and lontitude in case we switch between maps. Save the longitude and lontitude in case we switch between maps.
""" """
_LOG.debug("save_center : %s,%s" % (lat, lon) ) _LOG.debug("save_center : %s,%s", lat, lon)
if ( -90.0 < lat < +90.0 ) and ( -180.0 < lon < +180.0 ): if (-90.0 < lat < +90.0) and (-180.0 < lon < +180.0):
config.set("geography.center-lat", lat) config.set("geography.center-lat", lat)
config.set("geography.center-lon", lon) config.set("geography.center-lon", lon)
else: else:
_LOG.debug("save_center : new coordinates : %s,%s" % (lat, lon) ) _LOG.debug("save_center : new coordinates : %s,%s", lat, lon)
_LOG.debug("save_center : old coordinates : %s,%s" % (lat, lon) ) _LOG.debug("save_center : old coordinates : %s,%s", lat, lon)
# osmgpsmap bug ? reset to prior values to avoid osmgpsmap problems. # osmgpsmap bug ? reset to prior values to avoid osmgpsmap problems.
self.osm.set_center_and_zoom(config.get("geography.center-lat"), self.osm.set_center_and_zoom(config.get("geography.center-lat"),
config.get("geography.center-lon"), config.get("geography.center-lon"),
config.get("geography.zoom") ) config.get("geography.zoom"))
def activate_selection_zoom(self, osm, event): def activate_selection_zoom(self, osm, event):
""" """
@@ -383,7 +401,7 @@ class OsmGps():
if self.no_show_places_in_status_bar: if self.no_show_places_in_status_bar:
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
@@ -406,20 +424,20 @@ class OsmGps():
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])
mlonp = precision % float(mark[2]) mlonp = precision % float(mark[2])
latok = lonok = False latok = lonok = False
if (float(mlatp) >= (float(latp) - shift) ) and \ if (float(mlatp) >= (float(latp) - shift)) and \
(float(mlatp) <= (float(latp) + shift) ): (float(mlatp) <= (float(latp) + shift)):
latok = True latok = True
if (float(mlonp) >= (float(lonp) - shift) ) and \ if (float(mlonp) >= (float(lonp) - shift)) and \
(float(mlonp) <= (float(lonp) + shift) ): (float(mlonp) <= (float(lonp) + shift)):
lonok = True lonok = True
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
@@ -441,9 +459,9 @@ class OsmGps():
""" """
if active: if active:
self.osm.layer_remove(self.cross_map) self.osm.layer_remove(self.cross_map)
self.cross_map = osmgpsmap.MapOsd( show_crosshair=True) self.cross_map = osmgpsmap.MapOsd(show_crosshair=True)
self.osm.layer_add( self.cross_map ) self.osm.layer_add(self.cross_map)
else: else:
self.osm.layer_remove(self.cross_map) self.osm.layer_remove(self.cross_map)
self.cross_map = osmgpsmap.MapOsd( show_crosshair=False) self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
self.osm.layer_add( self.cross_map ) self.osm.layer_add(self.cross_map)

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,6 @@
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
import re import re
from gi.repository import GObject
import math import math
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -56,7 +55,6 @@ from gramps.gui.managedwindow import ManagedWindow
from .osmgps import OsmGps 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.display.place import displayer as place_displayer
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -66,6 +64,9 @@ from gramps.gen.display.place import displayer as place_displayer
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>'
# pylint: disable=unused-argument
# pylint: disable=no-member
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# PlaceSelection # PlaceSelection
@@ -87,8 +88,10 @@ class PlaceSelection(ManagedWindow, OsmGps):
ManagedWindow.__init__(self, uistate, [], PlaceSelection) ManagedWindow.__init__(self, uistate, [], PlaceSelection)
except WindowActiveError: except WindowActiveError:
return return
OsmGps.__init__(self)
self.uistate = uistate self.uistate = uistate
self.dbstate = dbstate self.dbstate = dbstate
self.places = []
self.lat = lat self.lat = lat
self.lon = lon self.lon = lon
self.osm = maps self.osm = maps
@@ -162,7 +165,8 @@ class PlaceSelection(ManagedWindow, OsmGps):
def slider_change(self, obj, lat, lon): def slider_change(self, obj, lat, lon):
""" """
Display on the map a circle in which we select all the places inside this region. Display on the map a circle in which we select all the places
inside this region.
""" """
self.radius = obj.get_value() if obj else 1.0 self.radius = obj.get_value() if obj else 1.0
self.show_the_region(self.radius) self.show_the_region(self.radius)
@@ -183,14 +187,15 @@ class PlaceSelection(ManagedWindow, OsmGps):
) )
for place in self.places: for place in self.places:
if not place[0]: if not place[0]:
_LOG.info('No hierarchy yet: %s' % place) _LOG.info('No hierarchy yet: %s', place)
continue continue
p = (place[0], place[1], place[2], place[3], place[4]) self.plist.append((place[0], place[1],
self.plist.append(p) place[2], place[3], place[4]))
# here, we could add value from geography names services ... # here, we could add value from geography names services ...
# if we found no place, we must create a default place. # if we found no place, we must create a default place.
self.plist.append((_("New place with empty fields"), "", "...", "", None)) self.plist.append((_("New place with empty fields"), "",
"...", "", None))
def hide_the_region(self): def hide_the_region(self):
""" """
@@ -251,7 +256,8 @@ class PlaceSelection(ManagedWindow, OsmGps):
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) == True:
# Do we already have this place ? avoid duplicates # Do we already have this place ? avoid duplicates
country, state, county, place, other = self.get_location(entry[9]) (country, state, county,
place, other) = self.get_location(entry[9])
if not [country, state, county, place, other] in self.places: if not [country, state, county, place, other] in self.places:
self.places.append([country, state, county, place, other]) self.places.append([country, state, county, place, other])
for place in self.dbstate.db.iter_places(): for place in self.dbstate.db.iter_places():
@@ -260,9 +266,12 @@ class PlaceSelection(ManagedWindow, OsmGps):
if latn and lonn: if latn and lonn:
if (math.hypot(lat-float(latn), if (math.hypot(lat-float(latn),
lon-float(lonn)) <= rds) == True: lon-float(lonn)) <= rds) == True:
country, state, county, place, other = self.get_location(place.get_gramps_id()) (country, state, county,
if not [country, state, county, place, other] in self.places: place, other) = self.get_location(place.get_gramps_id())
self.places.append([country, state, county, place, other]) if not [country, state, county,
place, other] in self.places:
self.places.append([country, state, county,
place, other])
def selection(self, obj, index, column, function): def selection(self, obj, index, column, function):
""" """

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011-2012 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,7 +25,6 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
from math import pi from math import pi
from gi.repository import GObject from gi.repository import GObject
@@ -56,7 +55,12 @@ try:
except: except:
raise raise
# pylint: disable=unused-argument
class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer): class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
"""
This class is used to select an area on the map
"""
def __init__(self): def __init__(self):
""" """
Initialize thz selection layer Initialize thz selection layer
@@ -108,16 +112,17 @@ class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
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)
# be sure when can select a region in all case. # be sure when can select a region in all case.
if ( crd_x < crd_x2 ): if crd_x < crd_x2:
if ( crd_y < crd_y2 ): if crd_y < crd_y2:
ctx.rectangle(crd_x, crd_y, crd_x2 - crd_x, crd_y2 - crd_y) ctx.rectangle(crd_x, crd_y, crd_x2 - crd_x, crd_y2 - crd_y)
else: else:
ctx.rectangle(crd_x, crd_y2, crd_x2 - crd_x, crd_y - crd_y2) ctx.rectangle(crd_x, crd_y2, crd_x2 - crd_x, crd_y - crd_y2)
else: else:
if ( crd_y < crd_y2 ): if crd_y < crd_y2:
ctx.rectangle(crd_x2, crd_y, crd_x - crd_x2, crd_y2 - crd_y) ctx.rectangle(crd_x2, crd_y, crd_x - crd_x2, crd_y2 - crd_y)
else: else:
ctx.rectangle(crd_x2, crd_y2, crd_x - crd_x2, crd_y - crd_y2) ctx.rectangle(crd_x2, crd_y2, crd_x - crd_x2,
crd_y - crd_y2)
ctx.stroke() ctx.stroke()
def do_render(self, gpsmap): def do_render(self, gpsmap):

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
import operator import operator
from gi.repository import Gtk from gi.repository import Gtk
from math import * from math import hypot
from html import escape from html import escape
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -105,6 +105,9 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -163,6 +166,9 @@ class GeoClose(GeoGraphyView):
self.place_list_ref = [] self.place_list_ref = []
self.cal = config.get('preferences.calendar-format-report') self.cal = config.get('preferences.calendar-format-report')
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.add_item = None
self.newmenu = None
self.config_meeting_slider = None
def get_title(self): def get_title(self):
""" """
@@ -215,20 +221,22 @@ class GeoClose(GeoGraphyView):
self.message_layer.clear_messages() self.message_layer.clear_messages()
active = self.get_active() active = self.get_active()
if active: if active:
p1 = self.dbstate.db.get_person_from_handle(active) indiv1 = self.dbstate.db.get_person_from_handle(active)
color = self._config.get('geography.color2') color = self._config.get('geography.color2')
self._createmap(p1, color, self.place_list_active, False) self._createmap(indiv1, color, self.place_list_active, False)
if self.refperson: if self.refperson:
color = self._config.get('geography.color1') color = self._config.get('geography.color1')
self.message_layer.add_message(_("Reference : %(name)s ( %(birth)s - %(death)s )") % { self.message_layer.add_message(
'name': _nd.display(self.refperson), _("Reference : %(name)s ( %(birth)s - %(death)s )") % {
'birth': self.birth(self.refperson), 'name': _nd.display(self.refperson),
'death': self.death(self.refperson)}) 'birth': self.birth(self.refperson),
if p1: 'death': self.death(self.refperson)})
self.message_layer.add_message(_("The other : %(name)s ( %(birth)s - %(death)s )") % { if indiv1:
'name': _nd.display(p1), self.message_layer.add_message(
'birth': self.birth(p1), _("The other : %(name)s ( %(birth)s - %(death)s )") % {
'death': self.death(p1)}) 'name': _nd.display(indiv1),
'birth': self.birth(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)
@@ -236,10 +244,12 @@ class GeoClose(GeoGraphyView):
self.refperson_bookmark = self.refperson.get_handle() self.refperson_bookmark = self.refperson.get_handle()
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(_("You must choose one reference person.")) self.message_layer.add_message(
_("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 history.")) "Return to this view and use the"
" history."))
self.possible_meeting(self.place_list_ref, self.place_list_active) self.possible_meeting(self.place_list_ref, self.place_list_active)
self.uistate.modify_statusbar(self.dbstate) self.uistate.modify_statusbar(self.dbstate)
@@ -286,13 +296,13 @@ class GeoClose(GeoGraphyView):
self.define_print_actions() self.define_print_actions()
self.ref_person = Gtk.ActionGroup(name=self.title + '/Selection') self.ref_person = Gtk.ActionGroup(name=self.title + '/Selection')
self.ref_person.add_actions([ self.ref_person.add_actions([
('RefPerson', 'gramps-person', _('reference _Person'), None , ('RefPerson', 'gramps-person', _('reference _Person'), None,
_("Select the person which is the reference for life ways"), _("Select the person which is the reference for life ways"),
self.selectPerson), self.select_person),
]) ])
self._add_action_group(self.ref_person) self._add_action_group(self.ref_person)
def selectPerson(self, obj): def select_person(self, obj):
""" """
Open a selection box to choose the ref person. Open a selection box to choose the ref person.
""" """
@@ -300,8 +310,8 @@ class GeoClose(GeoGraphyView):
self.skip_list = [] self.skip_list = []
self.refperson = None self.refperson = None
self.refperson_bookmark = None self.refperson_bookmark = None
SelectPerson = SelectorFactory('Person') selectperson = SelectorFactory('Person')
sel = SelectPerson(self.dbstate, self.uistate, self.track, sel = selectperson(self.dbstate, self.uistate, self.track,
_("Select the person which will be our reference."), _("Select the person which will be our reference."),
skip=self.skip_list) skip=self.skip_list)
self.refperson = sel.run() self.refperson = sel.run()
@@ -342,7 +352,7 @@ class GeoClose(GeoGraphyView):
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(points, 'orange',
float(self._config.get("geography.maximum_meeting_zone")) / 10) 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):
@@ -405,7 +415,7 @@ class GeoClose(GeoGraphyView):
# 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:
self._append_to_places_list(descr, evt, self._append_to_places_list(descr, evt,
_nd.display(person), _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -433,7 +443,7 @@ class GeoClose(GeoGraphyView):
handle = fam.get_mother_handle() handle = fam.get_mother_handle()
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
descr1 = "%s%s" % ( descr1, _nd.display(mother)) descr1 = "%s%s" % (descr1, _nd.display(mother))
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(
@@ -450,12 +460,12 @@ class GeoClose(GeoGraphyView):
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(descr,
evt, _nd.display(person), evt, _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -467,13 +477,14 @@ class GeoClose(GeoGraphyView):
role role
) )
else: else:
self._append_to_places_without_coord( place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
sort1 = sorted(self.place_list, key=operator.itemgetter(6)) sort1 = sorted(self.place_list, key=operator.itemgetter(6))
self.draw(None, sort1, color, reference) self.draw(None, sort1, color, reference)
# merge with the last results # merge with the last results
merge_list = [] merge_list = []
for the_list in self.sort, sort1 : merge_list += the_list for the_list in self.sort, sort1:
merge_list += the_list
self.sort = sorted(merge_list, key=operator.itemgetter(6)) self.sort = sorted(merge_list, key=operator.itemgetter(6))
def bubble_message(self, event, lat, lon, marks): def bubble_message(self, event, lat, lon, marks):
@@ -489,7 +500,7 @@ class GeoClose(GeoGraphyView):
prevmark = None prevmark = None
for mark in marks: for mark in marks:
for plce in self.all_place_list: for plce in self.all_place_list:
if (plce[3] == mark[3] and plce[4] == mark[4]): if plce[3] == mark[3] and plce[4] == mark[4]:
if plce[10] in events: if plce[10] in events:
continue continue
else: else:
@@ -507,18 +518,19 @@ class GeoClose(GeoGraphyView):
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
if date == "": if date == "":
date = _("Unknown") date = _("Unknown")
if ( plce[11] == EventRoleType.PRIMARY ): if plce[11] == EventRoleType.PRIMARY:
message = "(%s) %s : %s" % ( date, plce[2], plce[1] ) message = "(%s) %s : %s" % (date, plce[2], plce[1])
elif ( plce[11] == EventRoleType.FAMILY ): elif plce[11] == EventRoleType.FAMILY:
(father_name, mother_name) = self._get_father_and_mother_name(evt) (father_name,
mother_name) = self._get_father_and_mother_name(evt)
message = "(%s) %s : %s - %s" % (date, plce[7], message = "(%s) %s : %s - %s" % (date, plce[7],
father_name, father_name,
mother_name ) mother_name)
else: else:
descr = evt.get_description() descr = evt.get_description()
if descr == "": if descr == "":
descr = _('No description') descr = _('No description')
message = "(%s) %s => %s" % ( date, plce[11], descr) message = "(%s) %s => %s" % (date, plce[11], descr)
prevmark = plce prevmark = plce
self.add_item = Gtk.MenuItem(label=message) self.add_item = Gtk.MenuItem(label=message)
add_item = self.add_item add_item = self.add_item
@@ -551,8 +563,9 @@ class GeoClose(GeoGraphyView):
add_item = Gtk.MenuItem() add_item = Gtk.MenuItem()
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Choose and bookmark the new reference person")) add_item = Gtk.MenuItem(
add_item.connect("activate", self.selectPerson) label=_("Choose and bookmark the new reference person"))
add_item.connect("activate", self.select_person)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
return return

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,12 +28,9 @@ Geography for events
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
import sys
import operator import operator
from gi.repository import Gdk from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab KEY_TAB = Gdk.KEY_Tab
import socket
from gi.repository import Gtk from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -57,11 +54,6 @@ 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.pageview import PageView
from gramps.gui.editors import EditPlace
from gramps.gui.selectors.selectplace import SelectPlace
from gramps.gui.filters.sidebar import EventSidebarFilter
from gramps.gui.views.navigationview import NavigationView
from gramps.gui.views.bookmarks import EventBookmarks 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
@@ -106,6 +98,10 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=unused-argument
# pylint: disable=no-member
# pylint: disable=maybe-no-member
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -136,6 +132,7 @@ class GeoEvents(GeoGraphyView):
self.additional_uis.append(self.additional_ui()) self.additional_uis.append(self.additional_ui())
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.show_all = False self.show_all = False
self.cal = None
def get_title(self): def get_title(self):
""" """
@@ -196,7 +193,7 @@ class GeoEvents(GeoGraphyView):
else: else:
self._createmap(None) self._createmap(None)
def _createmap_for_one_event(self,event): def _createmap_for_one_event(self, event):
""" """
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.
@@ -204,7 +201,7 @@ class GeoEvents(GeoGraphyView):
dbstate = self.dbstate dbstate = self.dbstate
if self.nbplaces >= self._config.get("geography.max_places"): if self.nbplaces >= self._config.get("geography.max_places"):
return return
descr = descr2 = "" descr1 = descr2 = ""
if event: if event:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
eventyear = event.get_date_object().to_calendar(self.cal).get_year() eventyear = event.get_date_object().to_calendar(self.cal).get_year()
@@ -220,7 +217,7 @@ class GeoEvents(GeoGraphyView):
# 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:
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
@@ -232,8 +229,8 @@ class GeoEvents(GeoGraphyView):
if descr2 == "": if descr2 == "":
descr2 = ("%s") % _nd.display(person) descr2 = ("%s") % _nd.display(person)
else: else:
descr2 = ("%s - %s") % ( descr2, descr2 = ("%s - %s") % (descr2,
_nd.display(person)) _nd.display(person))
else: else:
# family list ? # family list ?
family_list = [ family_list = [
@@ -247,13 +244,15 @@ class GeoEvents(GeoGraphyView):
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(hdle) father = dbstate.db.get_person_from_handle(
hdle)
hdle = family.get_mother_handle() hdle = family.get_mother_handle()
if hdle: if hdle:
mother = dbstate.db.get_person_from_handle(hdle) mother = dbstate.db.get_person_from_handle(
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 ?")
@@ -269,7 +268,7 @@ class GeoEvents(GeoGraphyView):
None None
) )
def _createmap(self,obj): def _createmap(self, obj):
""" """
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.
@@ -283,8 +282,6 @@ class GeoEvents(GeoGraphyView):
self.maxyear = 0 self.maxyear = 0
self.nbmarkers = 0 self.nbmarkers = 0
self.nbplaces = 0 self.nbplaces = 0
latitude = ""
longitude = ""
self.without = 0 self.without = 0
self.cal = config.get('preferences.calendar-format-report') self.cal = config.get('preferences.calendar-format-report')
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
@@ -317,7 +314,7 @@ class GeoEvents(GeoGraphyView):
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()
@@ -362,7 +359,7 @@ class GeoEvents(GeoGraphyView):
evt = self.dbstate.db.get_event_from_gramps_id(mark[10]) evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
# format the date as described in preferences. # format the date as described in preferences.
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
message = "(%s) %s : %s" % (date, EventType( mark[7] ), mark[5] ) message = "(%s) %s : %s" % (date, EventType(mark[7]), mark[5])
prevmark = mark prevmark = mark
add_item = Gtk.MenuItem(label=message) add_item = Gtk.MenuItem(label=message)
add_item.show() add_item.show()
@@ -398,7 +395,7 @@ class GeoEvents(GeoGraphyView):
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Show all events")) add_item = Gtk.MenuItem(label=_("Show all events"))
add_item.connect("activate", self.show_all_events, event, lat , lon) add_item.connect("activate", self.show_all_events, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Centering on Place")) add_item = Gtk.MenuItem(label=_("Centering on Place"))
@@ -415,7 +412,8 @@ class GeoEvents(GeoGraphyView):
oldplace = mark[0] oldplace = mark[0]
modify = Gtk.MenuItem(label=mark[0]) modify = Gtk.MenuItem(label=mark[0])
modify.show() modify.show()
modify.connect("activate", self.goto_place, float(mark[3]), float(mark[4])) modify.connect("activate", self.goto_place,
float(mark[3]), float(mark[4]))
itemoption.append(modify) itemoption.append(modify)
def goto_place(self, obj, lat, lon): def goto_place(self, obj, lat, lon):

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
import operator import operator
from gi.repository import Gtk from gi.repository import Gtk
from math import * from math import hypot
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -103,6 +103,10 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -135,10 +139,10 @@ class GeoFamClose(GeoGraphyView):
) )
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
GeoGraphyView.__init__(self, _("Have these two families been able to meet?"), GeoGraphyView.__init__(self,
pdata, dbstate, uistate, _("Have these two families been able to meet?"),
FamilyBookmarks, pdata, dbstate, uistate,
nav_group) FamilyBookmarks, nav_group)
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.place_list = [] self.place_list = []
@@ -161,6 +165,7 @@ class GeoFamClose(GeoGraphyView):
self.place_list_ref = [] self.place_list_ref = []
self.cal = config.get('preferences.calendar-format-report') self.cal = config.get('preferences.calendar-format-report')
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.config_meeting_slider = None
def get_title(self): def get_title(self):
""" """
@@ -195,30 +200,33 @@ class GeoFamClose(GeoGraphyView):
""" """
return 'Family' return 'Family'
def family_label(self,family): def family_label(self, family):
"""
Create the family label depending on existence of father and mother
"""
if family is None: if family is None:
return "Unknown" return "Unknown"
f = m = None father = mother = None
hdl = family.get_father_handle() hdl = family.get_father_handle()
if hdl: if hdl:
f = self.dbstate.db.get_person_from_handle(hdl) father = self.dbstate.db.get_person_from_handle(hdl)
hdl = family.get_mother_handle() hdl = family.get_mother_handle()
if hdl: if hdl:
m = self.dbstate.db.get_person_from_handle(hdl) mother = self.dbstate.db.get_person_from_handle(hdl)
if f and m: 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(f), 'father' : _nd.display(father),
'mother' : _nd.display(m), 'mother' : _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
elif f: elif father:
label = "%(gramps_id)s : %(father)s" % { label = "%(gramps_id)s : %(father)s" % {
'father' : _nd.display(f), 'father' : _nd.display(father),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
elif m: elif mother:
label = "%(gramps_id)s : %(mother)s" % { label = "%(gramps_id)s : %(mother)s" % {
'mother' : _nd.display(m), 'mother' : _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
else: else:
@@ -245,29 +253,35 @@ class GeoFamClose(GeoGraphyView):
self.lifeway_layer.clear_ways() self.lifeway_layer.clear_ways()
self.message_layer.clear_messages() self.message_layer.clear_messages()
active = self.get_active() active = self.get_active()
f1 = None family = None
if active: if active:
f1 = self.dbstate.db.get_family_from_handle(active) family = self.dbstate.db.get_family_from_handle(active)
color = self._config.get('geography.color2') color = self._config.get('geography.color2')
self._createmap(f1, color, self.place_list_active, False) self._createmap(family, color, self.place_list_active, False)
if self.reffamily: if self.reffamily:
color = self._config.get('geography.color1') color = self._config.get('geography.color1')
self._createmap(self.reffamily, color, self.place_list_ref, True) self._createmap(self.reffamily, color, self.place_list_ref, True)
self.message_layer.add_message(_("Family reference : %s" % self.family_label(self.reffamily))) self.message_layer.add_message(
if f1: _("Family reference : %s" % self.family_label(self.reffamily)))
self.message_layer.add_message(_("The other family : %s" % self.family_label(f1))) if family:
self.message_layer.add_message(
_("The other family : %s" % self.family_label(
family)))
else: else:
self.message_layer.add_message(_("The other family : %s" % _("Unknown"))) self.message_layer.add_message(
_("The other family : %s" % _("Unknown")))
if self.reffamily_bookmark is None: if self.reffamily_bookmark is None:
self.reffamily_bookmark = self.reffamily.get_handle() self.reffamily_bookmark = self.reffamily.get_handle()
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(_("You must choose one reference family.")) self.message_layer.add_message(
self.message_layer.add_message(_("Go to the family view and select " _("You must choose one reference family."))
"the families you want to compare. " self.message_layer.add_message(
"Return to this view and use the history.")) _("Go to the family view and select "
if f1 is not None: "the families you want to compare. "
self._possible_family_meeting(self.reffamily, f1) "Return to this view and use the history."))
if family is not None:
self._possible_family_meeting(self.reffamily, family)
self.uistate.modify_statusbar(self.dbstate) self.uistate.modify_statusbar(self.dbstate)
def define_actions(self): def define_actions(self):
@@ -279,13 +293,13 @@ class GeoFamClose(GeoGraphyView):
self.define_print_actions() self.define_print_actions()
self.ref_family = Gtk.ActionGroup(self.title + '/Selection') self.ref_family = Gtk.ActionGroup(self.title + '/Selection')
self.ref_family.add_actions([ self.ref_family.add_actions([
('RefFamily', 'gramps-family', _('reference _Family'), None , ('RefFamily', 'gramps-family', _('reference _Family'), None,
_("Select the family which is the reference for life ways"), _("Select the family which is the reference for life ways"),
self.selectFamily), self.select_family),
]) ])
self._add_action_group(self.ref_family) self._add_action_group(self.ref_family)
def selectFamily(self, obj): def select_family(self, obj):
""" """
Open a selection box to choose the ref family. Open a selection box to choose the ref family.
""" """
@@ -293,8 +307,8 @@ class GeoFamClose(GeoGraphyView):
self.skip_list = [] self.skip_list = []
self.ref_family = None self.ref_family = None
self.reffamily_bookmark = None self.reffamily_bookmark = None
selectFamily = SelectorFactory('Family') select_family = SelectorFactory('Family')
sel = selectFamily(self.dbstate, self.uistate) sel = select_family(self.dbstate, self.uistate)
self.reffamily = sel.run() self.reffamily = sel.run()
self.goto_handle(None) self.goto_handle(None)
@@ -332,18 +346,19 @@ class GeoFamClose(GeoGraphyView):
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(points, 'orange',
float(self._config.get("geography.maximum_meeting_zone")) / 10) float(
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):
""" """
get place list for one person get place list for one person
""" """
list = [] place_list = []
for event in self.sort: for event in self.sort:
if ( event[1] == _nd.display(person)): if event[1] == _nd.display(person):
list.append(event) place_list.append(event)
return list return place_list
def possible_meeting(self, ref_person, person): def possible_meeting(self, ref_person, person):
""" """
@@ -370,11 +385,13 @@ class GeoFamClose(GeoGraphyView):
""" """
dbstate = self.dbstate dbstate = self.dbstate
try: try:
person = dbstate.db.get_person_from_handle(family.get_father_handle()) person = dbstate.db.get_person_from_handle(
family.get_father_handle())
except: except:
return return
if person is None: # family without father ? if person is None: # family without father ?
person = dbstate.db.get_person_from_handle(family.get_mother_handle()) person = dbstate.db.get_person_from_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:
@@ -408,7 +425,8 @@ class GeoFamClose(GeoGraphyView):
dbstate = self.dbstate dbstate = self.dbstate
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle(reference.get_father_handle()) person = dbstate.db.get_person_from_handle(
reference.get_father_handle())
except: except:
return return
if person is None: # family without father ? if person is None: # family without father ?
@@ -464,8 +482,8 @@ class GeoFamClose(GeoGraphyView):
except: except:
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)
@@ -482,7 +500,7 @@ class GeoFamClose(GeoGraphyView):
# 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:
self._append_to_places_list(descr, evt, self._append_to_places_list(descr, evt,
_nd.display(person), _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -513,7 +531,7 @@ class GeoFamClose(GeoGraphyView):
if handle: if handle:
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
descr1 = "%s%s" % ( descr1, _nd.display(mother)) descr1 = "%s%s" % (descr1, _nd.display(mother))
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(
@@ -532,10 +550,11 @@ class GeoFamClose(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType( evt = EventType(
event.get_type()) event.get_type())
eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str(
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
if ( longitude and latitude ): str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
if longitude and latitude:
self._append_to_places_list(descr, self._append_to_places_list(descr,
evt, _nd.display(person), evt, _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -547,13 +566,14 @@ class GeoFamClose(GeoGraphyView):
role role
) )
else: else:
self._append_to_places_without_coord( place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
sort1 = sorted(self.place_list, key=operator.itemgetter(6)) sort1 = sorted(self.place_list, key=operator.itemgetter(6))
self.draw(None, sort1, color, reference) self.draw(None, sort1, color, reference)
# merge with the last results # merge with the last results
merge_list = [] merge_list = []
for the_list in self.sort, sort1 : merge_list += the_list for the_list in self.sort, sort1:
merge_list += the_list
self.sort = sorted(merge_list, key=operator.itemgetter(6)) self.sort = sorted(merge_list, key=operator.itemgetter(6))
def _createmap_for_one_family(self, family, color, place_list, reference): def _createmap_for_one_family(self, family, color, place_list, reference):
@@ -563,7 +583,8 @@ class GeoFamClose(GeoGraphyView):
dbstate = self.dbstate dbstate = self.dbstate
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle(family.get_father_handle()) person = dbstate.db.get_person_from_handle(
family.get_father_handle())
except: except:
return return
family_id = family.gramps_id family_id = family.gramps_id
@@ -585,16 +606,20 @@ class GeoFamClose(GeoGraphyView):
if handle: if handle:
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") % {'id': father.gramps_id, comment = _("Father : %(id)s : %(name)s") % {
'name': _nd.display(father)} 'id': father.gramps_id,
self._createmap_for_one_person(father, color, place_list, reference) 'name': _nd.display(father)}
self._createmap_for_one_person(father, color,
place_list, reference)
handle = fam.get_mother_handle() handle = fam.get_mother_handle()
if handle: if handle:
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") % {'id': mother.gramps_id, comment = _("Mother : %(id)s : %(name)s") % {
'name': _nd.display(mother)} 'id': mother.gramps_id,
self._createmap_for_one_person(mother, color, place_list, reference) 'name': _nd.display(mother)}
self._createmap_for_one_person(mother, color,
place_list, reference)
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:
@@ -608,13 +633,16 @@ class GeoFamClose(GeoGraphyView):
'index' : index, 'index' : index,
'name' : _nd.display(child) 'name' : _nd.display(child)
} }
self._createmap_for_one_person(child, color, place_list, reference) self._createmap_for_one_person(child, color,
place_list,
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, place_list, reference) self._createmap_for_one_person(person, color,
place_list, reference)
def _createmap(self, family_x, color, place_list, reference): def _createmap(self, family_x, color, place_list, reference):
""" """
@@ -646,7 +674,8 @@ class GeoFamClose(GeoGraphyView):
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:
self._createmap_for_one_family(family, color, place_list, reference) self._createmap_for_one_family(family, color,
place_list, reference)
else: else:
self._createmap_for_one_family(family, color, place_list, reference) self._createmap_for_one_family(family, color, place_list, reference)
#self._create_markers() #self._create_markers()
@@ -664,7 +693,7 @@ class GeoFamClose(GeoGraphyView):
prevmark = None prevmark = None
for mark in marks: for mark in marks:
for plce in self.all_place_list: for plce in self.all_place_list:
if (plce[3] == mark[3] and plce[4] == mark[4]): if plce[3] == mark[3] and plce[4] == mark[4]:
if plce[10] in events: if plce[10] in events:
continue continue
else: else:
@@ -682,18 +711,19 @@ class GeoFamClose(GeoGraphyView):
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
if date == "": if date == "":
date = _("Unknown") date = _("Unknown")
if ( plce[11] == EventRoleType.PRIMARY ): if plce[11] == EventRoleType.PRIMARY:
message = "(%s) %s : %s" % ( date, plce[2], plce[1] ) message = "(%s) %s : %s" % (date, plce[2], plce[1])
elif ( plce[11] == EventRoleType.FAMILY ): elif plce[11] == EventRoleType.FAMILY:
(father_name, mother_name) = self._get_father_and_mother_name(evt) (father_name,
mother_name) = self._get_father_and_mother_name(evt)
message = "(%s) %s : %s - %s" % (date, plce[7], message = "(%s) %s : %s - %s" % (date, plce[7],
father_name, father_name,
mother_name ) mother_name)
else: else:
descr = evt.get_description() descr = evt.get_description()
if descr == "": if descr == "":
descr = _('No description') descr = _('No description')
message = "(%s) %s => %s" % ( date, plce[11], descr) message = "(%s) %s => %s" % (date, plce[11], descr)
prevmark = plce prevmark = plce
add_item = Gtk.MenuItem(label=message) add_item = Gtk.MenuItem(label=message)
add_item.show() add_item.show()
@@ -725,8 +755,9 @@ class GeoFamClose(GeoGraphyView):
add_item = Gtk.MenuItem() add_item = Gtk.MenuItem()
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Choose and bookmark the new reference family")) add_item = Gtk.MenuItem(
add_item.connect("activate", self.selectFamily) label=_("Choose and bookmark the new reference family"))
add_item.connect("activate", self.select_family)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
return return

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,12 +28,9 @@ Geography for one family
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
import sys
import operator import operator
from gi.repository import Gdk from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab KEY_TAB = Gdk.KEY_Tab
import socket
from gi.repository import Gtk from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -57,11 +54,6 @@ 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.pageview import PageView
from gramps.gui.editors import EditPlace
from gramps.gui.selectors.selectplace import SelectPlace
from gramps.gui.filters.sidebar import FamilySidebarFilter
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.geography import GeoGraphyView from gramps.plugins.lib.maps.geography import GeoGraphyView
@@ -105,6 +97,10 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -112,7 +108,7 @@ _UI_DEF = '''\
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GeoFamily(GeoGraphyView): class GeoFamily(GeoGraphyView):
""" """
The view used to render person map. The view used to render family map.
""" """
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
@@ -132,6 +128,7 @@ class GeoFamily(GeoGraphyView):
self.sort = [] self.sort = []
self.additional_uis.append(self.additional_ui()) self.additional_uis.append(self.additional_ui())
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.cal = None
def get_title(self): def get_title(self):
""" """
@@ -213,8 +210,9 @@ class GeoFamily(GeoGraphyView):
# 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, str(descr1 + descr + str(evt))): if not self._present_in_places_list(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),
@@ -235,63 +233,74 @@ class GeoFamily(GeoGraphyView):
if family is not None: if family is not None:
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_ref.ref) event = dbstate.db.get_event_from_handle(
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_handle) place = dbstate.db.get_place_from_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, (latitude,
longitude, "D.D8") longitude) = conv_lat_lon(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())
(father_name, mother_name) = self._get_father_and_mother_name(event) (father_name,
descr1 = "%s : %s - " % ( evt, father_name ) mother_name) = self._get_father_and_mother_name(event)
descr1 = "%s%s" % ( descr1, mother_name ) descr1 = "%s : %s - " % (evt,
father_name)
descr1 = "%s%s" % (descr1, mother_name)
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(2, str(descr1 + descr + str(evt))): if not self._present_in_places_list(
self._append_to_places_list(descr, 2, str(descr1 + descr + str(evt))):
str(descr1 + descr + str(evt)), self._append_to_places_list(
_nd.display(person), descr,
latitude, longitude, str(descr1 + descr + str(evt)),
role, eyear, _nd.display(person),
event.get_type(), latitude, longitude,
person.gramps_id, role, eyear,
place.gramps_id, event.get_type(),
event.gramps_id, person.gramps_id,
family.gramps_id place.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)
def family_label(self,family): def family_label(self, family):
"""
Create the family label depending on existence of the father and mother
"""
if family is None: if family is None:
return "Unknown" return "Unknown"
f = m = None father = mother = None
hdl = family.get_father_handle() hdl = family.get_father_handle()
if hdl: if hdl:
f = self.dbstate.db.get_person_from_handle(hdl) father = self.dbstate.db.get_person_from_handle(hdl)
hdl = family.get_mother_handle() hdl = family.get_mother_handle()
if hdl: if hdl:
m = self.dbstate.db.get_person_from_handle(hdl) mother = self.dbstate.db.get_person_from_handle(hdl)
if f and m: 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(f), 'father' : _nd.display(father),
'mother' : _nd.display(m), 'mother' : _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
elif f: elif father:
label = "%(gramps_id)s : %(father)s" % { label = "%(gramps_id)s : %(father)s" % {
'father' : _nd.display(f), 'father' : _nd.display(father),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
elif m: elif mother:
label = "%(gramps_id)s : %(mother)s" % { label = "%(gramps_id)s : %(mother)s" % {
'mother' : _nd.display(m), 'mother' : _nd.display(mother),
'gramps_id' : family.gramps_id, 'gramps_id' : family.gramps_id,
} }
else: else:
@@ -306,10 +315,12 @@ class GeoFamily(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.
""" """
dbstate = self.dbstate dbstate = self.dbstate
self.message_layer.add_message(_("Family places for %s") % self.family_label(family)) self.message_layer.add_message(
_("Family places for %s") % self.family_label(family))
person = None person = None
if family: if family:
person = dbstate.db.get_person_from_handle(family.get_father_handle()) person = dbstate.db.get_person_from_handle(
family.get_father_handle())
else: else:
return return
family_id = family.gramps_id family_id = family.gramps_id
@@ -331,16 +342,18 @@ class GeoFamily(GeoGraphyView):
if handle: if handle:
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") % {'id': father.gramps_id, comment = _("Father : %(id)s : %(name)s") % {
'name': _nd.display(father) } 'id': father.gramps_id,
'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()
if handle: if handle:
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") % {'id': mother.gramps_id, comment = _("Mother : %(id)s : %(name)s") % {
'name': _nd.display(mother) } 'id': mother.gramps_id,
'name': _nd.display(mother)}
self._createpersonmarkers(dbstate, mother, self._createpersonmarkers(dbstate, mother,
comment, family_id) comment, family_id)
index = 0 index = 0
@@ -360,7 +373,7 @@ class GeoFamily(GeoGraphyView):
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)
@@ -399,6 +412,9 @@ class GeoFamily(GeoGraphyView):
self._create_markers() self._create_markers()
def add_event_bubble_message(self, event, lat, lon, mark, menu): def add_event_bubble_message(self, event, lat, lon, mark, menu):
"""
Add an item to the popup menu.
"""
self.itemoption = Gtk.Menu() self.itemoption = Gtk.Menu()
itemoption = self.itemoption itemoption = self.itemoption
itemoption.show() itemoption.show()
@@ -421,6 +437,9 @@ class GeoFamily(GeoGraphyView):
itemoption.append(center) itemoption.append(center)
def bubble_message(self, event, lat, lon, marks): def bubble_message(self, event, lat, lon, marks):
"""
Add the popup menu.
"""
self.menu = Gtk.Menu() self.menu = Gtk.Menu()
menu = self.menu menu = self.menu
menu.set_title("family") menu.set_title("family")
@@ -444,18 +463,20 @@ class GeoFamily(GeoGraphyView):
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
if date == "": if date == "":
date = _("Unknown") date = _("Unknown")
if ( mark[5] == EventRoleType.PRIMARY ): if mark[5] == EventRoleType.PRIMARY:
message = "(%s) %s : %s" % ( date, mark[7], mark[1] ) message = "(%s) %s : %s" % (date, mark[7], mark[1])
elif ( mark[5] == EventRoleType.FAMILY ): elif mark[5] == EventRoleType.FAMILY:
evt = self.dbstate.db.get_event_from_gramps_id(mark[10]) evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
(father_name, mother_name) = self._get_father_and_mother_name(evt) (father_name,
message = "(%s) %s : %s - %s" % ( date, mark[7], father_name, mother_name ) mother_name) = self._get_father_and_mother_name(evt)
message = "(%s) %s : %s - %s" % (date, mark[7],
father_name, mother_name)
else: else:
evt = self.dbstate.db.get_event_from_gramps_id(mark[10]) evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
descr = evt.get_description() descr = evt.get_description()
if descr == "": if descr == "":
descr = _('No description') descr = _('No description')
message = "(%s) %s => %s" % ( date, mark[5], descr) message = "(%s) %s => %s" % (date, mark[5], descr)
prevmark = mark prevmark = mark
add_item = Gtk.MenuItem(label=message) add_item = Gtk.MenuItem(label=message)
add_item.show() add_item.show()

View File

@@ -2,7 +2,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -25,9 +25,15 @@
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
MODULE_VERSION="5.0" # pylint: disable=bad-whitespace
# pylint: disable=bad-whitespace
MODULE_VERSION = "5.0"
from gi import Repository from gi import Repository
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.plug._pluginreg import register, VIEW, STABLE #, END, START
_ = glocale.translation.gettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -40,9 +46,9 @@ _LOG = logging.getLogger("Geography")
# Attempting to import OsmGpsMap gives an error dialog if OsmGpsMap is not # Attempting to import OsmGpsMap gives an error dialog if OsmGpsMap is not
# available so test first and log just a warning to the console instead. # available so test first and log just a warning to the console instead.
OSMGPSMAP = False OSMGPSMAP = False
repository = Repository.get_default() REPOSITORY = Repository.get_default()
if repository.enumerate_versions("OsmGpsMap"): if REPOSITORY.enumerate_versions("OsmGpsMap"):
try : try:
# current osmgpsmap support GTK3 # current osmgpsmap support GTK3
import gi import gi
gi.require_version('OsmGpsMap', '1.0') gi.require_version('OsmGpsMap', '1.0')
@@ -58,22 +64,22 @@ if not OSMGPSMAP:
if has_display(): if has_display():
from gramps.gui.dialog import MessageHideDialog from gramps.gui.dialog import MessageHideDialog
from gramps.gen.const import URL_WIKISTRING from gramps.gen.const import URL_WIKISTRING
osmgps_dict = { 'gramps_wiki_build_osmgps_url' : OSMGPS_DICT = {'gramps_wiki_build_osmgps_url' :
URL_WIKISTRING + URL_WIKISTRING +
"GEPS_029:_GTK3-GObject_introspection" "GEPS_029:_GTK3-GObject_introspection"
"_Conversion#OsmGpsMap_for_Geography" } "_Conversion#OsmGpsMap_for_Geography"}
title = _("OsmGpsMap module not loaded.") TITLE = _("OsmGpsMap module not loaded.")
message = _("Geography functionality will not be available.\n" MESSAGE = _("Geography functionality will not be available.\n"
"To build it for Gramps see " "To build it for Gramps see "
"%(gramps_wiki_build_osmgps_url)s") % osmgps_dict "%(gramps_wiki_build_osmgps_url)s") % OSMGPS_DICT
MessageHideDialog(title, message, 'interface.ignore-osmgpsmap') MessageHideDialog(TITLE, MESSAGE, 'interface.ignore-osmgpsmap')
else: else:
# Load the view only if osmgpsmap library is present. # Load the view only if osmgpsmap library is present.
register(VIEW, register(VIEW,
id = 'geo1', id = 'geo1',
name = _("All known places for one Person"), name = _("All known places for one Person"),
description = _("A view showing the places visited by " description = _("A view showing the places visited by "
"one person during his life."), "one person during his life."),
version = '1.0', version = '1.0',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -87,10 +93,10 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo2', id = 'geo2',
name = _("All known places for one Family"), name = _("All known places for one Family"),
description = _("A view showing the places visited by " description = _("A view showing the places visited by "
"one family during all their life."), "one family during all their life."),
version = '1.0', version = '1.0',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -104,12 +110,14 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo3', id = 'geo3',
name = _("Every residence or move for a person and any descendants"), name = _("Every residence or move for a person "
description = _("A view showing all the places visited by " "and any descendants"),
"all persons during their life." description = _("A view showing all the places visited by "
"\nThis is for a person and any descendant." "all persons during their life."
"\nYou can see the dates corresponding to the period."), "\nThis is for a person and any descendant."
"\nYou can see the dates corresponding to "
"the period."),
version = '1.0', version = '1.0',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -123,11 +131,11 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo4', id = 'geo4',
name = _("Have these two families been able to meet?"), name = _("Have these two families been able to meet?"),
description = _("A view showing the places visited by " description = _("A view showing the places visited by "
"all family's members during their life: " "all family's members during their life: "
"have these two people been able to meet?"), "have these two people been able to meet?"),
version = '1.0.1', version = '1.0.1',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -141,11 +149,11 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo5', id = 'geo5',
name = _("Have they been able to meet?"), name = _("Have they been able to meet?"),
description = _("A view showing the places visited by " description = _("A view showing the places visited by "
"two persons during their life: " "two persons during their life: "
"have these two people been able to meet?"), "have these two people been able to meet?"),
version = '1.0.1', version = '1.0.1',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -159,9 +167,9 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo6', id = 'geo6',
name = _("All known Places"), name = _("All known Places"),
description = _("A view showing all places of the database."), description = _("A view showing all places of the database."),
version = '1.0', version = '1.0',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,
@@ -175,10 +183,10 @@ else:
) )
register(VIEW, register(VIEW,
id = 'geo7', id = 'geo7',
name = _("All places related to Events"), name = _("All places related to Events"),
description = _("A view showing all the event " description = _("A view showing all the event "
"places of the database."), "places of the database."),
version = '1.0', version = '1.0',
gramps_target_version = MODULE_VERSION, gramps_target_version = MODULE_VERSION,
status = STABLE, status = STABLE,

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -33,10 +33,6 @@ _ = glocale.translation.gettext
import operator import operator
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GObject
import time
import threading
from math import *
from gi.repository import GLib from gi.repository import GLib
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -58,11 +54,9 @@ 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 PersonBookmarks 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
from gramps.gui.selectors import SelectorFactory
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -107,6 +101,11 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView : GeoMoves # GeoView : GeoMoves
@@ -114,7 +113,8 @@ _UI_DEF = '''\
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GeoMoves(GeoGraphyView): class GeoMoves(GeoGraphyView):
""" """
The view used to render all places visited by one person and all his descendants. The view used to render all places visited by one person and all
his descendants.
""" """
CONFIGSETTINGS = ( CONFIGSETTINGS = (
('geography.path', constants.GEOGRAPHY_PATH), ('geography.path', constants.GEOGRAPHY_PATH),
@@ -164,6 +164,7 @@ class GeoMoves(GeoGraphyView):
self.markers_by_level = dict() self.markers_by_level = dict()
self.count = dict() self.count = dict()
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.person_list = []
def get_title(self): def get_title(self):
""" """
@@ -213,8 +214,8 @@ class GeoMoves(GeoGraphyView):
self.date_layer.clear_dates() self.date_layer.clear_dates()
active = self.get_active() active = self.get_active()
if active: if active:
p1 = self.dbstate.db.get_person_from_handle(active) person = self.dbstate.db.get_person_from_handle(active)
self._createmap(p1) self._createmap(person)
self.uistate.modify_statusbar(self.dbstate) self.uistate.modify_statusbar(self.dbstate)
def build_tree(self): def build_tree(self):
@@ -294,9 +295,9 @@ class GeoMoves(GeoGraphyView):
# 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:
self._append_to_places_list(descr, evt, self._append_to_places_list(descr, evt,
person.gramps_id, #_nd.display(person), person.gramps_id,
latitude, longitude, latitude, longitude,
descr1, eyear, descr1, eyear,
event.get_type(), event.get_type(),
@@ -325,7 +326,7 @@ class GeoMoves(GeoGraphyView):
if handle: if handle:
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
descr1 = "%s%s" % ( descr1, _nd.display(mother)) descr1 = "%s%s" % (descr1, _nd.display(mother))
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(
@@ -344,12 +345,15 @@ class GeoMoves(GeoGraphyView):
descr = _pd.display(dbstate.db, place) descr = _pd.display(dbstate.db, place)
evt = EventType( evt = EventType(
event.get_type()) event.get_type())
eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str(
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
if ( longitude and latitude ): str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
self._append_to_places_list(descr, evt, if longitude and latitude:
person.gramps_id, #_nd.display(person), self._append_to_places_list(
descr,
evt,
person.gramps_id,
latitude, longitude, latitude, longitude,
descr1, eyear, descr1, eyear,
event.get_type(), event.get_type(),
@@ -359,13 +363,13 @@ class GeoMoves(GeoGraphyView):
role role
) )
else: else:
self._append_to_places_without_coord( place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
sort1 = sorted(self.place_list, key=operator.itemgetter(1,6)) sort1 = sorted(self.place_list, key=operator.itemgetter(1, 6))
self.draw(None, sort1, color) self.draw(None, sort1, color)
# merge with the last results # merge with the last results
merge_list = self.sort merge_list = self.sort
for the_event in sort1 : for the_event in sort1:
if the_event not in merge_list: if the_event not in merge_list:
merge_list.append(the_event) merge_list.append(the_event)
self.sort = sorted(merge_list, key=operator.itemgetter(6)) self.sort = sorted(merge_list, key=operator.itemgetter(6))
@@ -388,7 +392,8 @@ class GeoMoves(GeoGraphyView):
dbstate = self.dbstate dbstate = self.dbstate
person = None person = None
try: try:
person = dbstate.db.get_person_from_handle(family.get_father_handle()) person = dbstate.db.get_person_from_handle(
family.get_father_handle())
except: except:
return return
family_id = family.gramps_id family_id = family.gramps_id
@@ -425,7 +430,8 @@ class GeoMoves(GeoGraphyView):
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
self._createmap_for_next_level(child, level, curlevel) self._createmap_for_next_level(child, level,
curlevel)
self._add_person_to_list(child.gramps_id, curlevel) self._add_person_to_list(child.gramps_id, curlevel)
def _createmap_for_one_level(self, family, level, curlevel): def _createmap_for_one_level(self, family, level, curlevel):
@@ -480,81 +486,84 @@ class GeoMoves(GeoGraphyView):
person = self.dbstate.db.get_person_from_handle(handle) person = self.dbstate.db.get_person_from_handle(handle)
if not person: if not person:
return return
self.message_layer.add_message(_("All descendance for %s") % _nd.display(person)) self.message_layer.add_message(
_("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)
def animate_moves(self, index, person, color): def animate_moves(self, index, person, color):
""" """
Animate all moves for one generation. Animate all moves for one generation.
""" """
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:
persons = self.markers_by_level[index] persons = self.markers_by_level[index]
except: except:
return return
for people in persons: for people in persons:
family_list = people.get_family_handle_list() family_list = people.get_family_handle_list()
for fhandle in family_list: for fhandle in family_list:
family = self.dbstate.db.get_family_from_handle(fhandle) family = self.dbstate.db.get_family_from_handle(fhandle)
self._prepare_for_one_family(family, index, index+1) self._prepare_for_one_family(family, index, index+1)
new_list = [] new_list = []
for plx, level in self.person_list: for plx, level in self.person_list:
plxp = self.dbstate.db.get_person_from_gramps_id(plx) plxp = self.dbstate.db.get_person_from_gramps_id(plx)
birth = "0000" birth = "0000"
death = "0000" death = "0000"
low_date = "9999" low_date = "9999"
high_date = "0000" high_date = "0000"
for event_ref in plxp.get_event_ref_list(): for event_ref in plxp.get_event_ref_list():
if not event_ref: if not event_ref:
continue continue
event = self.dbstate.db.get_event_from_handle(event_ref.ref) event = self.dbstate.db.get_event_from_handle(event_ref.ref)
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)
fyear = str("%04d" % date.get_year()) fyear = str("%04d" % date.get_year())
if event.get_type() == EventType.BIRTH: if event.get_type() == EventType.BIRTH:
birth = fyear birth = fyear
if event.get_type() == EventType.DEATH: if event.get_type() == EventType.DEATH:
death = fyear death = fyear
if fyear < low_date: if fyear < low_date:
low_date = fyear low_date = fyear
if fyear > high_date: if fyear > high_date:
high_date = fyear high_date = fyear
except: except:
pass pass
if birth == "0000": if birth == "0000":
birth = low_date birth = low_date
if death == "0000": if death == "0000":
death = high_date death = high_date
new_list.append([level, plxp, birth, death]) new_list.append([level, plxp, birth, death])
pidx = 0; pidx = 0
if isinstance(color, str) : if isinstance(color, str):
color = Gdk.color_parse(color) color = Gdk.color_parse(color)
for (level, plxp, birth, death) in sorted(new_list, key=operator.itemgetter(0,2)): for (level, plxp,
if index == int(self._config.get("geography.maximum_generations")): birth, death) in sorted(new_list, key=operator.itemgetter(0, 2)):
break if index == int(self._config.get("geography.maximum_generations")):
if level == index: break
pidx += 1 if level == index:
self._createmap_for_one_person(plxp, color) pidx += 1
color.red = (float(color.red - (index)*3000)%65535) self._createmap_for_one_person(plxp, color)
if ( index % 2 ): color.red = (float(color.red - (index)*3000)%65535)
color.green = float((color.green + (index)*3000)%65535) if index % 2:
else: color.green = float((color.green + (index)*3000)%65535)
color.blue = float((color.blue + (index)*3000)%65535) else:
self._createmap_for_one_person(person, color) color.blue = float((color.blue + (index)*3000)%65535)
if index < int(self._config.get("geography.maximum_generations")): self._createmap_for_one_person(person, color)
time_to_wait = int(self._config.get("geography.generation_interval")) if index < int(self._config.get("geography.maximum_generations")):
self._create_markers() time_to_wait = int(
# process next generation in a few milliseconds self._config.get("geography.generation_interval"))
GLib.timeout_add(int(time_to_wait), self.animate_moves, self._create_markers()
index+1, person, color) # process next generation in a few milliseconds
else: GLib.timeout_add(int(time_to_wait), self.animate_moves,
self.started = False index+1, person, color)
return False else:
self.started = False
return False
def bubble_message(self, event, lat, lon, marks): def bubble_message(self, event, lat, lon, marks):
""" """
@@ -568,7 +577,7 @@ class GeoMoves(GeoGraphyView):
oldplace = "" oldplace = ""
prevmark = None prevmark = None
# 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:
@@ -585,19 +594,20 @@ class GeoMoves(GeoGraphyView):
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
if date == "": if date == "":
date = _("Unknown") date = _("Unknown")
if ( mark[11] == EventRoleType.PRIMARY ): if mark[11] == EventRoleType.PRIMARY:
person = self.dbstate.db.get_person_from_gramps_id(mark[1]) person = self.dbstate.db.get_person_from_gramps_id(mark[1])
message = "(%s) %s : %s" % ( date, mark[2], _nd.display(person) ) message = "(%s) %s : %s" % (date, mark[2], _nd.display(person))
elif ( mark[11] == EventRoleType.FAMILY ): elif mark[11] == EventRoleType.FAMILY:
(father_name, mother_name) = self._get_father_and_mother_name(evt) (father_name,
mother_name) = self._get_father_and_mother_name(evt)
message = "(%s) %s : %s - %s" % (date, mark[2], message = "(%s) %s : %s - %s" % (date, mark[2],
father_name, father_name,
mother_name ) mother_name)
else: else:
descr = evt.get_description() descr = evt.get_description()
if descr == "": if descr == "":
descr = _('No description') descr = _('No description')
message = "(%s) %s => %s" % ( date, mark[11], descr) message = "(%s) %s => %s" % (date, mark[11], descr)
prevmark = mark prevmark = mark
add_item = Gtk.MenuItem(label=message) add_item = Gtk.MenuItem(label=message)
add_item.show() add_item.show()

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,14 +28,10 @@ Geography for one person
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
import sys
import operator import operator
from gi.repository import Gdk from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab KEY_TAB = Gdk.KEY_Tab
import socket
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib from gi.repository import GLib
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -59,11 +55,6 @@ 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.pageview import PageView
from gramps.gui.editors import EditPlace
from gramps.gui.selectors.selectplace import SelectPlace
from gramps.gui.filters.sidebar import PersonSidebarFilter
from gramps.gui.views.navigationview import NavigationView
from gramps.gui.views.bookmarks import PersonBookmarks 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
@@ -111,6 +102,11 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=maybe-no-member
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -163,6 +159,9 @@ class GeoPerson(GeoGraphyView):
self.sort = [] self.sort = []
self.additional_uis.append(self.additional_ui()) self.additional_uis.append(self.additional_ui())
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.already_started = False
self.large_move = False
self.cal = None
def get_title(self): def get_title(self):
""" """
@@ -230,8 +229,8 @@ class GeoPerson(GeoGraphyView):
self.already_started = False self.already_started = False
return False return False
i = int(index) i = int(index)
ni = i + 1 next_i = i + 1
if ni == len(marks) : if next_i == len(marks):
self.already_started = False self.already_started = False
return False return False
startlat = float(marks[i][3]) startlat = float(marks[i][3])
@@ -241,41 +240,41 @@ class GeoPerson(GeoGraphyView):
self.remove_all_gps() self.remove_all_gps()
self.large_move = False self.large_move = False
self.osm.gps_add(startlat, startlon, heading) self.osm.gps_add(startlat, startlon, heading)
endlat = float(marks[ni][3]) endlat = float(marks[next_i][3])
endlon = float(marks[ni][4]) endlon = float(marks[next_i][4])
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:
self.large_move = False self.large_move = False
# year format = YYYYMMDD ( for sort ) # year format = YYYYMMDD ( for sort )
startyear = str(marks[i][6])[0:4] startyear = str(marks[i][6])[0:4]
endyear = str(marks[ni][6])[0:4] endyear = str(marks[next_i][6])[0:4]
endmov = str(marks[len(marks)-1][6])[0:4] endmov = str(marks[len(marks)-1][6])[0:4]
years = int(endyear) - int(startyear) years = int(endyear) - int(startyear)
if years < 1: if years < 1:
years = 1 years = 1
if stepyear > 8999: if stepyear > 8999:
latstep = ( endlat - startlat ) / self._config.get("geography.steps") latstep = (endlat - startlat) / self._config.get("geography.steps")
lonstep = ( endlon - startlon ) / self._config.get("geography.steps") lonstep = (endlon - startlon) / self._config.get("geography.steps")
startlat += ( latstep * (stepyear - 8999) ) startlat += (latstep * (stepyear - 8999))
startlon += ( lonstep * (stepyear - 8999) ) startlon += (lonstep * (stepyear - 8999))
else: else:
latstep = ( endlat - startlat ) / years latstep = (endlat - startlat) / years
lonstep = ( endlon - startlon ) / years lonstep = (endlon - startlon) / years
stepyear = 1 if stepyear < 1 else stepyear stepyear = 1 if stepyear < 1 else stepyear
startlat += ( latstep * stepyear ) startlat += (latstep * stepyear)
startlon += ( lonstep * stepyear ) startlon += (lonstep * stepyear)
self.osm.gps_add(startlat, startlon, heading) self.osm.gps_add(startlat, startlon, heading)
stepyear += 1 stepyear += 1
difflat = round(( startlat - endlat ) if startlat > endlat else \ difflat = round((startlat - endlat) if startlat > endlat else \
( endlat - startlat ), 8) (endlat - startlat), 8)
difflon = round(( startlon - endlon ) if startlon > endlon else \ difflon = round((startlon - endlon) if startlon > endlon else \
( endlon - startlon ), 8) (endlon - startlon), 8)
if ( difflat == 0.0 and difflon == 0.0 ): if difflat == 0.0 and difflon == 0.0:
i += 1 i += 1
self.large_move = False self.large_move = False
stepyear = 1 stepyear = 1
@@ -283,13 +282,12 @@ class GeoPerson(GeoGraphyView):
# For a 100 years person, it takes 10 secondes. # For a 100 years person, it takes 10 secondes.
# if large_move, one step is the difflat or difflon / geography.steps # if large_move, one step is the difflat or difflon / geography.steps
# in this case, stepyear is >= 9000 # in this case, stepyear is >= 9000
# large move means longitude or latitude differences greater than geography.maximum_lon_lat # large move means longitude or latitude differences greater than
# 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")), self.animate,
menu, marks, i, stepyear) menu, marks, i, stepyear)
return False return False
#def _createmap(self,obj):
def _createmap(self): def _createmap(self):
""" """
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
@@ -316,16 +314,18 @@ class GeoPerson(GeoGraphyView):
if person is not None: if person is not None:
# 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(_("Person places for %s") % _nd.display(person)) self.message_layer.add_message(
_("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
event = dbstate.db.get_event_from_handle(event_ref.ref) event = dbstate.db.get_event_from_handle(event_ref.ref)
self.load_kml_files(event) self.load_kml_files(event)
role = event_ref.get_role() role = event_ref.get_role()
eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str(
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).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)
@@ -343,7 +343,7 @@ class GeoPerson(GeoGraphyView):
# 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:
self._append_to_places_list(descr, evt, self._append_to_places_list(descr, evt,
_nd.display(person), _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -374,28 +374,33 @@ class GeoPerson(GeoGraphyView):
if handle: if handle:
mother = dbstate.db.get_person_from_handle(handle) mother = dbstate.db.get_person_from_handle(handle)
if mother: if mother:
descr1 = "%s%s" % ( descr1, _nd.display(mother)) descr1 = "%s%s" % (descr1, _nd.display(mother))
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_ref.ref) event = dbstate.db.get_event_from_handle(
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_handle) place = dbstate.db.get_place_from_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, (latitude,
longitude, "D.D8") longitude) = conv_lat_lon(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("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str(
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
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(descr,
evt, _nd.display(person), evt, _nd.display(person),
latitude, longitude, latitude, longitude,
@@ -407,7 +412,7 @@ class GeoPerson(GeoGraphyView):
role role
) )
else: else:
self._append_to_places_without_coord( place.gramps_id, descr) self._append_to_places_without_coord(place.gramps_id, descr)
self.sort = sorted(self.place_list, self.sort = sorted(self.place_list,
key=operator.itemgetter(6) key=operator.itemgetter(6)
@@ -473,16 +478,18 @@ class GeoPerson(GeoGraphyView):
date = displayer.display(evt.get_date_object()) date = displayer.display(evt.get_date_object())
if date == "": if date == "":
date = _("Unknown") date = _("Unknown")
if ( mark[11] == EventRoleType.PRIMARY ): if mark[11] == EventRoleType.PRIMARY:
message = "(%s) %s : %s" % ( date, mark[2], mark[1] ) message = "(%s) %s : %s" % (date, mark[2], mark[1])
elif ( mark[11] == EventRoleType.FAMILY ): elif mark[11] == EventRoleType.FAMILY:
(father_name, mother_name) = self._get_father_and_mother_name(evt) (father_name,
message = "(%s) %s : %s - %s" % ( date, mark[7], father_name, mother_name ) mother_name) = self._get_father_and_mother_name(evt)
message = "(%s) %s : %s - %s" % (date, mark[7],
father_name, mother_name)
else: else:
descr = evt.get_description() descr = evt.get_description()
if descr == "": if descr == "":
descr = _('No description') descr = _('No description')
message = "(%s) %s => %s" % ( date, mark[11], descr) message = "(%s) %s => %s" % (date, mark[11], descr)
prevmark = mark prevmark = mark
add_item = Gtk.MenuItem(label=message) add_item = Gtk.MenuItem(label=message)
add_item.show() add_item.show()
@@ -541,9 +548,10 @@ class GeoPerson(GeoGraphyView):
"", "",
2, 'geography.speed', 2, 'geography.speed',
(100, 1000)) (100, 1000))
configdialog.add_text(grid, configdialog.add_text(
_('How many steps between two markers when we are on large move ?'), grid,
3, line_wrap=False) _('How many steps between two markers when we are on large move ?'),
3, line_wrap=False)
configdialog.add_slider(grid, configdialog.add_slider(grid,
"", "",
4, 'geography.steps', 4, 'geography.steps',

View File

@@ -3,7 +3,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2011 Serge Noiraud # Copyright (C) 2011-2016 Serge Noiraud
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -28,13 +28,10 @@ Geography for places
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
import sys
import time import time
import operator import operator
from gi.repository import Gdk from gi.repository import Gdk
KEY_TAB = Gdk.KEY_Tab KEY_TAB = Gdk.KEY_Tab
import socket
from gi.repository import Gtk from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -54,14 +51,8 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = 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.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.pageview import PageView
from gramps.gui.editors import EditPlace
from gramps.gui.selectors.selectplace import SelectPlace
from gramps.gui.filters.sidebar import PlaceSidebarFilter
from gramps.gui.views.navigationview import NavigationView
from gramps.gui.views.bookmarks import PlaceBookmarks from gramps.gui.views.bookmarks import PlaceBookmarks
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
@@ -106,6 +97,11 @@ _UI_DEF = '''\
</ui> </ui>
''' '''
# pylint: disable=no-member
# pylint: disable=maybe-no-member
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GeoView # GeoView
@@ -136,6 +132,9 @@ class GeoPlaces(GeoGraphyView):
self.additional_uis.append(self.additional_ui()) self.additional_uis.append(self.additional_ui())
self.no_show_places_in_status_bar = False self.no_show_places_in_status_bar = False
self.show_all = False self.show_all = False
self.itemoption = None
self.menu = None
self.cal = config.get('preferences.calendar-format-report')
def get_title(self): def get_title(self):
""" """
@@ -197,7 +196,7 @@ class GeoPlaces(GeoGraphyView):
else: else:
self._createmap(None) self._createmap(None)
def _create_one_place(self,place): def _create_one_place(self, place):
""" """
Create one entry for one place with a lat/lon. Create one entry for one place with a lat/lon.
""" """
@@ -212,7 +211,7 @@ class GeoPlaces(GeoGraphyView):
# 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:
self._append_to_places_list(descr, None, "", self._append_to_places_list(descr, None, "",
latitude, longitude, latitude, longitude,
None, None, None, None,
@@ -223,13 +222,12 @@ class GeoPlaces(GeoGraphyView):
None # family.gramps_id None # family.gramps_id
) )
def _createmap(self,place_x): def _createmap(self, place_x):
""" """
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.
""" """
dbstate = self.dbstate dbstate = self.dbstate
self.cal = config.get('preferences.calendar-format-report')
self.place_list = [] self.place_list = []
self.places_found = [] self.places_found = []
self.place_without_coordinates = [] self.place_without_coordinates = []
@@ -252,13 +250,17 @@ 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 we move the map) # gramps 3.4 python 2.7 (draw_markers are estimated when moving the map)
# 38101 places : createmap : 04'32"; create_markers : 0'04"; draw markers : N/A :: 0'03" # 38101 places: createmap: 04'32";
# 65598 places : createmap : 10'03"; create_markers : 0'07"; draw markers : N/A :: 0'05" # create_markers: 0'04"; draw markers: N/A :: 0'03"
# 65598 places: createmap: 10'03";
# create_markers: 0'07"; draw markers: N/A :: 0'05"
# gramps 3.5 python 2.7 new marker layer # gramps 3.5 python 2.7 new marker layer
# 38101 places : createmap : 03'09"; create_markers : 0'01"; draw markers : 0'04" # 38101 places: createmap: 03'09";
# 65598 places : createmap : 08'48"; create_markers : 0'01"; draw markers : 0'07" # create_markers: 0'01"; draw markers: 0'04"
_LOG.debug("%s" % time.strftime("start createmap : " # 65598 places: createmap: 08'48";
# create_markers: 0'01"; draw markers: 0'07"
_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()))
if self.show_all: if self.show_all:
self.show_all = False self.show_all = False
@@ -287,27 +289,29 @@ class GeoPlaces(GeoGraphyView):
progress.step() progress.step()
progress.close() progress.close()
elif place_x: elif place_x:
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)
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(), "D.D8") place.get_longitude(),
self.osm.set_center_and_zoom(float(latitude), float(longitude), "D.D8")
int(config.get("geography.zoom_when_center"))) self.osm.set_center_and_zoom(float(latitude), float(longitude),
int(config.get(
"geography.zoom_when_center")))
_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")))
@@ -390,7 +394,7 @@ class GeoPlaces(GeoGraphyView):
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Show all places")) add_item = Gtk.MenuItem(label=_("Show all places"))
add_item.connect("activate", self.show_all_places, event, lat , lon) add_item.connect("activate", self.show_all_places, event, lat, lon)
add_item.show() add_item.show()
menu.append(add_item) menu.append(add_item)
add_item = Gtk.MenuItem(label=_("Centering on Place")) add_item = Gtk.MenuItem(label=_("Centering on Place"))