2008-12-08 16:34:54 +05:30
|
|
|
# -*- python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2009-09-08 02:43:38 +05:30
|
|
|
# Copyright (C) 2007-2009 Serge Noiraud
|
2009-09-20 15:26:34 +05:30
|
|
|
# Copyright (C) 2008 Benny Malengier
|
|
|
|
# Copyright (C) 2009 Gerald Britton
|
2009-09-08 02:43:38 +05:30
|
|
|
# Copyright (C) 2009 Helge GRAMPS
|
|
|
|
# Copyright (C) 2009 Josip
|
2009-12-23 02:20:45 +05:30
|
|
|
# Copyright (C) 2009 Gary Burton
|
2009-12-23 15:38:16 +05:30
|
|
|
# Copyright (C) 2009 Nick Hall
|
2008-12-08 16:34:54 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
Geo View
|
|
|
|
"""
|
2008-12-08 16:34:54 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2008-12-08 16:34:54 +05:30
|
|
|
import os
|
|
|
|
import urlparse
|
|
|
|
import const
|
2009-01-19 04:33:05 +05:30
|
|
|
import operator
|
2009-09-08 02:43:38 +05:30
|
|
|
import locale
|
2009-12-24 17:48:18 +05:30
|
|
|
from gtk.keysyms import Tab as KEY_TAB
|
2008-12-08 16:34:54 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2009-10-23 01:22:27 +05:30
|
|
|
import pango
|
|
|
|
import gobject
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2008-12-09 12:56:03 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gen.lib
|
|
|
|
import Utils
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2009-12-23 02:20:45 +05:30
|
|
|
import Errors
|
2009-09-26 01:20:38 +05:30
|
|
|
from gui.utils import add_menuitem
|
|
|
|
from ReportBase import CSS_FILES
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.display.name import displayer as _nd
|
2008-12-10 20:29:26 +05:30
|
|
|
from PlaceUtils import conv_lat_lon
|
2009-10-08 02:21:12 +05:30
|
|
|
from gui.views.pageview import PageView
|
2009-12-23 02:20:45 +05:30
|
|
|
from gui.editors import EditPlace
|
2009-12-23 23:50:44 +05:30
|
|
|
from gui.selectors.selectplace import SelectPlace
|
2010-01-20 01:04:47 +05:30
|
|
|
from Filters.SideBar import PlaceSidebarFilter, EventSidebarFilter
|
2008-12-09 12:56:03 +05:30
|
|
|
|
2009-09-23 12:19:59 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# map icons
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-10-01 03:11:50 +05:30
|
|
|
_ICONS = {
|
2009-10-23 01:22:27 +05:30
|
|
|
gen.lib.EventType.BIRTH : 'gramps-geo-birth',
|
|
|
|
gen.lib.EventType.DEATH : 'gramps-geo-death',
|
|
|
|
gen.lib.EventType.MARRIAGE : 'gramps-geo-marriage',
|
2009-09-23 12:19:59 +05:30
|
|
|
}
|
|
|
|
|
2008-12-08 16:34:54 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2009-09-08 02:43:38 +05:30
|
|
|
# regexp for html title Notes ...
|
2008-12-08 16:34:54 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-09-08 02:43:38 +05:30
|
|
|
import re
|
|
|
|
ZOOMANDPOS = re.compile('zoom=([0-9]*) coord=([0-9\.\-\+]*), ([0-9\.\-\+]*):::')
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-09-08 02:43:38 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Web interfaces
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-09-08 02:43:38 +05:30
|
|
|
URL_SEP = '/'
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-11-10 02:01:19 +05:30
|
|
|
from htmlrenderer import HtmlView
|
2008-12-08 16:34:54 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-01-08 15:18:42 +05:30
|
|
|
GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview')
|
2009-01-19 04:33:05 +05:30
|
|
|
NB_MARKERS_PER_PAGE = 200
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-09-16 21:42:40 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Javascript template
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2009-09-20 15:26:34 +05:30
|
|
|
_HTMLHEADER = '''<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
|
2009-10-24 02:13:18 +05:30
|
|
|
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" %(xmllang)s >
|
2009-09-20 15:26:34 +05:30
|
|
|
<html xmlns=\"http://www.w3.org/1999/xhtml\" >
|
2009-10-23 01:22:27 +05:30
|
|
|
<head>
|
|
|
|
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>
|
|
|
|
<title>This is used to pass messages between javascript and python</title>
|
|
|
|
<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">
|
2009-10-24 02:13:18 +05:30
|
|
|
%(css)s<script type=\"text/javascript\"'''
|
2009-09-20 15:26:34 +05:30
|
|
|
|
2009-09-16 21:42:40 +05:30
|
|
|
_JAVASCRIPT = '''<script>
|
2009-10-23 01:22:27 +05:30
|
|
|
var gmarkers = []; var min = 0; var zoom = 0; var uzoom = 0;
|
|
|
|
var pos = 0; var mapstraction;
|
|
|
|
var regrep = new RegExp(\"default\",\"g\");
|
|
|
|
var current_map; var ulat; var ulon; var default_icon;
|
2009-10-24 02:13:18 +05:30
|
|
|
function getArgs(){
|
2009-10-23 01:22:27 +05:30
|
|
|
var args = new Object();
|
|
|
|
var query = location.search.substring(1);
|
|
|
|
var pairs = query.split("&");
|
|
|
|
search_array = query.split("&");
|
2009-10-24 02:13:18 +05:30
|
|
|
for (var i=0; i < pairs.length; i++){
|
2009-10-23 01:22:27 +05:30
|
|
|
var pos = pairs[i].indexOf('=');
|
|
|
|
if (pos == -1) continue;
|
|
|
|
var argname = pairs[i].substring(0,pos);
|
|
|
|
var value = pairs[i].substring(pos+1);
|
|
|
|
args[argname] = unescape(value);
|
2009-10-24 02:13:18 +05:30
|
|
|
}
|
2009-10-23 01:22:27 +05:30
|
|
|
return args;
|
2009-10-24 02:13:18 +05:30
|
|
|
}
|
2009-10-23 01:22:27 +05:30
|
|
|
var selectedmarkers = 'All';
|
|
|
|
// shows or hide markers of a particular category
|
2009-10-24 02:13:18 +05:30
|
|
|
function selectmarkers(year) {
|
2009-10-23 01:22:27 +05:30
|
|
|
selectedmarkers = year;
|
2009-10-24 02:13:18 +05:30
|
|
|
for (var i=0; i<gmarkers.length; i++) {
|
2009-10-23 01:22:27 +05:30
|
|
|
val = gmarkers[i].getAttribute("year");
|
|
|
|
min = parseInt(year);
|
|
|
|
max = min + step;
|
2009-10-24 02:13:18 +05:30
|
|
|
if ( selectedmarkers == "All" ) { min = 0; max = 9999; }
|
2009-10-23 01:22:27 +05:30
|
|
|
gmarkers[i].hide();
|
|
|
|
years = val.split(' ');
|
2009-10-24 02:13:18 +05:30
|
|
|
for ( j=0; j < years.length; j++) {
|
|
|
|
if ( years[j] >= min ) {
|
|
|
|
if ( years[j] < max ) {
|
2009-10-23 01:22:27 +05:30
|
|
|
gmarkers[i].show();
|
2009-10-24 02:13:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function savezoomandposition(map) {
|
2009-10-23 01:22:27 +05:30
|
|
|
var t=setTimeout("savezoomandposition(mapstraction)",1000);
|
|
|
|
// shows or hide markers of a particular category
|
|
|
|
nzoom = map.getZoom();
|
|
|
|
nposition=map.getCenter();
|
2009-10-24 02:13:18 +05:30
|
|
|
if ( ( nzoom != zoom ) || ( nposition != pos )) {
|
2009-10-23 01:22:27 +05:30
|
|
|
zoom = nzoom;
|
|
|
|
pos = nposition;
|
|
|
|
document.title = "zoom=" + zoom + " coord=" + pos + ":::";
|
2009-10-24 02:13:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
function placeclick(i) {
|
2009-10-23 01:22:27 +05:30
|
|
|
gmarkers[i].openBubble();
|
2009-10-24 02:13:18 +05:30
|
|
|
}
|
2009-09-16 21:42:40 +05:30
|
|
|
'''
|
|
|
|
|
2009-09-20 15:26:34 +05:30
|
|
|
_HTMLTRAILER = '''
|
2009-10-23 01:22:27 +05:30
|
|
|
setmarkers(mapstraction);
|
|
|
|
setcenterandzoom(mapstraction,uzoom,ulat,ulon);
|
|
|
|
savezoomandposition(mapstraction);
|
|
|
|
mapstraction.enableScrollWheelZoom();
|
|
|
|
</script>
|
|
|
|
</body>
|
2009-09-20 15:26:34 +05:30
|
|
|
</html>
|
|
|
|
'''
|
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-09-08 02:43:38 +05:30
|
|
|
def _get_sign(value):
|
2008-12-10 04:20:21 +05:30
|
|
|
"""
|
2009-09-08 02:43:38 +05:30
|
|
|
return 1 if we have a negative number, 0 in other case
|
2008-12-10 04:20:21 +05:30
|
|
|
"""
|
2009-09-08 02:43:38 +05:30
|
|
|
if value < 0.0:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def _get_zoom_lat(value):
|
2009-09-20 15:26:34 +05:30
|
|
|
"""
|
|
|
|
return the zoom value for latitude depending on the distance.
|
|
|
|
"""
|
2009-09-08 02:43:38 +05:30
|
|
|
zoomlat = 1
|
2009-09-20 15:26:34 +05:30
|
|
|
for i, distance in enumerate([80.0, 40.0, 20.0, 10.0, 3.0,
|
2009-09-08 02:43:38 +05:30
|
|
|
2.0, 1.0, 0.5, 0.2, 0.1]):
|
2009-09-20 15:26:34 +05:30
|
|
|
if value < distance:
|
2009-09-08 02:43:38 +05:30
|
|
|
zoomlat = i+1
|
|
|
|
return zoomlat + 2
|
|
|
|
|
|
|
|
def _get_zoom_long(value):
|
2009-09-20 15:26:34 +05:30
|
|
|
"""
|
|
|
|
return the zoom value for longitude depending on the distance.
|
|
|
|
"""
|
2009-09-08 02:43:38 +05:30
|
|
|
zoomlong = 1
|
2009-09-20 15:26:34 +05:30
|
|
|
for i, distance in enumerate([120.0, 60.0, 30.0, 15.0, 7.0,
|
2009-09-08 02:43:38 +05:30
|
|
|
4.0, 2.0, 1.0, .5, .2, .1]):
|
2009-09-20 15:26:34 +05:30
|
|
|
if value < distance:
|
2009-09-08 02:43:38 +05:30
|
|
|
zoomlong = i+1
|
|
|
|
return zoomlong + 2
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _make_callback(func, val):
|
2009-10-01 03:11:50 +05:30
|
|
|
"""
|
|
|
|
return a function
|
|
|
|
"""
|
2009-09-26 01:20:38 +05:30
|
|
|
return lambda x: func(val)
|
|
|
|
|
2008-12-08 16:34:54 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GeoView
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-12-12 17:43:22 +05:30
|
|
|
class GeoView(HtmlView):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
The view used to render html pages.
|
|
|
|
"""
|
|
|
|
def __init__(self, dbstate, uistate):
|
2009-12-23 23:27:54 +05:30
|
|
|
HtmlView.__init__(self, dbstate, uistate, title=_("GeoView"))
|
2009-09-20 15:26:34 +05:30
|
|
|
self.dbstate = dbstate
|
2009-12-23 02:20:45 +05:30
|
|
|
self.uistate = uistate
|
2009-09-08 02:43:38 +05:30
|
|
|
self.dbstate.connect('database-changed', self._new_database)
|
2008-12-08 16:34:54 +05:30
|
|
|
self.usedmap = "openstreetmap"
|
2009-10-01 03:11:50 +05:30
|
|
|
self.placeslist = []
|
|
|
|
self.stylesheetlabel = []
|
|
|
|
self.stylesheetdata = {}
|
2009-10-02 23:43:44 +05:30
|
|
|
self.stylesheetlbl = None
|
2008-12-08 16:34:54 +05:30
|
|
|
self.displaytype = "person"
|
2009-01-19 04:33:05 +05:30
|
|
|
self.nbmarkers = 0
|
2009-10-28 00:18:43 +05:30
|
|
|
self.nbplaces = 0
|
2009-01-29 05:26:32 +05:30
|
|
|
self.without = 0
|
2009-01-19 04:33:05 +05:30
|
|
|
self.nbpages = 0
|
2009-10-30 14:11:21 +05:30
|
|
|
self.last_index = 0
|
2009-02-11 04:51:46 +05:30
|
|
|
self.yearinmarker = []
|
2010-01-20 01:04:47 +05:30
|
|
|
self.javascript_ready = False
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mustcenter = False
|
2009-10-23 01:22:27 +05:30
|
|
|
self.centerlat = self.centerlon = 0.0
|
2009-02-11 04:51:46 +05:30
|
|
|
self.setattr = True
|
2009-10-23 01:22:27 +05:30
|
|
|
self.latit = self.longt = 0.0
|
|
|
|
self.height = self.width = 0.0
|
2009-02-11 04:51:46 +05:30
|
|
|
self.zoom = 1
|
2009-09-08 02:43:38 +05:30
|
|
|
self.lock_action = None
|
|
|
|
self.realzoom = 0
|
2009-10-23 01:22:27 +05:30
|
|
|
self.reallatitude = self.reallongitude = 0.0
|
2010-01-08 03:32:38 +05:30
|
|
|
self.cal = 0
|
2009-10-08 06:42:51 +05:30
|
|
|
if config.get('geoview.lock'):
|
|
|
|
self.realzoom = config.get('geoview.zoom')
|
|
|
|
self.displaytype = config.get('geoview.map')
|
2009-09-08 02:43:38 +05:30
|
|
|
self.reallatitude, self.reallongitude = conv_lat_lon(
|
2009-10-08 06:42:51 +05:30
|
|
|
config.get('geoview.latitude'),
|
|
|
|
config.get('geoview.longitude'),
|
2009-09-08 02:43:38 +05:30
|
|
|
"D.D8")
|
2009-10-08 06:42:51 +05:30
|
|
|
self.stylesheet = config.get('geoview.stylesheet')
|
2009-09-26 01:20:38 +05:30
|
|
|
if ( self.stylesheet == "" ):
|
|
|
|
self.stylesheet = CSS_FILES[0][1]
|
2009-10-23 01:22:27 +05:30
|
|
|
self.minyear = self.maxyear = 1
|
|
|
|
self.maxbut = 10
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview = None
|
|
|
|
self.yearint = 0
|
|
|
|
self.centered = True
|
|
|
|
self.center = True
|
|
|
|
self.place_list = []
|
|
|
|
self.htmlfile = ""
|
|
|
|
self.places = []
|
|
|
|
self.sort = []
|
2009-10-06 02:00:26 +05:30
|
|
|
self.psort = []
|
2009-12-24 17:48:18 +05:30
|
|
|
self.clear = gtk.Button("")
|
2009-10-30 14:11:21 +05:30
|
|
|
self.buttons = gtk.ListStore(gobject.TYPE_STRING, # The year
|
|
|
|
)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.plist = gtk.ListStore(gobject.TYPE_STRING, # The name
|
|
|
|
gobject.TYPE_INT, # the marker index
|
|
|
|
gobject.TYPE_INT # the marker page
|
|
|
|
)
|
2009-12-24 17:48:18 +05:30
|
|
|
# I suppress sort in the combobox for performances.
|
|
|
|
# I tried to load a database with more than 35000 places.
|
|
|
|
# with the sort function, its takes approximatively 20 minutes
|
|
|
|
# to see the combobox and the map.
|
|
|
|
# Without the sort function, it takes approximatively 4 minutes.
|
|
|
|
#self.plist.set_sort_column_id(0, gtk.SORT_ASCENDING)
|
2009-02-11 04:51:46 +05:30
|
|
|
self.without_coord_file = []
|
|
|
|
self.place_without_coordinates = []
|
2009-10-23 01:22:27 +05:30
|
|
|
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
|
2009-10-30 14:11:21 +05:30
|
|
|
self.last_year = None
|
2009-11-05 03:45:45 +05:30
|
|
|
self.last_selected_year = 0
|
2009-10-23 01:22:27 +05:30
|
|
|
self.header_size = 0
|
|
|
|
self.years = gtk.HBox()
|
2009-10-30 14:11:21 +05:30
|
|
|
self.ylabel = gtk.Label("")
|
|
|
|
self.ylabel.set_alignment(1.0, 0.5)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.yearsbox = gtk.ComboBox(self.buttons) # pylint: disable-msg=W0201
|
|
|
|
self.yearsbox.pack_start(cell)
|
|
|
|
self.yearsbox.add_attribute(self.yearsbox.get_cells()[0], 'text', 0)
|
|
|
|
self.yearsbox.connect('changed', self._ask_year_selection)
|
|
|
|
self.years.pack_start(self.ylabel, True, True, padding=2)
|
|
|
|
self.years.pack_start(self.yearsbox, True, True, padding=2)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.pages_selection = gtk.HBox()
|
|
|
|
self.pages = []
|
|
|
|
self.last_page = 1
|
|
|
|
self.pages.append(gtk.Button("<<"))
|
|
|
|
self.pages.append(gtk.Button("1")) # current page
|
|
|
|
self.pages.append(gtk.Button(">>"))
|
|
|
|
for page in self.pages:
|
|
|
|
page.connect("clicked", self._ask_new_page)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.pages_selection.pack_start(page, False, False, padding=2)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.nocoord = gtk.Button("Unref") # don't translate
|
|
|
|
self.nocoord.connect("clicked", self._show_places_without_coord)
|
|
|
|
self.without_coord_file = os.path.join(GEOVIEW_SUBPATH,
|
|
|
|
"without_coord.html")
|
2009-11-02 03:40:54 +05:30
|
|
|
self.endinit = False
|
2010-01-20 01:04:47 +05:30
|
|
|
self.generic_filter = None
|
|
|
|
self.hpaned = gtk.HBox() # for filters
|
|
|
|
self.filter.pack_start(self.hpaned, True, True)
|
2009-12-23 23:50:44 +05:30
|
|
|
self.signal_map = {'place-add': self._place_changed,
|
|
|
|
'place-update' : self._place_changed}
|
2009-12-23 12:36:44 +05:30
|
|
|
|
2009-12-23 23:50:44 +05:30
|
|
|
def _place_changed(self, handle_list):
|
2010-01-08 03:32:38 +05:30
|
|
|
"""
|
|
|
|
One place changed. need to display it.
|
|
|
|
"""
|
2009-12-23 12:36:44 +05:30
|
|
|
self.displaytype = "places"
|
2009-12-23 15:38:16 +05:30
|
|
|
self._set_lock_unlock(True)
|
2010-01-20 01:04:47 +05:30
|
|
|
self.filter_toggle(None, None, None, None)
|
2009-12-23 12:36:44 +05:30
|
|
|
self._geo_places()
|
|
|
|
|
2009-02-17 00:12:38 +05:30
|
|
|
def top_widget(self):
|
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
The top widget to use, for GeoView :
|
|
|
|
- Places list search
|
|
|
|
- Page selection if more than NB_MARKERS_PER_PAGE markers.
|
|
|
|
- Place without coordinates if needed
|
|
|
|
- Years selection
|
|
|
|
"""
|
|
|
|
self.box1 = gtk.VBox(False, 1) # pylint: disable-msg=W0201
|
2009-12-24 17:48:18 +05:30
|
|
|
self.clear.set_alignment(1.0, 0.5)
|
2009-10-23 01:22:27 +05:30
|
|
|
cell = gtk.CellRendererText()
|
2009-10-30 14:11:21 +05:30
|
|
|
self.placebox = gtk.ComboBoxEntry(self.plist)# pylint: disable-msg=W0201
|
|
|
|
self.placebox.pack_start(cell)
|
|
|
|
self.placebox.add_attribute(self.placebox.get_cells()[0], 'text', 0)
|
2009-10-23 01:22:27 +05:30
|
|
|
completion = gtk.EntryCompletion()
|
|
|
|
completion.set_model(self.plist)
|
|
|
|
completion.set_minimum_key_length(1)
|
|
|
|
completion.set_text_column(0)
|
|
|
|
completion.set_inline_completion(True)
|
|
|
|
completion.set_match_func(self._match_string)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.placebox.child.connect('changed', self._entry_selected_place)
|
2009-12-24 17:48:18 +05:30
|
|
|
self.placebox.child.connect('key-press-event', self._entry_key_event)
|
|
|
|
self.clear.connect('clicked', self._erase_placebox_selection)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.placebox.child.set_completion(completion)
|
2009-10-23 01:22:27 +05:30
|
|
|
box = gtk.HBox()
|
2009-12-24 17:48:18 +05:30
|
|
|
box.pack_start(self.clear, False, False, padding=2)
|
2009-10-30 14:11:21 +05:30
|
|
|
box.pack_start(self.placebox, False, False, padding=2)
|
2009-10-23 01:22:27 +05:30
|
|
|
box.pack_start(self.pages_selection, False, False, padding=2)
|
|
|
|
box.pack_start(self.nocoord, False, False, padding=2)
|
2009-10-30 14:11:21 +05:30
|
|
|
box.pack_start(self.years, False, False, padding=2)
|
2009-10-23 01:22:27 +05:30
|
|
|
box.show_all()
|
|
|
|
self.title = gtk.Label('')
|
|
|
|
self.title.set_single_line_mode(True)
|
|
|
|
font = pango.FontDescription("monospace")
|
|
|
|
font.set_weight(pango.WEIGHT_HEAVY)
|
|
|
|
font.set_style(pango.STYLE_NORMAL)
|
|
|
|
self.title.modify_font(font)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.box1.pack_start(box, False, False, padding=2)
|
|
|
|
self.box1.pack_start(self.title, False, False, padding=2)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.box1.show_all()
|
2010-01-20 01:04:47 +05:30
|
|
|
if self.displaytype == "places":
|
|
|
|
self.build_filters_container(self.filter, PlaceSidebarFilter)
|
|
|
|
elif self.displaytype == "event":
|
|
|
|
self.build_filters_container(self.filter, EventSidebarFilter)
|
2009-10-23 01:22:27 +05:30
|
|
|
return self.box1
|
|
|
|
|
2009-12-24 17:48:18 +05:30
|
|
|
def _entry_key_event(self, widget, event):
|
|
|
|
"""
|
|
|
|
The user enter characters. If he enter tab, I'll try to complete.
|
|
|
|
This is used when the completion doen't start at the beginning
|
|
|
|
of the word or sentence.
|
|
|
|
i.e : If we have in our place list :
|
|
|
|
...
|
|
|
|
"town of london, England"
|
|
|
|
"in the town of londonderry"
|
|
|
|
"ville de londres"
|
|
|
|
...
|
|
|
|
in the entrybox, if you select "londr", then enter tab,
|
|
|
|
the selected item will be "ville de londres"
|
|
|
|
"""
|
|
|
|
prefix = widget.get_text().lower()
|
|
|
|
count = 0
|
|
|
|
found = "inconnu"
|
|
|
|
if event.keyval == KEY_TAB:
|
|
|
|
for place in self.plist:
|
|
|
|
if prefix in place[0].lower():
|
|
|
|
count += 1
|
|
|
|
found = place[0]
|
|
|
|
if count == 1:
|
|
|
|
self.placebox.child.set_text(found)
|
|
|
|
pass
|
|
|
|
|
2009-10-30 14:11:21 +05:30
|
|
|
def _match_string(self, compl, key, fiter): # pylint: disable-msg=W0613
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
Used to select places in the combobox.
|
|
|
|
"""
|
|
|
|
model = compl.get_model()
|
|
|
|
text = model.get_value(fiter, 0)
|
|
|
|
# the key passed to this function is not unicode! bug ?
|
|
|
|
# ie : in french, when you enter é, key is equal to e
|
|
|
|
ukey = compl.get_entry().get_text()
|
|
|
|
if ukey is None or text is None:
|
|
|
|
return False
|
|
|
|
if ukey.lower() in text.lower():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _set_years_selection(self, yearbase, step, maxyear):
|
|
|
|
"""
|
2009-10-30 14:11:21 +05:30
|
|
|
Creation of the years list for the years comboBox.
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
base = 0
|
2009-11-05 03:45:45 +05:30
|
|
|
self.ylabel.set_text("%s : %d %s" % ( _("Time period"),
|
|
|
|
step, _("years")) )
|
|
|
|
self.yearsbox.hide()
|
|
|
|
self.yearsbox.freeze_child_notify()
|
|
|
|
self.yearsbox.set_model(None)
|
|
|
|
self.buttons.clear()
|
2009-10-30 14:11:21 +05:30
|
|
|
self.buttons.append([""])
|
|
|
|
self.buttons.append([_("All")])
|
|
|
|
for but in range(0, self.maxbut + 1): # pylint: disable-msg=W0612
|
|
|
|
newyear = yearbase + base
|
|
|
|
if newyear <= maxyear:
|
|
|
|
self.buttons.append([str(newyear)])
|
2009-10-23 01:22:27 +05:30
|
|
|
base += step
|
2009-11-05 03:45:45 +05:30
|
|
|
self.yearsbox.set_model(self.buttons)
|
|
|
|
self.yearsbox.set_active(1)
|
|
|
|
self.yearsbox.show()
|
|
|
|
self.yearsbox.thaw_child_notify()
|
2009-10-23 01:22:27 +05:30
|
|
|
|
|
|
|
def _ask_year_selection(self, widget, data=None):
|
|
|
|
# pylint: disable-msg=W0613
|
|
|
|
"""
|
2009-10-30 14:11:21 +05:30
|
|
|
Ask to the renderer to apply the selected year
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
if widget == None:
|
|
|
|
return
|
|
|
|
if widget.get_active():
|
2009-10-30 14:11:21 +05:30
|
|
|
self.last_year = widget
|
2009-10-23 01:22:27 +05:30
|
|
|
self._set_markersonpage(widget)
|
|
|
|
|
|
|
|
def _ask_new_page(self, widget, data=None): # pylint: disable-msg=W0613
|
|
|
|
"""
|
|
|
|
Ask to select a new page when we are in a multi-pages map.
|
|
|
|
"""
|
|
|
|
if widget == None:
|
|
|
|
return
|
|
|
|
page = widget.get_label()
|
2009-10-28 00:18:43 +05:30
|
|
|
(current, maxp ) = self.pages[1].get_label().split('/', 1)
|
|
|
|
if ( page == "<<" and int(current) > 1):
|
2009-10-23 01:22:27 +05:30
|
|
|
cpage = -1
|
2009-10-28 00:18:43 +05:30
|
|
|
elif ( page == ">>" and int(current) < int(maxp)):
|
2009-10-23 01:22:27 +05:30
|
|
|
cpage = +1
|
|
|
|
else:
|
|
|
|
cpage = 0
|
|
|
|
cpage += int(current)
|
|
|
|
self.last_page = cpage
|
|
|
|
ftype = {"places":'P', "event":'E', "family":'F', "person":'I'}.get(
|
|
|
|
self.displaytype, 'X')
|
|
|
|
url = os.path.join(GEOVIEW_SUBPATH, "GeoV-%c-%05d.html" % (ftype,
|
|
|
|
cpage))
|
|
|
|
url = urlparse.urlunsplit( ('file', '', URL_SEP.join(url.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
url += '?map=%s' % self.usedmap
|
|
|
|
url += '&zoom=%d' % int(self.realzoom)
|
|
|
|
url += '&lat=%s' % str(self.reallatitude)
|
|
|
|
url += '&lon=%s' % str(self.reallongitude)
|
2009-12-16 05:13:00 +05:30
|
|
|
self._openurl(url)
|
2009-10-23 01:22:27 +05:30
|
|
|
self._create_pages_selection(cpage, int(maxp))
|
|
|
|
self._savezoomandposition()
|
2009-11-05 03:45:45 +05:30
|
|
|
# Need to wait the page is loaded to show the markers.
|
|
|
|
gobject.timeout_add(1500, self._show_selected_places)
|
2009-12-24 17:48:18 +05:30
|
|
|
self.placebox.child.set_text("")
|
2009-11-05 03:45:45 +05:30
|
|
|
|
|
|
|
def _show_selected_places(self):
|
|
|
|
"""
|
|
|
|
Here, we synchronize the years combobox with the renderer
|
2009-12-18 13:06:20 +05:30
|
|
|
except when we are in the places view.
|
2009-11-05 03:45:45 +05:30
|
|
|
"""
|
2009-12-18 13:06:20 +05:30
|
|
|
if self.displaytype != "places":
|
|
|
|
index = 0
|
|
|
|
for r_year in self.buttons:
|
|
|
|
if self.last_selected_year == r_year[0]:
|
|
|
|
self.yearsbox.set_active(index)
|
|
|
|
self._call_js_selectmarkers(r_year[0])
|
|
|
|
index += 1
|
2009-10-23 01:22:27 +05:30
|
|
|
|
|
|
|
def _show_places_without_coord(self, widget): # pylint: disable-msg=W0613
|
|
|
|
"""
|
|
|
|
Show the page which contains the list of all places without coordinates.
|
2009-02-17 00:12:38 +05:30
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
url = urlparse.urlunsplit( ('file', '',
|
|
|
|
URL_SEP.join(self.without_coord_file.split(os.sep)),
|
|
|
|
'', ''))
|
2009-12-16 05:13:00 +05:30
|
|
|
self._openurl(url)
|
2009-02-17 00:12:38 +05:30
|
|
|
|
2009-10-30 14:11:21 +05:30
|
|
|
def _entry_selected_place(self, combobox): # pylint: disable-msg=W0612
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
Ask to the renderer to show the info bubble.
|
|
|
|
"""
|
|
|
|
place = combobox.get_text()
|
2009-10-30 14:11:21 +05:30
|
|
|
for entry in self.placebox.get_model():
|
2009-10-23 01:22:27 +05:30
|
|
|
if ( entry[0] == place ):
|
|
|
|
# Is this entry in the current page ?
|
2009-10-28 00:18:43 +05:30
|
|
|
if self.last_page == int(entry[2]):
|
2009-10-23 01:22:27 +05:30
|
|
|
# Yes, we don't need to load another page.
|
2009-10-28 00:18:43 +05:30
|
|
|
self._show_place_info_bubble(entry[1])
|
2009-11-05 03:45:45 +05:30
|
|
|
self._show_selected_places()
|
2009-10-23 01:22:27 +05:30
|
|
|
else:
|
|
|
|
# No, we need to load the correct page
|
2009-10-28 00:18:43 +05:30
|
|
|
self.last_page = int(entry[2])
|
2009-10-23 01:22:27 +05:30
|
|
|
ftype = { "places":'P',
|
|
|
|
"event":'E',
|
|
|
|
"family":'F',
|
|
|
|
"person":'I'}.get( self.displaytype, 'X')
|
|
|
|
url = os.path.join(GEOVIEW_SUBPATH, "GeoV-%c-%05d.html" %
|
|
|
|
(ftype, entry[2]))
|
|
|
|
url = urlparse.urlunsplit( ('file', '',
|
|
|
|
URL_SEP.join(url.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
url += '?map=%s' % self.usedmap
|
|
|
|
url += '&zoom=%d' % int(self.realzoom)
|
|
|
|
url += '&lat=%s' % str(self.reallatitude)
|
|
|
|
url += '&lon=%s' % str(self.reallongitude)
|
2009-12-16 05:13:00 +05:30
|
|
|
self._openurl(url)
|
2009-10-23 01:22:27 +05:30
|
|
|
(current, maxp ) = self.pages[1].get_label().split('/', 1)
|
|
|
|
self._create_pages_selection(entry[2], int(maxp))
|
|
|
|
self._savezoomandposition()
|
2009-11-05 03:45:45 +05:30
|
|
|
# Need to wait the page is loaded to show the info bubble.
|
|
|
|
gobject.timeout_add(1500, self._show_place_info_bubble,
|
2009-10-30 14:11:21 +05:30
|
|
|
entry[1])
|
2009-11-05 03:45:45 +05:30
|
|
|
# Need to wait the page is loaded to show the markers.
|
|
|
|
gobject.timeout_add(1600, self._show_selected_places)
|
2009-10-23 01:22:27 +05:30
|
|
|
return
|
|
|
|
|
2009-10-28 00:18:43 +05:30
|
|
|
def _show_place_info_bubble(self, marker_index):
|
|
|
|
"""
|
|
|
|
We need to call javascript to show the info bubble.
|
|
|
|
"""
|
2010-01-20 01:04:47 +05:30
|
|
|
if self.javascript_ready:
|
|
|
|
self.renderer.execute_script("javascript:placeclick('%d')" %
|
|
|
|
marker_index)
|
2009-10-28 00:18:43 +05:30
|
|
|
|
2009-12-24 17:48:18 +05:30
|
|
|
def _erase_placebox_selection(self, arg):
|
2009-11-05 03:45:45 +05:30
|
|
|
"""
|
2009-12-18 13:06:20 +05:30
|
|
|
We erase the place name in the entrybox after 1 second.
|
2009-11-05 03:45:45 +05:30
|
|
|
"""
|
2009-12-24 17:48:18 +05:30
|
|
|
self.placebox.child.set_text("")
|
2009-11-05 03:45:45 +05:30
|
|
|
|
2008-12-12 17:43:22 +05:30
|
|
|
def on_delete(self):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-01-19 04:33:05 +05:30
|
|
|
We need to suppress temporary files here.
|
2009-09-08 02:43:38 +05:30
|
|
|
Save the zoom, latitude, longitude and lock
|
|
|
|
"""
|
|
|
|
self._savezoomandposition()
|
2009-10-08 06:42:51 +05:30
|
|
|
config.set('geoview.lock',
|
2009-09-08 02:43:38 +05:30
|
|
|
self.lock_action.get_action('SaveZoom').get_active()
|
|
|
|
)
|
|
|
|
if self.lock_action.get_action('SaveZoom').get_active():
|
2009-10-08 23:31:06 +05:30
|
|
|
config.set('geoview.zoom', int(self.realzoom))
|
2009-10-08 06:42:51 +05:30
|
|
|
config.set('geoview.latitude', self.reallatitude)
|
|
|
|
config.set('geoview.longitude', self.reallongitude)
|
|
|
|
config.set('geoview.map', self.displaytype)
|
2009-09-08 02:43:38 +05:30
|
|
|
else:
|
2009-10-08 06:42:51 +05:30
|
|
|
config.set('geoview.zoom', 0)
|
|
|
|
config.set('geoview.latitude', "0.0")
|
|
|
|
config.set('geoview.longitude', "0.0")
|
|
|
|
config.set('geoview.map', "person")
|
|
|
|
config.set('geoview.stylesheet', self.stylesheet)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2008-12-12 03:34:45 +05:30
|
|
|
def init_parent_signals_for_map(self, widget, event):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
Required to properly bootstrap the signal handlers.
|
|
|
|
This handler is connected by build_widget.
|
|
|
|
After the outside ViewManager has placed this widget we are
|
|
|
|
able to access the parent container.
|
|
|
|
"""
|
2008-12-12 17:43:22 +05:30
|
|
|
self.box.disconnect(self.bootstrap_handler)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.years.hide()
|
|
|
|
self.pages_selection.hide()
|
|
|
|
self.nocoord.hide()
|
|
|
|
self.box.connect("size-allocate", self._size_request_for_map)
|
2009-08-14 03:29:59 +05:30
|
|
|
self._size_request_for_map(widget.parent, event)
|
2009-01-27 04:00:13 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _size_request_for_map(self, widget, event, data=None):
|
2009-10-23 01:22:27 +05:30
|
|
|
# pylint: disable-msg=W0613
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
We need to resize the map
|
|
|
|
"""
|
|
|
|
gws = widget.get_allocation()
|
|
|
|
self.width = gws.width
|
|
|
|
self.height = gws.height
|
2009-10-23 01:22:27 +05:30
|
|
|
self.header_size = self.box1.get_allocation().height + 8
|
2010-01-11 00:49:33 +05:30
|
|
|
if not self.uistate.get_active('Person'):
|
2009-10-06 02:00:26 +05:30
|
|
|
return
|
2009-01-05 05:12:20 +05:30
|
|
|
self.external_uri()
|
2008-12-12 03:34:45 +05:30
|
|
|
|
2008-12-08 16:34:54 +05:30
|
|
|
def set_active(self):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Set view active when we enter into this view.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2008-12-08 16:34:54 +05:30
|
|
|
self.key_active_changed = self.dbstate.connect('active-changed',
|
2009-10-23 01:22:27 +05:30
|
|
|
self._goto_active_person)
|
|
|
|
self._goto_active_person()
|
2010-02-04 03:13:45 +05:30
|
|
|
self.filter.hide() # hide the filter
|
2009-01-27 04:00:13 +05:30
|
|
|
|
2008-12-08 16:34:54 +05:30
|
|
|
def set_inactive(self):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Set view inactive when switching to another view.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2008-12-12 17:43:22 +05:30
|
|
|
HtmlView.set_inactive(self)
|
2008-12-08 16:34:54 +05:30
|
|
|
self.dbstate.disconnect(self.key_active_changed)
|
2009-01-27 04:00:13 +05:30
|
|
|
|
2009-11-14 22:47:34 +05:30
|
|
|
def get_stock(self):
|
|
|
|
"""
|
|
|
|
Returns the name of the stock icon to use for the display.
|
|
|
|
This assumes that this icon has already been registered
|
|
|
|
as a stock icon.
|
|
|
|
"""
|
|
|
|
return 'gramps-geo'
|
|
|
|
|
|
|
|
def get_viewtype_stock(self):
|
|
|
|
"""Type of view in category
|
|
|
|
"""
|
|
|
|
return 'gramps-geo'
|
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _savezoomandposition(self, timeloop=None):
|
2009-09-08 02:43:38 +05:30
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
The only way we have to save the zoom and position is to change the
|
|
|
|
title of the html page then to get this title.
|
2009-09-08 02:43:38 +05:30
|
|
|
When the title change, we receive a 'changed-title' signal.
|
|
|
|
Then we can get the new title with the new values.
|
|
|
|
"""
|
|
|
|
res = self.dbstate.db.get_researcher()
|
|
|
|
if res: # Don't modify the current values if no db is loaded.
|
|
|
|
start = 0
|
2009-09-09 02:58:27 +05:30
|
|
|
try:
|
|
|
|
title = ZOOMANDPOS.search(self.renderer.title, start)
|
|
|
|
if title:
|
2009-10-23 01:22:27 +05:30
|
|
|
if self.realzoom != title.group(1):
|
|
|
|
self.realzoom = title.group(1)
|
|
|
|
if self.reallatitude != title.group(2):
|
|
|
|
self.reallatitude = title.group(2)
|
|
|
|
if self.reallongitude != title.group(3):
|
|
|
|
self.reallongitude = title.group(3)
|
2009-10-30 14:11:21 +05:30
|
|
|
except: # pylint: disable-msg=W0704
|
|
|
|
pass # pylint: disable-msg=W0702
|
2009-10-23 01:22:27 +05:30
|
|
|
if timeloop:
|
|
|
|
gobject.timeout_add(timeloop, self._savezoomandposition, timeloop)
|
|
|
|
|
|
|
|
def _do_we_need_to_zoom_between_map(self):
|
|
|
|
"""
|
|
|
|
Look if we need to use the lasts zoom, latitude and longitude retrieved
|
|
|
|
from the renderer, or if we must use the last ones we just created.
|
|
|
|
"""
|
|
|
|
if self.reallatitude == None:
|
|
|
|
self.reallatitude = 0.0
|
|
|
|
if self.reallongitude == None:
|
|
|
|
self.reallongitude = 0.0
|
|
|
|
if not self.lock_action.get_action('SaveZoom').get_active():
|
|
|
|
self.reallatitude = self.latit
|
|
|
|
self.reallongitude = self.longt
|
|
|
|
self.realzoom = self.zoom
|
2009-09-08 02:43:38 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _change_map(self, usedmap):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Tell the browser to change the current map.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
self._do_we_need_to_zoom_between_map()
|
|
|
|
if self.last_page != 1:
|
|
|
|
ftype = {"places":'P',
|
|
|
|
"event":'E',
|
|
|
|
"family":'F',
|
|
|
|
"person":'I'}.get(self.displaytype, 'X')
|
|
|
|
url = os.path.join(GEOVIEW_SUBPATH, "GeoV-%c-%05d.html" %
|
|
|
|
(ftype, self.last_page))
|
|
|
|
url = urlparse.urlunsplit( ('file', '',
|
|
|
|
URL_SEP.join(url.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
else:
|
|
|
|
url = urlparse.urlunsplit( ('file', '',
|
|
|
|
URL_SEP.join(self.htmlfile.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
url += '?map=%s' % usedmap
|
|
|
|
url += '&zoom=%d' % int(self.realzoom)
|
|
|
|
url += '&lat=%s' % str(self.reallatitude)
|
|
|
|
url += '&lon=%s' % str(self.reallongitude)
|
2009-12-16 05:13:00 +05:30
|
|
|
self._openurl(url)
|
2009-09-08 02:43:38 +05:30
|
|
|
self._savezoomandposition()
|
2009-10-30 14:11:21 +05:30
|
|
|
if self.displaytype != "places":
|
|
|
|
# Need to wait the page is loaded to set the markers.
|
2009-11-05 03:45:45 +05:30
|
|
|
gobject.timeout_add(1500, self._set_markersonpage, self.last_year)
|
2009-10-23 01:22:27 +05:30
|
|
|
|
|
|
|
def _set_markersonpage(self, widget):
|
|
|
|
"""
|
2009-11-05 03:45:45 +05:30
|
|
|
get the year to select then call javascript
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
2009-11-02 03:40:54 +05:30
|
|
|
if not self.endinit:
|
|
|
|
return
|
2009-10-23 01:22:27 +05:30
|
|
|
if widget:
|
2009-10-30 14:11:21 +05:30
|
|
|
model = widget.get_model()
|
|
|
|
if model:
|
2009-11-02 03:40:54 +05:30
|
|
|
year = "no"
|
|
|
|
try:
|
|
|
|
year = model.get_value(widget.get_active_iter(), 0)
|
|
|
|
except: # pylint: disable-msg=W0704
|
|
|
|
pass # pylint: disable-msg=W0702
|
2009-12-16 05:13:00 +05:30
|
|
|
if self.last_selected_year == 0:
|
|
|
|
self.last_selected_year = year
|
|
|
|
elif year != "no":
|
2009-11-05 03:45:45 +05:30
|
|
|
self.last_selected_year = year
|
|
|
|
self._call_js_selectmarkers(year)
|
|
|
|
|
|
|
|
def _call_js_selectmarkers(self, year):
|
|
|
|
"""
|
|
|
|
Ask to the renderer to show All or specific markers.
|
|
|
|
"""
|
2010-01-20 01:04:47 +05:30
|
|
|
if self.javascript_ready:
|
|
|
|
if year == _("All"):
|
|
|
|
self.renderer.execute_script(
|
|
|
|
"javascript:selectmarkers('All')")
|
|
|
|
else:
|
|
|
|
self.renderer.execute_script(
|
|
|
|
"javascript:selectmarkers('%s')" % year )
|
2008-12-08 16:34:54 +05:30
|
|
|
|
|
|
|
def ui_definition(self):
|
|
|
|
"""
|
|
|
|
Specifies the UIManager XML code that defines the menus and buttons
|
|
|
|
associated with the interface.
|
2008-12-13 03:03:22 +05:30
|
|
|
<placeholder name="CommonNavigation">
|
|
|
|
<toolitem action="Back"/>
|
|
|
|
<toolitem action="Forward"/>
|
|
|
|
<toolitem action="Refresh"/>
|
|
|
|
</placeholder>
|
2010-02-05 17:43:24 +05:30
|
|
|
<toolitem action="StyleSheet"/>
|
|
|
|
"""
|
|
|
|
return '''<ui>
|
|
|
|
<toolbar name="ToolBar">
|
2008-12-10 04:20:21 +05:30
|
|
|
<placeholder name="CommonEdit">
|
2009-12-24 21:25:01 +05:30
|
|
|
<toolitem action="Provider"/>
|
2009-09-08 02:43:38 +05:30
|
|
|
<toolitem action="SaveZoom"/>
|
2009-12-23 02:20:45 +05:30
|
|
|
<toolitem action="AddPlace"/>
|
2009-12-23 23:50:44 +05:30
|
|
|
<toolitem action="LinkPlace"/>
|
2008-12-10 04:20:21 +05:30
|
|
|
<separator/>
|
|
|
|
<toolitem action="PersonMaps"/>
|
|
|
|
<toolitem action="FamilyMaps"/>
|
|
|
|
<toolitem action="EventMaps"/>
|
|
|
|
<toolitem action="AllPlacesMaps"/>
|
|
|
|
</placeholder>
|
|
|
|
</toolbar>
|
2009-10-23 01:22:27 +05:30
|
|
|
</ui>'''
|
2008-12-08 16:34:54 +05:30
|
|
|
|
|
|
|
def define_actions(self):
|
|
|
|
"""
|
|
|
|
Required define_actions function for PageView. Builds the action
|
2009-01-20 02:28:02 +05:30
|
|
|
group information required.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2010-02-05 17:43:24 +05:30
|
|
|
#HtmlView._define_actions_fw_bw(self)
|
|
|
|
#self.forward_action.set_sensitive(False)
|
|
|
|
#self.back_action.set_sensitive(False)
|
2009-12-23 02:20:45 +05:30
|
|
|
self._add_action('AddPlace', gtk.STOCK_ADD,
|
|
|
|
_('_Add Place'),
|
|
|
|
callback=self._add_place,
|
|
|
|
tip=_("Add the location centred on the map as a new place in "
|
|
|
|
"Gramps. Double click the location to centre on the map."))
|
2009-12-23 23:50:44 +05:30
|
|
|
self._add_action('LinkPlace', 'gramps-place',
|
|
|
|
_('_Link Place'),
|
|
|
|
callback=self._link_place,
|
|
|
|
tip=_("Link the location centred on the map to a place in "
|
|
|
|
"Gramps. Double click the location to centre on the map."))
|
2009-12-24 21:25:01 +05:30
|
|
|
self.provider_action = gtk.ActionGroup(self.title + "/Provider")
|
|
|
|
self.provider_action.add_toggle_actions([
|
|
|
|
('Provider', 'gramps-geo-mainmap', _("_Provider"), "<ALT>P",
|
|
|
|
_("Select the maps provider. You can choose "
|
|
|
|
"between OpenStreetMap and Google maps"),
|
|
|
|
self._change_provider,
|
|
|
|
)
|
|
|
|
])
|
|
|
|
self._add_action_group(self.provider_action)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.lock_action = gtk.ActionGroup(self.title + "/SaveZoom")
|
2009-09-08 02:43:38 +05:30
|
|
|
self.lock_action.add_toggle_actions([
|
|
|
|
('SaveZoom', 'gramps-lock', _("_SaveZoom"), "<ALT>L",
|
|
|
|
_("Save the zoom between places map, person map, "
|
|
|
|
"family map and events map"),
|
|
|
|
self._save_zoom,
|
2009-10-08 06:42:51 +05:30
|
|
|
config.get('geoview.lock')
|
2009-09-08 02:43:38 +05:30
|
|
|
)
|
|
|
|
])
|
|
|
|
self._add_action_group(self.lock_action)
|
2009-02-04 01:49:05 +05:30
|
|
|
self._add_action('AllPlacesMaps', gtk.STOCK_HOME, _('_All Places'),
|
2009-10-08 02:21:12 +05:30
|
|
|
callback=self._all_places, tip=_("Attempt to view all places in "
|
2009-08-14 03:29:59 +05:30
|
|
|
"the family tree."))
|
2008-12-10 04:20:21 +05:30
|
|
|
self._add_action('PersonMaps', 'gramps-person', _('_Person'),
|
2009-08-14 03:29:59 +05:30
|
|
|
callback=self._person_places,
|
|
|
|
tip=_("Attempt to view all the places "
|
|
|
|
"where the selected people lived."))
|
2008-12-10 04:20:21 +05:30
|
|
|
self._add_action('FamilyMaps', 'gramps-parents-add', _('_Family'),
|
2009-08-14 03:29:59 +05:30
|
|
|
callback=self._family_places,
|
2009-02-11 04:51:46 +05:30
|
|
|
tip=_("Attempt to view places of the selected people's family."))
|
2008-12-10 04:20:21 +05:30
|
|
|
self._add_action('EventMaps', 'gramps-event', _('_Event'),
|
2009-08-14 03:29:59 +05:30
|
|
|
callback=self._event_places,
|
2009-02-11 04:51:46 +05:30
|
|
|
tip=_("Attempt to view places connected to all events."))
|
2010-02-05 17:43:24 +05:30
|
|
|
#self._add_toolmenu_action('StyleSheet', _('Selecting stylesheet ...'),
|
|
|
|
# _("Reload the map with new style."),
|
|
|
|
# self._gotostyle,
|
|
|
|
# _('Select a StyleSheet'))
|
2010-01-20 01:04:47 +05:30
|
|
|
self._add_toggle_action('Filter', None, _('_Filter'),
|
|
|
|
callback=self.filter_toggle_action,
|
|
|
|
value=config.get('interface.filter'))
|
|
|
|
config.connect('interface.filter',self.filter_toggle)
|
2009-09-26 01:20:38 +05:30
|
|
|
|
2009-10-30 14:11:21 +05:30
|
|
|
def go_back(self, button): # pylint: disable-msg=W0613
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
Go to the previous loaded url.
|
|
|
|
We need to set all the buttons insensitive.
|
|
|
|
"""
|
|
|
|
self.box1.set_sensitive(False)
|
|
|
|
self.renderer.window.go_back()
|
|
|
|
|
2009-10-30 14:11:21 +05:30
|
|
|
def go_forward(self, button): # pylint: disable-msg=W0613
|
2009-10-23 01:22:27 +05:30
|
|
|
"""
|
|
|
|
Go to the next loaded url.
|
|
|
|
We need to set all the buttons sensitive if we cannot go forward.
|
|
|
|
"""
|
|
|
|
self.renderer.window.go_forward()
|
|
|
|
if not self.renderer.window.can_go_forward():
|
|
|
|
self.box1.set_sensitive(True)
|
|
|
|
|
2009-09-26 01:20:38 +05:30
|
|
|
def change_page(self):
|
|
|
|
"""
|
|
|
|
Called by viewmanager at end of realization when arriving on the page
|
|
|
|
At this point the Toolbar is created. We need to:
|
|
|
|
1. get the menutoolbutton
|
|
|
|
2. add all possible css styles sheet available
|
|
|
|
3. add the actions that correspond to clicking in this drop down menu
|
|
|
|
4. set icon and label of the menutoolbutton now that it is realized
|
|
|
|
5. store label so it can be changed when selection changes
|
|
|
|
"""
|
2009-10-08 02:21:12 +05:30
|
|
|
PageView.change_page(self)
|
2009-10-06 02:00:26 +05:30
|
|
|
# menutoolbutton actions are stored in PageView class,
|
2009-09-26 01:20:38 +05:30
|
|
|
# obtain the widgets where we need to add to menu
|
2010-02-05 17:43:24 +05:30
|
|
|
#actionstyles = self.action_toolmenu['StyleSheet']
|
|
|
|
#widgets = actionstyles.get_proxies()
|
|
|
|
#mmenu = self.__create_styles_menu_actions()
|
2009-09-26 01:20:38 +05:30
|
|
|
|
2010-02-05 17:43:24 +05:30
|
|
|
#if not self.stylesheetdata:
|
|
|
|
# return
|
2009-09-26 01:20:38 +05:30
|
|
|
|
2010-02-05 17:43:24 +05:30
|
|
|
#self.stylesheetlabel = []
|
2009-09-26 01:20:38 +05:30
|
|
|
|
|
|
|
#store all gtk labels to be able to update label on selection change
|
2010-02-05 17:43:24 +05:30
|
|
|
#for widget in widgets :
|
|
|
|
# if isinstance(widget, gtk.MenuToolButton):
|
|
|
|
# widget.set_menu(mmenu)
|
|
|
|
# if gtk.pygtk_version >= (2, 12, 0):
|
|
|
|
# widget.set_arrow_tooltip_text(actionstyles.arrowtooltip)
|
|
|
|
# lbl = gtk.Label(self._mapstyle_label())
|
|
|
|
# self.stylesheetlbl = lbl
|
|
|
|
# lbl.show()
|
|
|
|
# self.stylesheetlabel.append(lbl)
|
|
|
|
# widget.set_label_widget(self.stylesheetlabel[-1])
|
|
|
|
# widget.set_stock_id(gtk.STOCK_SELECT_FONT)
|
2009-09-26 02:37:38 +05:30
|
|
|
self._set_lock_unlock_icon()
|
2010-02-05 17:43:24 +05:30
|
|
|
#self._set_mapstylelabel(self.stylesheet)
|
2009-10-23 01:22:27 +05:30
|
|
|
self._savezoomandposition(500) # every 500 millisecondes
|
2009-11-02 03:40:54 +05:30
|
|
|
self.endinit = True
|
2010-01-20 01:04:47 +05:30
|
|
|
self.filter_toggle(None, None, None, None)
|
2009-12-16 05:13:00 +05:30
|
|
|
self._geo_places()
|
2009-09-26 01:20:38 +05:30
|
|
|
|
|
|
|
def __create_styles_menu_actions(self):
|
|
|
|
"""
|
|
|
|
Function creating a menu and actions that are used as dropdown menu
|
|
|
|
from the menutoolbutton
|
|
|
|
"""
|
2009-10-30 14:11:21 +05:30
|
|
|
# disable msg=W0612 # i is unused
|
2009-10-23 01:22:27 +05:30
|
|
|
# pylint: disable-msg=W0612
|
2009-09-26 01:20:38 +05:30
|
|
|
menu = gtk.Menu()
|
|
|
|
#select the stylesheets to show
|
|
|
|
self.stylesheetdata = {}
|
|
|
|
stylelist = []
|
|
|
|
for style in CSS_FILES:
|
|
|
|
stylelist.append([style[0], style[1]])
|
|
|
|
for i, stylesheet in zip(range(len(stylelist)), stylelist):
|
2009-10-02 23:43:44 +05:30
|
|
|
key = ""
|
|
|
|
for word in stylesheet[0].split(' '):
|
|
|
|
key += word.capitalize()
|
|
|
|
key = key.replace(' ','')
|
2009-09-26 01:20:38 +05:30
|
|
|
add_menuitem(menu, stylesheet[0], stylesheet[1] ,
|
2009-10-23 01:22:27 +05:30
|
|
|
_make_callback(self._set_mapstylesheet,
|
2009-10-01 03:11:50 +05:30
|
|
|
stylesheet[1]))
|
2009-10-06 02:00:26 +05:30
|
|
|
self.stylesheetdata[key] = [stylesheet[0], stylesheet[1]]
|
2009-09-26 01:20:38 +05:30
|
|
|
return menu
|
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _mapstyle_label(self):
|
2009-09-26 01:20:38 +05:30
|
|
|
"""
|
|
|
|
return the current label for the menutoolbutton
|
|
|
|
"""
|
|
|
|
return self.stylesheet
|
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _set_mapstylesheet(self, obj):
|
2009-09-26 01:20:38 +05:30
|
|
|
"""
|
|
|
|
Set the style of the map view
|
|
|
|
"""
|
|
|
|
self.stylesheet = obj
|
2009-10-23 01:22:27 +05:30
|
|
|
self._set_mapstylelabel(obj)
|
2009-10-02 23:43:44 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _set_mapstylelabel(self, obj):
|
2009-10-02 23:43:44 +05:30
|
|
|
"""
|
|
|
|
Set the style label in the selection button.
|
|
|
|
"""
|
|
|
|
for stylesheet in self.stylesheetdata.keys():
|
|
|
|
if obj == self.stylesheetdata[stylesheet][1]:
|
|
|
|
self.stylesheetlbl.set_text(self.stylesheetdata[stylesheet][0])
|
2009-09-26 01:20:38 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _gotostyle(self, obj): # pylint: disable-msg=W0613
|
2009-09-26 01:20:38 +05:30
|
|
|
"""
|
|
|
|
Change the style of the map view
|
|
|
|
"""
|
2010-01-11 00:49:33 +05:30
|
|
|
if not self.uistate.get_active('Person'):
|
2009-10-23 01:22:27 +05:30
|
|
|
return
|
2010-01-20 01:04:47 +05:30
|
|
|
self.filter_toggle(None, None, None, None)
|
2009-09-26 01:20:38 +05:30
|
|
|
self._geo_places()
|
2008-12-10 04:20:21 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _goto_active_person(self, handle=None): # pylint: disable-msg=W0613
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
Here when the GeoView page is loaded
|
|
|
|
"""
|
2010-01-11 00:49:33 +05:30
|
|
|
if not self.uistate.get_active('Person'):
|
2009-10-23 01:22:27 +05:30
|
|
|
return
|
2010-01-20 01:04:47 +05:30
|
|
|
self.filter_toggle(None, None, None, None)
|
2009-09-08 02:43:38 +05:30
|
|
|
self._geo_places()
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _all_places(self, hanle=None): # pylint: disable-msg=W0613
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
Specifies the place for the home person to display with mapstraction.
|
|
|
|
"""
|
|
|
|
self.displaytype = "places"
|
2010-01-20 01:04:47 +05:30
|
|
|
self.build_filters_container(self.filter, PlaceSidebarFilter)
|
2009-09-08 02:43:38 +05:30
|
|
|
self._geo_places()
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _person_places(self, handle=None): # pylint: disable-msg=W0613
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
Specifies the person places.
|
|
|
|
"""
|
|
|
|
self.displaytype = "person"
|
2010-01-20 01:04:47 +05:30
|
|
|
self.no_filter()
|
2010-01-11 00:49:33 +05:30
|
|
|
if not self.uistate.get_active('Person'):
|
2009-10-23 01:22:27 +05:30
|
|
|
return
|
2009-09-08 02:43:38 +05:30
|
|
|
self._geo_places()
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _family_places(self, hanle=None): # pylint: disable-msg=W0613
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
Specifies the family places to display with mapstraction.
|
|
|
|
"""
|
|
|
|
self.displaytype = "family"
|
2010-01-20 01:04:47 +05:30
|
|
|
self.no_filter()
|
2010-01-11 00:49:33 +05:30
|
|
|
if not self.uistate.get_active('Person'):
|
2009-10-23 01:22:27 +05:30
|
|
|
return
|
2009-09-08 02:43:38 +05:30
|
|
|
self._geo_places()
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _event_places(self, hanle=None): # pylint: disable-msg=W0613
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
Specifies all event places to display with mapstraction.
|
|
|
|
"""
|
|
|
|
self.displaytype = "event"
|
2010-01-20 01:04:47 +05:30
|
|
|
self.build_filters_container(self.filter, EventSidebarFilter)
|
2009-09-08 02:43:38 +05:30
|
|
|
self._geo_places()
|
|
|
|
|
2009-12-23 12:36:44 +05:30
|
|
|
def _new_database(self, db):
|
2009-09-08 02:43:38 +05:30
|
|
|
"""
|
|
|
|
We just change the database.
|
|
|
|
Restore the initial config. Is it good ?
|
|
|
|
"""
|
2009-10-08 06:42:51 +05:30
|
|
|
if config.get('geoview.lock'):
|
|
|
|
self.realzoom = config.get('geoview.zoom')
|
|
|
|
self.displaytype = config.get('geoview.map')
|
2009-09-08 02:43:38 +05:30
|
|
|
self.reallatitude, self.reallongitude = conv_lat_lon(
|
2009-10-08 06:42:51 +05:30
|
|
|
config.get('geoview.latitude'),
|
|
|
|
config.get('geoview.longitude'),
|
2009-09-08 02:43:38 +05:30
|
|
|
"D.D8")
|
2009-12-23 12:36:44 +05:30
|
|
|
self._change_db(db)
|
|
|
|
for sig in self.signal_map:
|
|
|
|
self.callman.add_db_signal(sig, self.signal_map[sig])
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-09-08 02:43:38 +05:30
|
|
|
def _geo_places(self):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
Specifies the places to display with mapstraction.
|
|
|
|
"""
|
2009-12-16 05:13:00 +05:30
|
|
|
if not self.endinit:
|
|
|
|
return
|
2009-09-08 02:43:38 +05:30
|
|
|
if self.nbmarkers > 0 :
|
|
|
|
# While the db is not loaded, we have 0 markers.
|
|
|
|
self._savezoomandposition()
|
2009-01-19 04:33:05 +05:30
|
|
|
self.nbmarkers = 0
|
2009-10-28 00:18:43 +05:30
|
|
|
self.nbplaces = 0
|
2009-01-29 05:26:32 +05:30
|
|
|
self.without = 0
|
2010-01-20 01:04:47 +05:30
|
|
|
self.javascript_ready = False
|
2009-09-08 02:43:38 +05:30
|
|
|
self._createmapstraction(self.displaytype)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-12-23 15:38:16 +05:30
|
|
|
def _set_lock_unlock(self, state):
|
|
|
|
"""
|
|
|
|
Change the lock/unlock state.
|
|
|
|
"""
|
|
|
|
actionstyles = self.lock_action.get_action('SaveZoom')
|
|
|
|
widgets = actionstyles.get_proxies()
|
|
|
|
for widget in widgets :
|
|
|
|
if isinstance(widget, gtk.ToggleToolButton):
|
|
|
|
widget.set_active(state)
|
|
|
|
self._set_lock_unlock_icon()
|
|
|
|
|
2009-09-26 02:37:38 +05:30
|
|
|
def _set_lock_unlock_icon(self):
|
2009-10-01 03:11:50 +05:30
|
|
|
"""
|
|
|
|
Change the lock/unlock icon depending on the button state.
|
|
|
|
"""
|
2009-09-26 02:37:38 +05:30
|
|
|
actionstyles = self.lock_action.get_action('SaveZoom')
|
|
|
|
widgets = actionstyles.get_proxies()
|
|
|
|
for widget in widgets :
|
|
|
|
if isinstance(widget, gtk.ToggleToolButton):
|
|
|
|
if self.lock_action.get_action('SaveZoom').get_active():
|
|
|
|
widget.set_stock_id('gramps-lock')
|
|
|
|
else:
|
|
|
|
widget.set_stock_id('gramps-unlock')
|
|
|
|
|
2009-09-08 02:43:38 +05:30
|
|
|
def _save_zoom(self, button):
|
|
|
|
"""
|
|
|
|
Do we change the zoom between maps ?
|
|
|
|
It's not between maps providers, but between people, family,
|
|
|
|
events or places map.
|
|
|
|
When we unlock, we reload the page with our values.
|
|
|
|
"""
|
|
|
|
if not button.get_active():
|
|
|
|
self._change_map(self.usedmap)
|
2009-09-26 02:37:38 +05:30
|
|
|
self._set_lock_unlock_icon()
|
2009-09-08 02:43:38 +05:30
|
|
|
|
2009-12-24 21:25:01 +05:30
|
|
|
def _change_provider(self, button):
|
|
|
|
"""
|
|
|
|
Toogle between the two maps providers.
|
|
|
|
Inactive ( the default ) is openstreetmap.
|
|
|
|
Active means Google maps.
|
|
|
|
"""
|
|
|
|
if button.get_active():
|
|
|
|
self.usedmap = "google"
|
|
|
|
else:
|
|
|
|
self.usedmap = "openstreetmap"
|
|
|
|
self._change_map(self.usedmap)
|
|
|
|
self._set_provider_icon()
|
|
|
|
self._ask_year_selection(self.last_year)
|
|
|
|
|
|
|
|
def _set_provider_icon(self):
|
|
|
|
"""
|
|
|
|
Change the provider icon depending on the button state.
|
|
|
|
"""
|
|
|
|
actionstyles = self.provider_action.get_action('Provider')
|
|
|
|
widgets = actionstyles.get_proxies()
|
|
|
|
for widget in widgets :
|
|
|
|
if isinstance(widget, gtk.ToggleToolButton):
|
|
|
|
if self.provider_action.get_action('Provider').get_active():
|
|
|
|
widget.set_stock_id('gramps-geo-altmap')
|
|
|
|
else:
|
|
|
|
widget.set_stock_id('gramps-geo-mainmap')
|
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createpageplaceswithoutcoord(self):
|
2009-01-29 05:26:32 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create a page with the list of all places without coordinates
|
2009-01-29 05:26:32 +05:30
|
|
|
page.
|
|
|
|
"""
|
|
|
|
data = """
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" \
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" >
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
|
|
|
<title>%(title)s</title>
|
2009-09-26 01:20:38 +05:30
|
|
|
%(css)s
|
2009-01-29 05:26:32 +05:30
|
|
|
</head>
|
|
|
|
<body >
|
2009-09-08 02:43:38 +05:30
|
|
|
<H4>%(content)s<a href="javascript:history.go(-1)">%(back)s</a></H4>
|
2009-01-29 05:26:32 +05:30
|
|
|
""" % { 'title' : _('List of places without coordinates'),
|
2009-02-04 01:49:05 +05:30
|
|
|
'content': _('Here is the list of all places in the family tree'
|
2009-01-29 05:26:32 +05:30
|
|
|
' for which we have no coordinates.<br>'
|
2009-09-08 02:43:38 +05:30
|
|
|
' This means no longitude or latitude.<p>'),
|
2009-09-26 01:20:38 +05:30
|
|
|
'back' : _('Back to prior page'),
|
|
|
|
'css' : self._add_stylesheet()
|
2009-01-29 05:26:32 +05:30
|
|
|
}
|
|
|
|
end = """
|
|
|
|
</table>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
2009-02-11 04:51:46 +05:30
|
|
|
ufd = open(self.without_coord_file, "w+")
|
|
|
|
ufd.write(data)
|
2009-01-29 05:26:32 +05:30
|
|
|
self.places = sorted(self.place_without_coordinates)
|
|
|
|
i = 1
|
2009-02-11 04:51:46 +05:30
|
|
|
ufd.write("<table border=1 ><th width=10%>NB</th>")
|
|
|
|
ufd.write("<th width=20%>Gramps ID</th><th>Place</th>")
|
2009-01-29 05:26:32 +05:30
|
|
|
for place in self.places:
|
2009-09-08 02:43:38 +05:30
|
|
|
ufd.write("<tr><td>%d</td><td>%s</td><td>%s</td></tr>\n"
|
2009-02-11 04:51:46 +05:30
|
|
|
% ( i, place[0], place[1] ))
|
2009-01-29 05:26:32 +05:30
|
|
|
i += 1
|
2009-02-11 04:51:46 +05:30
|
|
|
ufd.write(end)
|
|
|
|
ufd.close()
|
2009-01-29 05:26:32 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _create_pages_without(self):
|
|
|
|
"""
|
|
|
|
Show or hide the page without coord button.
|
|
|
|
"""
|
|
|
|
if self.without > 0:
|
|
|
|
self._createpageplaceswithoutcoord()
|
|
|
|
self.nocoord.set_label("%d ?" % ( self.without) )
|
|
|
|
self.nocoord.show()
|
|
|
|
else:
|
|
|
|
self.nocoord.hide()
|
|
|
|
|
|
|
|
def _create_pages_selection(self, current, pages):
|
|
|
|
"""
|
|
|
|
Set the label text in the pages selection button
|
|
|
|
"""
|
|
|
|
self.pages[1].set_label("%d/%d" % ( current, pages ) )
|
|
|
|
|
|
|
|
def _createmapstractionpostheader(self, h4mess, curpage):
|
2009-10-30 14:11:21 +05:30
|
|
|
# disable msg=W0613 # curpage is unused
|
|
|
|
# pylint: disable-msg=W0613
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
This is needed to add infos to the header.
|
|
|
|
This can't be in createmapstractionheader because we need
|
|
|
|
to know something which is known only after some work.
|
|
|
|
"""
|
2008-12-08 16:34:54 +05:30
|
|
|
if self.maxyear == 0:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.maxyear = 2100
|
2008-12-08 16:34:54 +05:30
|
|
|
if self.minyear == 9999:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.minyear = 1500
|
2009-12-23 01:07:21 +05:30
|
|
|
adjust_before_min_year = config.get('behavior.date-before-range')
|
|
|
|
adjust_after_max_year = config.get('behavior.date-after-range')
|
|
|
|
self.minyear -= ( self.minyear - adjust_before_min_year ) % 10
|
|
|
|
self.maxyear -= ( self.maxyear + adjust_after_max_year ) % 10
|
|
|
|
self.yearint = adjust_after_max_year + \
|
|
|
|
( self.maxyear - self.minyear ) / \
|
|
|
|
( self.maxbut - 1 )
|
|
|
|
self.yearint -= self.yearint % 10
|
2008-12-08 16:34:54 +05:30
|
|
|
if self.yearint == 0:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.yearint = 10
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write("<script>\n")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" var step = %s;\n" % self.yearint)
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write("</script>\n")
|
|
|
|
self.mapview.write("</head>\n")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("<body>\n")
|
|
|
|
self.years.hide()
|
|
|
|
if h4mess:
|
|
|
|
self.mapview.write("<h4>%s</h4>\n" % h4mess)
|
|
|
|
else:
|
|
|
|
if self.displaytype != "places":
|
|
|
|
self._set_years_selection(self.minyear,
|
|
|
|
self.yearint,
|
2009-12-23 01:07:21 +05:30
|
|
|
self.maxyear)
|
|
|
|
#self.maxyear + adjust_after_max_year)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.years.show()
|
|
|
|
self.mapview.write("<div id=\"GOverviewMapControl_Helper\"")
|
|
|
|
self.mapview.write(" style=\"height: %dpx; " %
|
|
|
|
(self.height - self.header_size ))
|
|
|
|
self.mapview.write(" width: %dpx; display:none;\"\n" % self.width)
|
|
|
|
self.mapview.write(" comment=\"just a work around a GOverview"
|
|
|
|
"MapControl() behaviour:\n")
|
|
|
|
self.mapview.write(" some time the first non-class object will "
|
|
|
|
"be used to find the width\n")
|
|
|
|
self.mapview.write(" because GOverviewMapControl() wants to be "
|
|
|
|
"most rigth the map jumps\n")
|
|
|
|
self.mapview.write(" to the left (outside)\"")
|
|
|
|
self.mapview.write("></div>\n")
|
|
|
|
self.mapview.write("<div id='geo-map' class='Mapstraction' style=\"")
|
2009-01-19 04:33:05 +05:30
|
|
|
if h4mess:
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("display: none; ")
|
|
|
|
self.mapview.write("height: %dpx\"></div>\n" %
|
|
|
|
(self.height - self.header_size ))
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write("<script type=\"text/javascript\">\n")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" args=getArgs();")
|
|
|
|
self.mapview.write(" if (args.map) current_map=args.map;")
|
|
|
|
self.mapview.write(" if (args.lat) ulat=args.lat;")
|
|
|
|
self.mapview.write(" if (args.lon) ulon=args.lon;")
|
|
|
|
self.mapview.write(" if (args.zoom) uzoom=parseInt(args.zoom);")
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write(" mapstraction = new Mapstraction")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("('geo-map',args.map);\n")
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write(" mapstraction.addControls(")
|
|
|
|
self.mapview.write("{ pan: true, zoom: 'large', ")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("scale: true, map_type: true });\n")
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _create_needed_javascript(self):
|
|
|
|
"""
|
|
|
|
Create the needed javascript functions.
|
|
|
|
"""
|
2009-10-24 02:13:18 +05:30
|
|
|
self.mapview.write(_JAVASCRIPT)
|
|
|
|
# _JAVASCRIPT.format(
|
|
|
|
# )
|
|
|
|
# )
|
2009-09-16 21:42:40 +05:30
|
|
|
return
|
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstractionheader(self, filename):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
Create the html header of the page.
|
|
|
|
"""
|
2009-10-30 14:11:21 +05:30
|
|
|
# disable msg=W0612 # modifier is unused
|
2009-10-23 01:22:27 +05:30
|
|
|
# pylint: disable-msg=W0612
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview = open(filename, "w+")
|
2009-09-08 02:43:38 +05:30
|
|
|
(lang_country, modifier ) = locale.getlocale()
|
2009-10-06 02:00:26 +05:30
|
|
|
if lang_country == None:
|
|
|
|
lang = "en"
|
|
|
|
else:
|
|
|
|
lang = lang_country.split('_')[0]
|
2009-09-20 15:26:34 +05:30
|
|
|
self.mapview.write(
|
2009-10-24 02:13:18 +05:30
|
|
|
_HTMLHEADER % {
|
|
|
|
"xmllang" : "xml:lang=\"%s\"" % lang,
|
|
|
|
"css": self._add_stylesheet()
|
|
|
|
}
|
2009-09-20 15:26:34 +05:30
|
|
|
)
|
2009-10-23 01:22:27 +05:30
|
|
|
fpath = os.path.join(const.ROOT_DIR, 'mapstraction',
|
|
|
|
#'mxn.js?(openlayers,google)')
|
|
|
|
'mapstraction.js')
|
2009-09-08 02:43:38 +05:30
|
|
|
upath = urlparse.urlunsplit(('file', '',
|
|
|
|
URL_SEP.join(fpath.split(os.sep)),
|
|
|
|
'', ''))
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" src=\"%s\"></script>\n" % upath)
|
2009-09-23 12:19:59 +05:30
|
|
|
self.mapview.write("<script type=\"text/javascript\"")
|
2009-09-24 01:50:57 +05:30
|
|
|
self.mapview.write(" src=\"http://maps.google.com/")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("maps?file=api&v=2&hl=%s\"></script>\n" % lang )
|
2009-08-14 03:29:59 +05:30
|
|
|
|
|
|
|
def _createmapstractiontrailer(self):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Add the last directives for the html page.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-09-16 21:42:40 +05:30
|
|
|
|
2009-10-24 02:13:18 +05:30
|
|
|
self.mapview.write(_HTMLTRAILER)
|
|
|
|
# _HTMLTRAILER.format(
|
|
|
|
# )
|
|
|
|
# )
|
2008-12-12 17:43:22 +05:30
|
|
|
self.mapview.close()
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _set_center_and_zoom(self, ptype):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-14 03:29:59 +05:30
|
|
|
Calculate the zoom.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-01-19 04:33:05 +05:30
|
|
|
# Select the center of the map and the zoom
|
2009-01-24 19:22:53 +05:30
|
|
|
self.centered = False
|
2009-02-11 04:51:46 +05:30
|
|
|
if ptype == 2:
|
2009-09-23 12:19:59 +05:30
|
|
|
# Sort by places and year for events
|
|
|
|
self.sort = sorted(self.place_list,
|
|
|
|
key=operator.itemgetter(3, 4, 7)
|
|
|
|
)
|
2009-01-19 04:33:05 +05:30
|
|
|
else:
|
2009-09-23 12:19:59 +05:30
|
|
|
# Sort by date in all other cases
|
|
|
|
self.sort = sorted(self.place_list,
|
|
|
|
key=operator.itemgetter(7)
|
|
|
|
)
|
2009-09-08 02:43:38 +05:30
|
|
|
signminlon = _get_sign(self.minlon)
|
|
|
|
signminlat = _get_sign(self.minlat)
|
|
|
|
signmaxlon = _get_sign(self.maxlon)
|
|
|
|
signmaxlat = _get_sign(self.maxlat)
|
2008-12-08 16:34:54 +05:30
|
|
|
if signminlon == signmaxlon:
|
2009-02-11 04:51:46 +05:30
|
|
|
maxlong = abs(abs(self.minlon)-abs(self.maxlon))
|
2008-12-08 16:34:54 +05:30
|
|
|
else:
|
2009-02-11 04:51:46 +05:30
|
|
|
maxlong = abs(abs(self.minlon)+abs(self.maxlon))
|
2008-12-08 16:34:54 +05:30
|
|
|
if signminlat == signmaxlat:
|
2009-02-11 04:51:46 +05:30
|
|
|
maxlat = abs(abs(self.minlat)-abs(self.maxlat))
|
2008-12-08 16:34:54 +05:30
|
|
|
else:
|
2009-02-11 04:51:46 +05:30
|
|
|
maxlat = abs(abs(self.minlat)+abs(self.maxlat))
|
2009-01-19 04:33:05 +05:30
|
|
|
# Calculate the zoom. all places must be displayed on the map.
|
2009-09-08 02:43:38 +05:30
|
|
|
zoomlat = _get_zoom_lat(maxlat)
|
|
|
|
zoomlong = _get_zoom_long(maxlong)
|
2009-09-16 21:42:40 +05:30
|
|
|
self.zoom = zoomlat if zoomlat < zoomlong else zoomlong
|
2008-12-23 23:58:33 +05:30
|
|
|
self.zoom -= 1
|
2009-01-31 17:02:50 +05:30
|
|
|
if self.zoom < 2:
|
|
|
|
self.zoom = 2
|
2009-01-19 04:33:05 +05:30
|
|
|
# We center the map on a point at the center of all markers
|
|
|
|
self.centerlat = maxlat/2
|
|
|
|
self.centerlon = maxlong/2
|
2009-09-16 21:42:40 +05:30
|
|
|
latit = longt = 0.0
|
2009-01-19 04:33:05 +05:30
|
|
|
for mark in self.sort:
|
2009-01-24 19:22:53 +05:30
|
|
|
cent = int(mark[6])
|
|
|
|
if cent:
|
|
|
|
self.centered = True
|
2009-01-29 05:26:32 +05:30
|
|
|
if ( signminlat == signmaxlat ):
|
2009-01-31 17:02:50 +05:30
|
|
|
if signminlat == 1:
|
|
|
|
latit = self.minlat+self.centerlat
|
2009-01-29 05:26:32 +05:30
|
|
|
else:
|
2009-01-31 17:02:50 +05:30
|
|
|
latit = self.maxlat-self.centerlat
|
2009-01-29 05:26:32 +05:30
|
|
|
elif self.maxlat > self.centerlat:
|
2009-01-19 04:33:05 +05:30
|
|
|
latit = self.maxlat-self.centerlat
|
|
|
|
else:
|
2009-01-31 17:02:50 +05:30
|
|
|
latit = self.minlat+self.centerlat
|
2009-01-29 05:26:32 +05:30
|
|
|
if ( signminlon == signmaxlon ):
|
2009-01-31 17:02:50 +05:30
|
|
|
if signminlon == 1:
|
|
|
|
longt = self.minlon+self.centerlon
|
2009-01-29 05:26:32 +05:30
|
|
|
else:
|
2009-01-31 17:02:50 +05:30
|
|
|
longt = self.maxlon-self.centerlon
|
2009-01-29 05:26:32 +05:30
|
|
|
elif self.maxlon > self.centerlon:
|
2009-01-19 04:33:05 +05:30
|
|
|
longt = self.maxlon-self.centerlon
|
|
|
|
else:
|
2009-01-31 17:02:50 +05:30
|
|
|
longt = self.minlon+self.centerlon
|
2009-02-11 04:51:46 +05:30
|
|
|
# all maps: 0.0 for longitude and latitude means no location.
|
2009-09-16 21:42:40 +05:30
|
|
|
if latit == longt == 0.0:
|
|
|
|
latit = longt = 0.00000001
|
2009-01-27 04:00:13 +05:30
|
|
|
self.mustcenter = False
|
2009-09-16 21:42:40 +05:30
|
|
|
if not (latit == longt == 0.0):
|
2009-01-27 04:00:13 +05:30
|
|
|
self.latit = latit
|
|
|
|
self.longt = longt
|
|
|
|
self.mustcenter = True
|
2009-08-14 03:29:59 +05:30
|
|
|
|
|
|
|
def _create_pages(self, ptype, h3mess, h4mess):
|
|
|
|
"""
|
|
|
|
Do we need to create a multi-pages document ?
|
|
|
|
Do we have too many markers ?
|
|
|
|
"""
|
2009-10-30 14:11:21 +05:30
|
|
|
# disable msg=W0612 # page is unused
|
2009-10-23 01:22:27 +05:30
|
|
|
# pylint: disable-msg=W0612
|
2009-08-14 03:29:59 +05:30
|
|
|
self.nbpages = 0
|
2009-10-30 14:11:21 +05:30
|
|
|
self.last_page = 1
|
2009-10-24 02:47:20 +05:30
|
|
|
self.box1.set_sensitive(True)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.pages_selection.hide()
|
2009-10-30 14:11:21 +05:30
|
|
|
self.placebox.child.set_text("")
|
|
|
|
self.placebox.freeze_child_notify()
|
|
|
|
self.placebox.set_model(None)
|
2009-10-23 01:22:27 +05:30
|
|
|
self.plist.clear()
|
2009-12-24 17:48:18 +05:30
|
|
|
self.clear.set_label("%s (%d)" % ( _("Places list"), self.nbplaces ))
|
2009-11-02 03:40:54 +05:30
|
|
|
pages = ( self.nbplaces / NB_MARKERS_PER_PAGE )
|
|
|
|
if (self.nbplaces % NB_MARKERS_PER_PAGE ) != 0:
|
|
|
|
pages += 1
|
|
|
|
if self.nbplaces == 0:
|
2009-08-14 03:29:59 +05:30
|
|
|
try:
|
|
|
|
self._createmapstractiontrailer()
|
2009-10-30 14:11:21 +05:30
|
|
|
except: # pylint: disable-msg=W0704
|
|
|
|
pass # pylint: disable-msg=W0702
|
2009-08-14 03:29:59 +05:30
|
|
|
self._set_center_and_zoom(ptype)
|
2009-10-23 01:22:27 +05:30
|
|
|
self._create_pages_without()
|
|
|
|
if pages > 1:
|
|
|
|
self._create_pages_selection(1, pages)
|
|
|
|
self.pages_selection.show()
|
2009-10-28 00:18:43 +05:30
|
|
|
self.last_index = 0
|
2009-02-11 04:51:46 +05:30
|
|
|
for page in range(0, pages, 1):
|
2009-01-19 04:33:05 +05:30
|
|
|
self.nbpages += 1
|
2009-09-16 21:42:40 +05:30
|
|
|
ftype = {1:'P', 2:'E', 3:'F', 4:'I'}.get(ptype, 'X')
|
2009-09-08 02:43:38 +05:30
|
|
|
filename = os.path.join(GEOVIEW_SUBPATH,
|
|
|
|
"GeoV-%c-%05d.html" %
|
|
|
|
(ftype, self.nbpages))
|
2009-01-19 04:33:05 +05:30
|
|
|
if self.nbpages == 1:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.htmlfile = filename
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractionheader(filename)
|
|
|
|
self._create_needed_javascript()
|
2009-01-19 04:33:05 +05:30
|
|
|
first = ( self.nbpages - 1 ) * NB_MARKERS_PER_PAGE
|
|
|
|
last = ( self.nbpages * NB_MARKERS_PER_PAGE ) - 1
|
2009-08-14 03:29:59 +05:30
|
|
|
self._create_markers(ptype, first, last)
|
2009-10-23 01:22:27 +05:30
|
|
|
self._show_title(h3mess)
|
|
|
|
self._createmapstractionpostheader(h4mess, self.nbpages)
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractiontrailer()
|
2009-01-19 04:33:05 +05:30
|
|
|
if self.nbpages == 1:
|
2009-12-16 05:13:00 +05:30
|
|
|
self._do_we_need_to_zoom_between_map()
|
|
|
|
url = urlparse.urlunsplit( ('file', '',
|
|
|
|
URL_SEP.join(self.htmlfile.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
url += '?map=%s' % self.usedmap
|
|
|
|
url += '&zoom=%d' % int(self.realzoom)
|
|
|
|
url += '&lat=%s' % str(self.reallatitude)
|
|
|
|
url += '&lon=%s' % str(self.reallongitude)
|
|
|
|
self._openurl(url)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.placebox.set_model(self.plist)
|
|
|
|
self.placebox.thaw_child_notify()
|
2009-01-19 04:33:05 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstraction(self, displaytype):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
|
|
|
Which kind of map are we going to create ?
|
|
|
|
"""
|
2010-01-08 03:32:38 +05:30
|
|
|
self.cal = config.get('preferences.calendar-format-report')
|
2009-01-19 04:33:05 +05:30
|
|
|
if displaytype == "places":
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractionplaces(self.dbstate)
|
2009-01-19 04:33:05 +05:30
|
|
|
elif displaytype == "family":
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractionfamily(self.dbstate)
|
2009-01-19 04:33:05 +05:30
|
|
|
elif displaytype == "person":
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractionperson(self.dbstate)
|
2009-01-19 04:33:05 +05:30
|
|
|
elif displaytype == "event":
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapstractionevents(self.dbstate)
|
2009-01-19 04:33:05 +05:30
|
|
|
else:
|
2009-09-08 02:43:38 +05:30
|
|
|
self._createmapstractionheader(os.path.join(GEOVIEW_SUBPATH,
|
|
|
|
"error.html"))
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createmapnotimplemented()
|
|
|
|
self._createmapstractiontrailer()
|
2009-01-19 04:33:05 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _append_to_places_without_coord(self, gid, place):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create a list of places without coordinates.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
if not [gid, place] in self.place_without_coordinates:
|
|
|
|
self.place_without_coordinates.append([gid, place])
|
|
|
|
self.without += 1
|
2009-01-29 05:26:32 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _append_to_places_list(self, place, evttype, name, lat,
|
2009-09-23 12:19:59 +05:30
|
|
|
longit, descr, center, year, icontype):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create a list of places with coordinates.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-10-28 00:18:43 +05:30
|
|
|
found = 0
|
|
|
|
for place_info in self.place_list:
|
|
|
|
if place_info[0] == place:
|
|
|
|
found = 1
|
|
|
|
break
|
|
|
|
if not found:
|
|
|
|
self.nbplaces += 1
|
2009-02-11 04:51:46 +05:30
|
|
|
self.place_list.append([place, name, evttype, lat,
|
2009-09-23 12:19:59 +05:30
|
|
|
longit, descr, int(center), year, icontype])
|
2009-01-19 04:33:05 +05:30
|
|
|
self.nbmarkers += 1
|
2009-02-11 04:51:46 +05:30
|
|
|
tfa = float(lat)
|
|
|
|
tfb = float(longit)
|
2009-01-24 19:22:53 +05:30
|
|
|
if year is not None:
|
2009-02-11 04:51:46 +05:30
|
|
|
tfc = int(year)
|
|
|
|
if tfc != 0:
|
|
|
|
if tfc < self.minyear:
|
|
|
|
self.minyear = tfc
|
|
|
|
if tfc > self.maxyear:
|
|
|
|
self.maxyear = tfc
|
2009-09-16 21:42:40 +05:30
|
|
|
tfa += 0.00000001 if tfa >= 0 else -0.00000001
|
|
|
|
tfb += 0.00000001 if tfb >= 0 else -0.00000001
|
2009-10-30 14:11:21 +05:30
|
|
|
if self.minlat == 0.0 or tfa < self.minlat:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.minlat = tfa
|
2009-10-30 14:11:21 +05:30
|
|
|
if self.maxlat == 0.0 or tfa > self.maxlat:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.maxlat = tfa
|
2009-10-30 14:11:21 +05:30
|
|
|
if self.minlon == 0.0 or tfb < self.minlon:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.minlon = tfb
|
2009-10-30 14:11:21 +05:30
|
|
|
if self.maxlon == 0.0 or tfb > self.maxlon:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.maxlon = tfb
|
2009-01-19 04:33:05 +05:30
|
|
|
|
2009-09-23 12:19:59 +05:30
|
|
|
def _set_icon(self, markertype, differtype, ptype):
|
2009-10-01 03:11:50 +05:30
|
|
|
"""
|
|
|
|
Select the good icon depending on events.
|
|
|
|
If we have different events for one place, we use the default icon.
|
|
|
|
"""
|
2009-09-23 12:19:59 +05:30
|
|
|
if ptype != 1: # for places, we have no event type
|
2009-10-01 03:11:50 +05:30
|
|
|
value = _ICONS.get(markertype.value, 'gramps-geo-default')
|
2009-09-23 12:19:59 +05:30
|
|
|
else:
|
|
|
|
value = 'gramps-geo-default'
|
|
|
|
if differtype: # in case multiple evts
|
|
|
|
value = 'gramps-geo-default' # we use default icon.
|
|
|
|
if ( value == "gramps-geo-default" ):
|
2009-10-01 03:11:50 +05:30
|
|
|
value = value.replace("default","\" + default_icon + \"")
|
2009-09-23 12:19:59 +05:30
|
|
|
ipath = os.path.join(const.ROOT_DIR, 'images/22x22/', '%s.png' % value )
|
|
|
|
upath = urlparse.urlunsplit(('file', '',
|
|
|
|
URL_SEP.join(ipath.split(os.sep)), '', ''))
|
|
|
|
self.mapview.write("my_marker.setIcon(\"%s\",[22,22],[0,22]);" % upath)
|
2009-10-28 00:18:43 +05:30
|
|
|
self.mapview.write("my_marker.setShadowIcon(\"\");")
|
2009-09-23 12:19:59 +05:30
|
|
|
|
2009-10-23 01:22:27 +05:30
|
|
|
def _show_title(self, title):
|
|
|
|
"""
|
|
|
|
Show the current title map in the gtk label above the map.
|
|
|
|
"""
|
|
|
|
self.title.set_text(title)
|
|
|
|
|
2009-09-20 15:26:34 +05:30
|
|
|
def _create_markers(self, formatype, firstm, lastm):
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create all markers for the specified person.
|
2009-02-11 04:51:46 +05:30
|
|
|
"""
|
2009-01-19 04:33:05 +05:30
|
|
|
last = ""
|
2009-09-23 12:19:59 +05:30
|
|
|
current = ""
|
2009-10-01 03:11:50 +05:30
|
|
|
self.placeslist = []
|
2009-10-28 00:18:43 +05:30
|
|
|
indm = 0
|
2009-02-11 04:51:46 +05:30
|
|
|
divclose = True
|
2009-01-19 04:33:05 +05:30
|
|
|
self.yearinmarker = []
|
2009-02-11 04:51:46 +05:30
|
|
|
ininterval = False
|
2009-01-19 04:33:05 +05:30
|
|
|
self.setattr = True
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" function setcenterandzoom(map,uzoom,ulat,ulon){\n")
|
2009-01-19 04:33:05 +05:30
|
|
|
if self.mustcenter:
|
2009-01-24 19:22:53 +05:30
|
|
|
self.centered = True
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" var point = new LatLonPoint")
|
|
|
|
self.mapview.write("(ulat,ulon);")
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write("map.setCenterAndZoom")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("(point, uzoom);\n")
|
2009-01-19 04:33:05 +05:30
|
|
|
self.setattr = False
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write("}\n")
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write(" function setmarkers(map) {\n")
|
|
|
|
self.mapview.write(" if ( args.map != \"openstreetmap\" ) {")
|
2009-09-23 12:19:59 +05:30
|
|
|
self.mapview.write(" default_icon = \"altmap\";")
|
|
|
|
self.mapview.write(" } else { ")
|
|
|
|
self.mapview.write(" default_icon = \"mainmap\"; }\n")
|
|
|
|
differtype = False
|
|
|
|
savetype = None
|
2009-10-28 00:18:43 +05:30
|
|
|
index_mark = 0
|
|
|
|
indm = firstm
|
2009-01-19 04:33:05 +05:30
|
|
|
for mark in self.sort:
|
2009-10-28 00:18:43 +05:30
|
|
|
index_mark += 1
|
|
|
|
if index_mark < self.last_index:
|
|
|
|
continue
|
2009-01-19 04:33:05 +05:30
|
|
|
if ( indm >= firstm ) and ( indm <= lastm ):
|
2009-02-11 04:51:46 +05:30
|
|
|
ininterval = True
|
|
|
|
if ininterval:
|
2009-09-23 12:19:59 +05:30
|
|
|
current = {
|
|
|
|
2 : [mark[3], mark[4]],
|
|
|
|
}.get(formatype, mark[0])
|
|
|
|
if last != current:
|
2009-01-28 00:43:42 +05:30
|
|
|
if not divclose:
|
2009-02-11 04:51:46 +05:30
|
|
|
if ininterval:
|
2009-01-28 00:43:42 +05:30
|
|
|
self.mapview.write("</div>\");")
|
|
|
|
divclose = True
|
|
|
|
years = ""
|
|
|
|
if mark[2]:
|
2009-02-11 04:51:46 +05:30
|
|
|
for year in self.yearinmarker:
|
|
|
|
years += "%d " % year
|
2009-01-28 00:43:42 +05:30
|
|
|
years += "end"
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("my_marker.setAttribute")
|
|
|
|
self.mapview.write("('year','%s');" % years)
|
2009-01-28 00:43:42 +05:30
|
|
|
self.yearinmarker = []
|
2009-09-23 12:19:59 +05:30
|
|
|
self._set_icon(savetype, differtype, formatype)
|
2009-09-24 01:50:57 +05:30
|
|
|
differtype = False
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write("map.addMarker(my_marker);")
|
2009-01-19 04:33:05 +05:30
|
|
|
if ( indm > lastm ):
|
2009-01-28 00:43:42 +05:30
|
|
|
if (indm % NB_MARKERS_PER_PAGE) == 0:
|
2009-10-28 00:18:43 +05:30
|
|
|
self.last_index = index_mark
|
2009-02-11 04:51:46 +05:30
|
|
|
ininterval = False
|
2009-09-23 12:19:59 +05:30
|
|
|
last = {
|
|
|
|
2 : [mark[3], mark[4]],
|
|
|
|
}.get(formatype, mark[0])
|
2009-01-19 04:33:05 +05:30
|
|
|
if ( indm >= firstm ) and ( indm <= lastm ):
|
2009-10-30 14:11:21 +05:30
|
|
|
ind = indm % NB_MARKERS_PER_PAGE
|
2009-10-28 00:18:43 +05:30
|
|
|
self.plist.append([ mark[0], ind, self.nbpages] )
|
|
|
|
indm += 1
|
2009-10-23 01:22:27 +05:30
|
|
|
self.mapview.write("\n var point = new LatLonPoint")
|
2009-10-01 03:11:50 +05:30
|
|
|
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("(%s,%s);" % (mark[3], mark[4]))
|
2009-01-28 00:43:42 +05:30
|
|
|
self.mapview.write("my_marker = new Marker(point);")
|
2009-10-28 00:18:43 +05:30
|
|
|
self.mapview.write("gmarkers[%d]=my_marker;" % ind )
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("my_marker.setLabel")
|
|
|
|
self.mapview.write("(\"%s\");" % mark[0])
|
2009-01-19 04:33:05 +05:30
|
|
|
self.yearinmarker.append(mark[7])
|
2009-02-11 04:51:46 +05:30
|
|
|
divclose = False
|
2009-09-23 12:19:59 +05:30
|
|
|
differtype = False
|
2009-09-24 01:50:57 +05:30
|
|
|
if mark[8] and not differtype:
|
2009-09-23 12:19:59 +05:30
|
|
|
savetype = mark[8]
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("my_marker.setInfoBubble(\"<div ")
|
2009-09-26 01:20:38 +05:30
|
|
|
self.mapview.write("id='geo-info' >")
|
2009-09-23 12:19:59 +05:30
|
|
|
self.mapview.write("%s<br>" % mark[0])
|
2009-09-20 15:26:34 +05:30
|
|
|
if formatype == 1:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("<br>%s" % mark[5])
|
2009-09-20 15:26:34 +05:30
|
|
|
elif formatype == 2:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("<br>%s - %s" % (mark[7],
|
|
|
|
mark[5]))
|
2009-09-20 15:26:34 +05:30
|
|
|
elif formatype == 3:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("<br>%s - %s" % (mark[7],
|
|
|
|
mark[5]))
|
2009-09-20 15:26:34 +05:30
|
|
|
elif formatype == 4:
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("<br>%s - %s" % (mark[7],
|
|
|
|
mark[5]))
|
2009-01-19 04:33:05 +05:30
|
|
|
else: # This marker already exists. add info.
|
2009-09-23 12:19:59 +05:30
|
|
|
if ( mark[8] and savetype != mark[8] ):
|
|
|
|
differtype = True
|
2009-10-28 00:18:43 +05:30
|
|
|
if indm > last:
|
|
|
|
divclose = True
|
|
|
|
else:
|
|
|
|
self.mapview.write("<br>%s - %s" % (mark[7], mark[5]))
|
2009-08-14 03:29:59 +05:30
|
|
|
ret = 1
|
|
|
|
for year in self.yearinmarker:
|
|
|
|
if year == mark[7]:
|
|
|
|
ret = 0
|
|
|
|
if (ret):
|
2009-01-19 04:33:05 +05:30
|
|
|
self.yearinmarker.append(mark[7])
|
|
|
|
else:
|
|
|
|
indm += 1
|
2009-02-11 04:51:46 +05:30
|
|
|
if self.nbmarkers > 0 and ininterval:
|
2009-01-28 00:43:42 +05:30
|
|
|
years = ""
|
|
|
|
if mark[2]:
|
2009-02-11 04:51:46 +05:30
|
|
|
for year in self.yearinmarker:
|
|
|
|
years += "%d " % year
|
2009-01-28 00:43:42 +05:30
|
|
|
years += "end"
|
|
|
|
self.mapview.write("</div>\");")
|
|
|
|
self.mapview.write("my_marker.setAttribute('year','%s');" % years)
|
2009-09-23 12:19:59 +05:30
|
|
|
self._set_icon(savetype, differtype, formatype)
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write("map.addMarker(my_marker);")
|
2009-01-28 00:43:42 +05:30
|
|
|
if self.nbmarkers == 0:
|
2009-01-27 04:00:13 +05:30
|
|
|
# We have no valid geographic point to center the map.
|
2009-01-27 13:03:40 +05:30
|
|
|
longitude = 0.0
|
|
|
|
latitude = 0.0
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("\nvar point = new LatLonPoint")
|
|
|
|
self.mapview.write("(%s,%s);\n" % (latitude, longitude))
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write(" map.setCenterAndZoom")
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write("(point, %d);\n" % 2)
|
2009-01-27 04:00:13 +05:30
|
|
|
self.mapview.write(" my_marker = new Marker(point);\n")
|
2009-02-11 04:51:46 +05:30
|
|
|
self.mapview.write(" my_marker.setLabel")
|
|
|
|
self.mapview.write("(\"%s\");\n" % _("No location."))
|
|
|
|
self.mapview.write(" my_marker.setInfoBubble(\"<div ")
|
|
|
|
self.mapview.write("style='white-space:nowrap;' >")
|
2009-02-04 01:49:05 +05:30
|
|
|
self.mapview.write(_("You have no places in your family tree "
|
|
|
|
" with coordinates."))
|
2009-01-27 13:03:40 +05:30
|
|
|
self.mapview.write("<br>")
|
2009-02-04 01:49:05 +05:30
|
|
|
self.mapview.write(_("You are looking at the default map."))
|
2009-01-27 13:03:40 +05:30
|
|
|
self.mapview.write("</div>\");\n")
|
2009-09-23 12:19:59 +05:30
|
|
|
self._set_icon(None, True, 1)
|
2009-10-06 02:00:26 +05:30
|
|
|
self.mapview.write(" map.addMarker(my_marker);")
|
2009-08-14 03:29:59 +05:30
|
|
|
self.mapview.write("\n}")
|
|
|
|
self.mapview.write("\n</script>\n")
|
2009-01-19 04:33:05 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createpersonmarkers(self, dbstate, person, comment):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create all markers for the specified person.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
latitude = ""
|
|
|
|
longitude = ""
|
|
|
|
if person:
|
2009-10-23 01:22:27 +05:30
|
|
|
event_ref = person.get_birth_ref()
|
|
|
|
if event_ref:
|
|
|
|
event = dbstate.db.get_event_from_handle(event_ref.ref)
|
2010-01-08 03:32:38 +05:30
|
|
|
eventyear = event.get_date_object().to_calendar(self.cal).get_year()
|
2009-10-23 01:22:27 +05:30
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = dbstate.db.get_place_from_handle(place_handle)
|
2009-08-10 04:16:55 +05:30
|
|
|
if place:
|
|
|
|
longitude = place.get_longitude()
|
|
|
|
latitude = place.get_latitude()
|
|
|
|
latitude, longitude = conv_lat_lon(latitude,
|
|
|
|
longitude, "D.D8")
|
|
|
|
if comment:
|
|
|
|
descr1 = _("%(comment)s : birth place.") % {
|
|
|
|
'comment': comment}
|
|
|
|
else:
|
|
|
|
descr1 = _("birth place.")
|
|
|
|
descr = place.get_title()
|
|
|
|
# place.get_longitude and place.get_latitude return
|
|
|
|
# one string. We have coordinates when the two values
|
|
|
|
# contains non null string.
|
|
|
|
if ( longitude and latitude ):
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_list(descr,
|
|
|
|
gen.lib.EventType.BIRTH,
|
|
|
|
_nd.display(person),
|
|
|
|
latitude, longitude,
|
|
|
|
descr1,
|
|
|
|
int(self.center),
|
2009-10-23 01:22:27 +05:30
|
|
|
eventyear,
|
|
|
|
event.get_type()
|
2009-09-23 12:19:59 +05:30
|
|
|
)
|
2009-08-10 04:16:55 +05:30
|
|
|
self.center = False
|
|
|
|
else:
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_without_coord(
|
|
|
|
place.gramps_id, descr)
|
2008-12-08 16:34:54 +05:30
|
|
|
latitude = ""
|
|
|
|
longitude = ""
|
2009-10-23 01:22:27 +05:30
|
|
|
event_ref = person.get_death_ref()
|
|
|
|
if event_ref:
|
|
|
|
event = dbstate.db.get_event_from_handle(event_ref.ref)
|
2010-01-08 03:32:38 +05:30
|
|
|
eventyear = event.get_date_object().to_calendar(self.cal).get_year()
|
2009-10-23 01:22:27 +05:30
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = dbstate.db.get_place_from_handle(place_handle)
|
2009-08-10 04:16:55 +05:30
|
|
|
if place:
|
|
|
|
longitude = place.get_longitude()
|
|
|
|
latitude = place.get_latitude()
|
|
|
|
latitude, longitude = conv_lat_lon(latitude,
|
|
|
|
longitude, "D.D8")
|
|
|
|
descr = place.get_title()
|
|
|
|
if comment:
|
|
|
|
descr1 = _("%(comment)s : death place.") % {
|
|
|
|
'comment': comment}
|
|
|
|
else:
|
|
|
|
descr1 = _("death place.")
|
|
|
|
# place.get_longitude and place.get_latitude return
|
|
|
|
# one string. We have coordinates when the two values
|
|
|
|
# contains non null string.
|
|
|
|
if ( longitude and latitude ):
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_list(descr,
|
|
|
|
gen.lib.EventType.DEATH,
|
|
|
|
_nd.display(person),
|
|
|
|
latitude, longitude,
|
|
|
|
descr1,
|
|
|
|
int(self.center),
|
2009-10-23 01:22:27 +05:30
|
|
|
eventyear,
|
|
|
|
event.get_type()
|
2009-09-23 12:19:59 +05:30
|
|
|
)
|
2009-08-10 04:16:55 +05:30
|
|
|
self.center = False
|
|
|
|
else:
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_without_coord(
|
|
|
|
place.gramps_id, descr)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstractionplaces(self, dbstate):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create the marker for each place in the database which has a lat/lon.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
self.place_list = []
|
2009-01-29 05:26:32 +05:30
|
|
|
self.place_without_coordinates = []
|
2009-09-16 21:42:40 +05:30
|
|
|
self.minlat = 0.0
|
|
|
|
self.maxlat = 0.0
|
|
|
|
self.minlon = 0.0
|
|
|
|
self.maxlon = 0.0
|
|
|
|
self.minyear = 9999
|
|
|
|
self.maxyear = 0
|
2008-12-08 16:34:54 +05:30
|
|
|
latitude = ""
|
|
|
|
longitude = ""
|
2009-01-24 19:22:53 +05:30
|
|
|
self.center = True
|
2009-09-16 01:07:23 +05:30
|
|
|
|
2010-01-20 01:04:47 +05:30
|
|
|
if self.generic_filter == None or not config.get('interface.filter'):
|
|
|
|
places_handle = dbstate.db.iter_place_handles()
|
|
|
|
else:
|
|
|
|
places_handle = self.generic_filter.apply(dbstate.db, dbstate.db.iter_place_handles())
|
|
|
|
for place_hdl in places_handle:
|
|
|
|
place = dbstate.db.get_place_from_handle(place_hdl)
|
2009-09-20 15:26:34 +05:30
|
|
|
descr = place.get_title()
|
|
|
|
descr1 = _("Id : %s") % place.gramps_id
|
|
|
|
longitude = place.get_longitude()
|
|
|
|
latitude = place.get_latitude()
|
|
|
|
latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")
|
|
|
|
# place.get_longitude and place.get_latitude return
|
|
|
|
# one string. We have coordinates when the two values
|
|
|
|
# contains non null string.
|
|
|
|
if ( longitude and latitude ):
|
|
|
|
self._append_to_places_list(descr, None, "",
|
|
|
|
latitude, longitude,
|
2009-09-23 12:19:59 +05:30
|
|
|
descr1, self.center, None,
|
|
|
|
gen.lib.EventType.UNKNOWN)
|
2009-09-20 15:26:34 +05:30
|
|
|
self.center = False
|
|
|
|
else:
|
|
|
|
self._append_to_places_without_coord(place.gramps_id, descr)
|
2009-10-30 14:11:21 +05:30
|
|
|
self.yearsbox.hide()
|
2009-10-23 01:22:27 +05:30
|
|
|
self._need_to_create_pages(1, self.center,
|
|
|
|
_("All places in the family tree with "
|
|
|
|
"coordinates."),
|
|
|
|
)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstractionevents(self, dbstate):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-10-23 01:22:27 +05:30
|
|
|
Create one marker for each place associated with an event in the
|
|
|
|
database which has a lat/lon.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
self.place_list = []
|
2009-01-29 05:26:32 +05:30
|
|
|
self.place_without_coordinates = []
|
2009-10-23 01:22:27 +05:30
|
|
|
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
|
2009-09-16 21:42:40 +05:30
|
|
|
self.minyear = 9999
|
|
|
|
self.maxyear = 0
|
2008-12-08 16:34:54 +05:30
|
|
|
latitude = ""
|
|
|
|
longitude = ""
|
2009-01-24 19:22:53 +05:30
|
|
|
self.center = True
|
2009-09-16 01:07:23 +05:30
|
|
|
|
2010-01-20 01:04:47 +05:30
|
|
|
if self.generic_filter == None or not config.get('interface.filter'):
|
|
|
|
events_handle = dbstate.db.iter_event_handles()
|
|
|
|
else:
|
|
|
|
events_handle = self.generic_filter.apply(dbstate.db, dbstate.db.iter_event_handles())
|
|
|
|
for event_hdl in events_handle:
|
|
|
|
event = dbstate.db.get_event_from_handle(event_hdl)
|
2009-09-16 01:07:23 +05:30
|
|
|
place_handle = event.get_place_handle()
|
2010-01-08 03:32:38 +05:30
|
|
|
eventyear = event.get_date_object().to_calendar(self.cal).get_year()
|
2009-09-16 01:07:23 +05:30
|
|
|
if place_handle:
|
|
|
|
place = dbstate.db.get_place_from_handle(place_handle)
|
|
|
|
if place:
|
2009-09-23 12:19:59 +05:30
|
|
|
descr1 = place.get_title()
|
2009-09-16 01:07:23 +05:30
|
|
|
longitude = place.get_longitude()
|
|
|
|
latitude = place.get_latitude()
|
|
|
|
latitude, longitude = conv_lat_lon(latitude, longitude,
|
|
|
|
"D.D8")
|
|
|
|
# place.get_longitude and place.get_latitude return
|
|
|
|
# one string. We have coordinates when the two values
|
|
|
|
# contains non null string.
|
|
|
|
if ( longitude and latitude ):
|
|
|
|
person_list = [
|
|
|
|
dbstate.db.get_person_from_handle(ref_handle)
|
|
|
|
for (ref_type, ref_handle) in
|
|
|
|
dbstate.db.find_backlink_handles(event.handle)
|
|
|
|
if ref_type == 'Person'
|
|
|
|
]
|
2009-09-24 23:11:33 +05:30
|
|
|
descr2 = event.get_type()
|
2009-09-16 01:07:23 +05:30
|
|
|
if person_list:
|
|
|
|
for person in person_list:
|
2009-09-24 02:50:58 +05:30
|
|
|
descr2 = ("%(description)s - %(name)s") % {
|
2009-09-23 12:19:59 +05:30
|
|
|
'description' : descr2,
|
2009-09-16 01:07:23 +05:30
|
|
|
'name' : _nd.display(person)}
|
|
|
|
descr = ("%(eventtype)s;"+
|
|
|
|
" %(place)s%(description)s"
|
|
|
|
) % { 'eventtype': gen.lib.EventType(
|
|
|
|
event.get_type()
|
|
|
|
),
|
|
|
|
'place': place.get_title(),
|
2009-09-23 12:19:59 +05:30
|
|
|
'description': descr2}
|
2009-01-05 05:12:20 +05:30
|
|
|
else:
|
2009-09-16 01:07:23 +05:30
|
|
|
descr = ("%(eventtype)s; %(place)s<br>") % {
|
|
|
|
'eventtype': gen.lib.EventType(
|
|
|
|
event.get_type()
|
|
|
|
),
|
|
|
|
'place': place.get_title()}
|
|
|
|
self._append_to_places_list(descr1, descr,
|
|
|
|
descr,
|
|
|
|
latitude, longitude,
|
|
|
|
descr2, self.center,
|
2009-09-23 12:19:59 +05:30
|
|
|
eventyear,
|
|
|
|
event.get_type()
|
|
|
|
)
|
2009-09-16 01:07:23 +05:30
|
|
|
self.center = False
|
|
|
|
else:
|
|
|
|
descr = place.get_title()
|
|
|
|
self._append_to_places_without_coord(
|
|
|
|
place.gramps_id, descr)
|
2009-10-23 01:22:27 +05:30
|
|
|
self._need_to_create_pages(2, self.center,
|
|
|
|
_("All events in the family tree with "
|
|
|
|
"coordinates."),
|
|
|
|
)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstractionfamily(self, dbstate):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create all markers for each people of a family
|
2008-12-08 16:34:54 +05:30
|
|
|
in the database which has a lat/lon.
|
|
|
|
"""
|
|
|
|
self.place_list = []
|
2009-01-29 05:26:32 +05:30
|
|
|
self.place_without_coordinates = []
|
2009-10-23 01:22:27 +05:30
|
|
|
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
|
2009-09-16 21:42:40 +05:30
|
|
|
self.minyear = 9999
|
|
|
|
self.maxyear = 0
|
2009-01-24 19:22:53 +05:30
|
|
|
self.center = True
|
2010-01-11 00:49:33 +05:30
|
|
|
person_handle = self.uistate.get_active('Person')
|
|
|
|
person = dbstate.db.get_person_from_handle(person_handle)
|
2009-01-28 00:43:42 +05:30
|
|
|
if person is not None:
|
2008-12-08 16:34:54 +05:30
|
|
|
family_list = person.get_family_handle_list()
|
|
|
|
if len(family_list) > 0:
|
|
|
|
fhandle = family_list[0] # first is primary
|
2009-02-11 04:51:46 +05:30
|
|
|
fam = dbstate.db.get_family_from_handle(fhandle)
|
2009-08-14 03:29:59 +05:30
|
|
|
handle = fam.get_father_handle()
|
|
|
|
father = dbstate.db.get_person_from_handle(handle)
|
2008-12-08 16:34:54 +05:30
|
|
|
if father:
|
2009-09-23 12:19:59 +05:30
|
|
|
comment = _("Id : Father : %s : %s") % ( father.gramps_id,
|
|
|
|
_nd.display(father)
|
|
|
|
)
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createpersonmarkers(dbstate, father, comment)
|
|
|
|
handle = fam.get_mother_handle()
|
|
|
|
mother = dbstate.db.get_person_from_handle(handle)
|
2008-12-08 16:34:54 +05:30
|
|
|
if mother:
|
2009-09-23 12:19:59 +05:30
|
|
|
comment = _("Id : Mother : %s : %s") % ( mother.gramps_id,
|
|
|
|
_nd.display(mother)
|
|
|
|
)
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createpersonmarkers(dbstate, mother, comment)
|
2008-12-08 16:34:54 +05:30
|
|
|
index = 0
|
|
|
|
child_ref_list = fam.get_child_ref_list()
|
|
|
|
if child_ref_list:
|
|
|
|
for child_ref in child_ref_list:
|
2009-02-11 04:51:46 +05:30
|
|
|
child = dbstate.db.get_person_from_handle(child_ref.ref)
|
2008-12-08 16:34:54 +05:30
|
|
|
if child:
|
|
|
|
index += 1
|
2009-09-23 12:19:59 +05:30
|
|
|
comment = _("Id : Child : %(id)s - %(index)d "
|
|
|
|
": %(name)s") % {
|
|
|
|
'id' : child.gramps_id,
|
|
|
|
'index' : index,
|
|
|
|
'name' : _nd.display(child)
|
|
|
|
}
|
2009-08-14 03:29:59 +05:30
|
|
|
self._createpersonmarkers(dbstate, child, comment)
|
2009-09-08 02:43:38 +05:30
|
|
|
else:
|
2009-11-02 03:40:54 +05:30
|
|
|
comment = _("Id : Person : %(id)s %(name)s has no family.") % {
|
|
|
|
'id' : person.gramps_id ,
|
|
|
|
'name' : _nd.display(person)
|
|
|
|
}
|
2009-09-08 02:43:38 +05:30
|
|
|
self._createpersonmarkers(dbstate, person, comment)
|
2009-12-18 13:06:20 +05:30
|
|
|
self._need_to_create_pages(3, self.center,
|
|
|
|
_("All %(name)s people's family places in the"
|
|
|
|
" family tree with coordinates.") % {
|
|
|
|
'name' :_nd.display(person) },
|
|
|
|
)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapstractionperson(self, dbstate):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Create all markers for each people's event in the database which has
|
|
|
|
a lat/lon.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
|
|
|
self.place_list = []
|
2009-01-29 05:26:32 +05:30
|
|
|
self.place_without_coordinates = []
|
2009-10-23 01:22:27 +05:30
|
|
|
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
|
2009-09-16 21:42:40 +05:30
|
|
|
self.minyear = 9999
|
|
|
|
self.maxyear = 0
|
2008-12-08 16:34:54 +05:30
|
|
|
latitude = ""
|
|
|
|
longitude = ""
|
2010-01-11 00:49:33 +05:30
|
|
|
person_handle = self.uistate.get_active('Person')
|
|
|
|
person = dbstate.db.get_person_from_handle(person_handle)
|
2009-01-24 19:22:53 +05:30
|
|
|
self.center = True
|
2009-01-28 00:43:42 +05:30
|
|
|
if person is not None:
|
2008-12-08 16:34:54 +05:30
|
|
|
# For each event, if we have a place, set a marker.
|
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
if not event_ref:
|
|
|
|
continue
|
|
|
|
if event_ref.role != gen.lib.EventRoleType.PRIMARY:
|
|
|
|
# Only match primaries, no witnesses
|
|
|
|
continue
|
2009-02-11 04:51:46 +05:30
|
|
|
event = dbstate.db.get_event_from_handle(event_ref.ref)
|
2010-01-08 03:32:38 +05:30
|
|
|
eventyear = event.get_date_object().to_calendar(self.cal).get_year()
|
2008-12-08 16:34:54 +05:30
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
2009-02-11 04:51:46 +05:30
|
|
|
place = dbstate.db.get_place_from_handle(place_handle)
|
2009-08-10 04:16:55 +05:30
|
|
|
if place:
|
|
|
|
longitude = place.get_longitude()
|
|
|
|
latitude = place.get_latitude()
|
|
|
|
latitude, longitude = conv_lat_lon(latitude,
|
|
|
|
longitude, "D.D8")
|
|
|
|
descr = place.get_title()
|
|
|
|
evt = gen.lib.EventType(event.get_type())
|
|
|
|
descr1 = _("%(eventtype)s : %(name)s") % {
|
|
|
|
'eventtype': evt,
|
|
|
|
'name': _nd.display(person)}
|
|
|
|
# place.get_longitude and place.get_latitude return
|
|
|
|
# one string. We have coordinates when the two values
|
|
|
|
# contains non null string.
|
|
|
|
if ( longitude and latitude ):
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_list(descr, evt,
|
|
|
|
_nd.display(person),
|
|
|
|
latitude, longitude,
|
|
|
|
descr1, self.center,
|
2009-09-23 12:19:59 +05:30
|
|
|
eventyear,
|
|
|
|
event.get_type()
|
|
|
|
)
|
2009-08-10 04:16:55 +05:30
|
|
|
self.center = False
|
|
|
|
else:
|
2009-08-14 03:29:59 +05:30
|
|
|
self._append_to_places_without_coord(
|
|
|
|
place.gramps_id, descr)
|
2009-12-18 13:06:20 +05:30
|
|
|
self._need_to_create_pages(4, self.center,
|
|
|
|
_("All event places for") + (" %s." %
|
2009-10-23 01:22:27 +05:30
|
|
|
_nd.display(person) ) )
|
|
|
|
|
|
|
|
def _need_to_create_pages(self, ptype, center, message ):
|
|
|
|
"""
|
|
|
|
Prepare the header of the page if we have no markers.
|
|
|
|
"""
|
|
|
|
if center:
|
|
|
|
self._create_pages(ptype, "",
|
|
|
|
_("Cannot center the map. No location with coordinates."
|
|
|
|
"The following reasons are : <ul>"
|
|
|
|
"<li>The active person has no places with coordinates.</li>"
|
2009-12-23 12:36:44 +05:30
|
|
|
"<li>The active person's family members have no places "
|
2009-10-23 01:22:27 +05:30
|
|
|
"with coordinates.</li><li>You have no places.</li>"
|
|
|
|
"<li>You have no active person set.</li>"),
|
|
|
|
)
|
2009-10-24 02:47:20 +05:30
|
|
|
self.box1.set_sensitive(False)
|
2009-01-19 04:33:05 +05:30
|
|
|
else:
|
|
|
|
mess = ""
|
2009-10-23 01:22:27 +05:30
|
|
|
self._create_pages(ptype, message, mess)
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-08-14 03:29:59 +05:30
|
|
|
def _createmapnotimplemented(self):
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-08-10 04:16:55 +05:30
|
|
|
Inform the user this work is not implemented.
|
2008-12-08 16:34:54 +05:30
|
|
|
"""
|
2009-02-04 01:49:05 +05:30
|
|
|
self.mapview.write(" <H1>%s </H1>" % _("Not yet implemented ..."))
|
2008-12-08 16:34:54 +05:30
|
|
|
|
2009-09-26 01:20:38 +05:30
|
|
|
def _add_stylesheet(self):
|
|
|
|
"""
|
|
|
|
return all the css styles sheet needed for GeoView.
|
|
|
|
We use two styles sheets :
|
|
|
|
The first one based on the default used by NarrativeWeb.
|
|
|
|
The second one is specific to GeoView.
|
|
|
|
"""
|
2010-02-05 17:43:24 +05:30
|
|
|
return u''
|
2009-09-26 01:20:38 +05:30
|
|
|
# Get the default stylesheet.
|
|
|
|
dblp = "<link media=\"screen\" "
|
|
|
|
delp = "type=\"text/css\" rel=\"stylesheet\" />\n"
|
2009-10-01 03:11:50 +05:30
|
|
|
if self.stylesheet != "":
|
|
|
|
cpath = os.path.join(const.ROOT_DIR,
|
|
|
|
'data',
|
|
|
|
'%s' % self.stylesheet
|
|
|
|
)
|
|
|
|
dpath = urlparse.urlunsplit(('file', '',
|
|
|
|
URL_SEP.join(cpath.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
dcp = "href=\"%s\" " % dpath
|
2009-09-26 01:20:38 +05:30
|
|
|
# Get the GeoView stylesheet.
|
|
|
|
cpath = os.path.join(const.ROOT_DIR,
|
|
|
|
'data',
|
2009-10-01 03:11:50 +05:30
|
|
|
'GeoView.css'
|
2009-09-26 01:20:38 +05:30
|
|
|
)
|
|
|
|
gpath = urlparse.urlunsplit(('file', '',
|
|
|
|
URL_SEP.join(cpath.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
gcp = "href=\"%s\" " % gpath
|
2009-10-01 03:11:50 +05:30
|
|
|
if self.stylesheet != "":
|
2009-10-23 01:22:27 +05:30
|
|
|
return u'%s%s%s %s%s%s' % (dblp, dcp, delp, dblp, gcp, delp)
|
2009-10-01 03:11:50 +05:30
|
|
|
else:
|
|
|
|
return u'%s%s%s' % (dblp, gcp, delp)
|
2009-09-26 01:20:38 +05:30
|
|
|
|
2009-12-16 05:13:00 +05:30
|
|
|
def _openurl(self,url):
|
|
|
|
"""
|
|
|
|
Here, we call really the htmlview and the renderer
|
|
|
|
"""
|
|
|
|
if self.endinit:
|
|
|
|
self.open(url)
|
2010-01-20 01:04:47 +05:30
|
|
|
self.javascript_ready = True
|
2009-12-16 05:13:00 +05:30
|
|
|
|
2009-12-23 02:20:45 +05:30
|
|
|
def _add_place(self,url):
|
|
|
|
"""
|
|
|
|
Add a new place using longitude and latitude of location centred
|
|
|
|
on the map
|
|
|
|
"""
|
|
|
|
new_place = gen.lib.Place()
|
2009-12-24 03:02:01 +05:30
|
|
|
new_place.set_latitude(str(self.reallatitude))
|
|
|
|
new_place.set_longitude(str(self.reallongitude))
|
2009-12-23 02:20:45 +05:30
|
|
|
try:
|
|
|
|
EditPlace(self.dbstate, self.uistate, [], new_place)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2009-12-23 23:50:44 +05:30
|
|
|
|
|
|
|
def _link_place(self,url):
|
|
|
|
"""
|
|
|
|
Link an existing place using longitude and latitude of location centred
|
|
|
|
on the map
|
|
|
|
"""
|
|
|
|
selector = SelectPlace(self.dbstate, self.uistate, [])
|
|
|
|
place = selector.run()
|
|
|
|
if place:
|
2009-12-24 04:32:26 +05:30
|
|
|
place.set_latitude(str(self.reallatitude))
|
|
|
|
place.set_longitude(str(self.reallongitude))
|
2009-12-23 23:50:44 +05:30
|
|
|
try:
|
|
|
|
EditPlace(self.dbstate, self.uistate, [], place)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2010-01-20 01:04:47 +05:30
|
|
|
|
|
|
|
####################################################################
|
|
|
|
# Filters
|
|
|
|
####################################################################
|
|
|
|
def build_filters_container(self, box, filter_class):
|
|
|
|
"""
|
|
|
|
Used to create the filters on Geoview.
|
|
|
|
Depending on the events view or places, view we must generate the
|
|
|
|
good filter.
|
|
|
|
We need to remove the old filter if it exists then add the new one.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.vbox.destroy()
|
|
|
|
except: # pylint: disable-msg=W0704
|
|
|
|
pass # pylint: disable-msg=W0702
|
2010-01-25 23:15:21 +05:30
|
|
|
map(self.hpaned.remove, self.hpaned.get_children())
|
2010-01-20 01:04:47 +05:30
|
|
|
self.vbox = gtk.VBox()
|
|
|
|
self.hpaned.pack_start(self.vbox, True, True)
|
|
|
|
self.filter_sidebar = filter_class(self.dbstate, self.uistate,
|
|
|
|
self.filter_clicked)
|
|
|
|
self.filter_pane = self.filter_sidebar.get_widget()
|
|
|
|
self.hpaned.pack_end(self.filter_pane, False, False)
|
|
|
|
box.show_all()
|
|
|
|
self.filter_toggle(None, None, None, None)
|
|
|
|
|
|
|
|
def no_filter(self):
|
|
|
|
"""
|
|
|
|
We don't need a filter for the current view.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.filter_pane.hide()
|
|
|
|
except: # pylint: disable-msg=W0704
|
|
|
|
pass # pylint: disable-msg=W0702
|
|
|
|
|
|
|
|
def filter_toggle(self, client, cnxn_id, entry, data):
|
|
|
|
"""
|
|
|
|
We must show or hide the filter depending on the filter toggle button.
|
|
|
|
"""
|
|
|
|
if not self.endinit:
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.displaytype == "places" or self.displaytype == "event":
|
|
|
|
if config.get('interface.filter'):
|
2010-02-04 03:13:45 +05:30
|
|
|
self.filter.show()
|
2010-01-20 01:04:47 +05:30
|
|
|
else:
|
2010-02-04 03:13:45 +05:30
|
|
|
self.filter.hide()
|
2010-01-20 01:04:47 +05:30
|
|
|
|
|
|
|
def filter_toggle_action(self, obj):
|
|
|
|
"""
|
|
|
|
Depending on the filter toggle button action, we must show or hile
|
|
|
|
the filter then save the state in the config file.
|
|
|
|
"""
|
|
|
|
if self.displaytype == "places" or self.displaytype == "event":
|
|
|
|
if obj.get_active():
|
2010-02-04 03:13:45 +05:30
|
|
|
self.filter.show()
|
2010-01-20 01:04:47 +05:30
|
|
|
active = True
|
|
|
|
else:
|
2010-02-04 03:13:45 +05:30
|
|
|
self.filter.hide()
|
2010-01-20 01:04:47 +05:30
|
|
|
active = False
|
|
|
|
config.set('interface.filter', active)
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
def filter_clicked(self):
|
|
|
|
"""
|
|
|
|
We have clicked on the Find button into the filter box.
|
|
|
|
"""
|
|
|
|
self.generic_filter = self.filter_sidebar.get_filter()
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
def build_tree(self):
|
|
|
|
"""
|
|
|
|
Builds the new view depending on the filter.
|
|
|
|
"""
|
|
|
|
self._geo_places()
|
2010-02-03 15:56:35 +05:30
|
|
|
|
|
|
|
def _create_start_page(self):
|
|
|
|
"""
|
|
|
|
This command creates a default start page, and returns the URL of
|
|
|
|
this page.
|
|
|
|
"""
|
|
|
|
tmpdir = GEOVIEW_SUBPATH
|
|
|
|
data = """
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" \
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" >
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
|
|
|
<title>%(title)s</title>
|
|
|
|
</head>
|
|
|
|
<body >
|
|
|
|
<H1>%(title)s</H1>
|
|
|
|
<H4>%(content)s</H4>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""" % { 'height' : 600,
|
|
|
|
'title' : _('Start page for the Geography View'),
|
|
|
|
'content': _('You don\'t see a map here for the following '
|
|
|
|
'reasons :<br><ol>'
|
|
|
|
'<li>Your database is empty or not yet selected.</li>'
|
|
|
|
'<li>You don\'t yet select a person.</li>'
|
|
|
|
'<li>You have no place in your database.</li>'
|
|
|
|
'<li>The selected places have no coordinates.</li>'
|
|
|
|
'</ol>')
|
|
|
|
}
|
|
|
|
filename = os.path.join(tmpdir, 'geography.html')
|
|
|
|
# Now we have two views : Web and Geography, we need to create the
|
|
|
|
# startpage only once.
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
ufd = file(filename, "w+")
|
|
|
|
ufd.write(data)
|
|
|
|
ufd.close()
|
|
|
|
return urlparse.urlunsplit(('file', '',
|
|
|
|
URL_SEP.join(filename.split(os.sep)),
|
|
|
|
'', ''))
|
|
|
|
|