New mapservice plugin structure, as a general solution to #2659
* configure.in * src/DataViews/PlaceView.py * src/Config/_GrampsConfigKeys.py * src/gen/plug/_manager.py * src/plugins/mapservices * src/plugins/mapservices/googlemap.py * src/plugins/mapservices/openstreetmap.py * src/plugins/lib/Makefile.am * src/plugins/lib/libmapservice.py * src/plugins/Makefile.am * src/widgets/menutoolbuttonaction.py * src/widgets/Makefile.am * src/PageView.py * po/POTFILES.in svn: r11811
This commit is contained in:
@@ -11,6 +11,7 @@ SUBDIRS = \
|
||||
graph \
|
||||
import \
|
||||
lib \
|
||||
mapservices \
|
||||
quickview \
|
||||
rel \
|
||||
textreport \
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/plugins/lib
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
libholiday.py
|
||||
libholiday.py\
|
||||
libmapservices.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/plugins/lib
|
||||
pkgpythondir = @pkgpythondir@/plugins/lib
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
Google Maps map service. Open place in maps.google.com
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
@@ -36,7 +43,11 @@ class MapService():
|
||||
A service is a singleton, we only need one to exist
|
||||
Usage is as a callable when used
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.database = None
|
||||
self.items = None
|
||||
self.url = ''
|
||||
|
||||
def __call__(self, database, items):
|
||||
"""Callable class, usable as a function. This guarantees the class is
|
||||
instantiated once when a service is registered. Afterward only calls
|
||||
@@ -45,11 +56,11 @@ class MapService():
|
||||
items: list of tuples (place_handle, description), where description
|
||||
is None or a string to use for marker (eg 'birth John Doe')
|
||||
"""
|
||||
self.db = database
|
||||
self.database = database
|
||||
self.items = items
|
||||
self.url = ''
|
||||
#An instance is called, we display the result
|
||||
self._calc_url()
|
||||
self.calc_url()
|
||||
self.__display()
|
||||
self._free()
|
||||
|
||||
@@ -57,23 +68,24 @@ class MapService():
|
||||
"""Obtain the first place object"""
|
||||
place_handle = self.items[0][0]
|
||||
|
||||
return self.db.get_place_from_handle(place_handle), self.items[0][1]
|
||||
return self.database.get_place_from_handle(place_handle), \
|
||||
self.items[0][1]
|
||||
|
||||
def _all_places(self):
|
||||
"""Obtain a list generator of all place objects
|
||||
Usage: for place, descr in mapservice.all_places()
|
||||
"""
|
||||
for handle, descr in db.get_handles():
|
||||
yield self.db.get_place_from_handle(handle), descr
|
||||
for handle, descr in self.database.get_handles():
|
||||
yield self.database.get_place_from_handle(handle), descr
|
||||
|
||||
def _lat_lon(self, place, format="D.D8"):
|
||||
"""return the lat, lon value of place in the requested format
|
||||
None, None if invalid
|
||||
"""
|
||||
return PlaceUtils.conv_lat_lon(place.get_latitude(),
|
||||
return conv_lat_lon(place.get_latitude(),
|
||||
place.get_longitude(), format)
|
||||
|
||||
def _calc_url(self):
|
||||
def calc_url(self):
|
||||
"""Base class needs to overwrite this, calculation of the self.path"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
84
src/plugins/mapservices/googlemap.py
Normal file
84
src/plugins/mapservices/googlemap.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Benny Malengier
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Google Maps map service plugin. Open place in maps.google.com
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gen.plug import PluginManager
|
||||
from libmapservice import MapService
|
||||
|
||||
|
||||
class GoogleMapService(MapService):
|
||||
"""Map service using http://maps.google.com"""
|
||||
def __init__(self):
|
||||
MapService.__init__(self)
|
||||
|
||||
def calc_url(self):
|
||||
""" Determine the url to use on maps.google.com
|
||||
Logic: use lat lon if present
|
||||
otherwise use city and country if present
|
||||
otherwise use description of the place
|
||||
"""
|
||||
place = self._get_first_place()[0]
|
||||
latitude, longitude = self._lat_lon(place)
|
||||
if longitude and latitude:
|
||||
self.url = "http://maps.google.com/?sll=%s,%s&z=15" % (latitude,
|
||||
longitude)
|
||||
return
|
||||
|
||||
city = place.get_main_location().get_city()
|
||||
country = place.get_main_location().get_country()
|
||||
if city and country:
|
||||
self.url = "http://maps.google.com/maps?q=%s,%s" % (city, country)
|
||||
return
|
||||
|
||||
titledescr = place.get_title()
|
||||
self.url = "http://maps.google.com/maps?q=%s" % \
|
||||
'+'.join(titledescr.split())
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register map service
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
PluginManager.get_instance().register_mapservice(
|
||||
name = 'GoogleMaps',
|
||||
mapservice = GoogleMapService(),
|
||||
translated_name = _("GoogleMaps"),
|
||||
status = _("Stable"),
|
||||
tooltip= _("Open on maps.google.com"),
|
||||
author_name="Benny Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
||||
88
src/plugins/mapservices/openstreetmap.py
Normal file
88
src/plugins/mapservices/openstreetmap.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Benny Malengier
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
OpenStreetMap map service plugin. Open place in openstreetmap.org
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gen.plug import PluginManager
|
||||
from libmapservice import MapService
|
||||
|
||||
|
||||
class OpensStreetMapService(MapService):
|
||||
"""Map service using http://openstreetmap.org
|
||||
Resource: http://wiki.openstreetmap.org/index.php/Name_finder
|
||||
"""
|
||||
def __init__(self):
|
||||
MapService.__init__(self)
|
||||
|
||||
def calc_url(self):
|
||||
""" Determine the url to use
|
||||
Logic: use lat lon if present
|
||||
otherwise use city and country if present
|
||||
otherwise use description of the place
|
||||
"""
|
||||
place = self._get_first_place()[0]
|
||||
latitude, longitude = self._lat_lon(place)
|
||||
if longitude and latitude:
|
||||
self.url = "http://www.openstreetmap.org/" \
|
||||
"?lat=%s&lon=%s&zoom=15" % (latitude, longitude)
|
||||
|
||||
return
|
||||
|
||||
city = place.get_main_location().get_city()
|
||||
country = place.get_main_location().get_country()
|
||||
if city and country:
|
||||
self.url = "http://gazetteer.openstreetmap.org/namefinder/"\
|
||||
"?find=%s%%2C%s" % (city, country)
|
||||
return
|
||||
|
||||
titledescr = place.get_title()
|
||||
self.url = "http://gazetteer.openstreetmap.org/namefinder/"\
|
||||
"?find=%s" % '+'.join(titledescr.split())
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register map service
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
PluginManager.get_instance().register_mapservice(
|
||||
name = 'OpenStreetMap',
|
||||
mapservice = OpensStreetMapService(),
|
||||
translated_name = _("OpenStreetMap"),
|
||||
status = _("Stable"),
|
||||
tooltip= _("Open on openstreetmap.org"),
|
||||
author_name="Benny Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
||||
Reference in New Issue
Block a user