From 1284fb9aa2aa1558e81ffa8712d8e89fabac5a2d Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Sun, 20 Sep 2009 09:56:34 +0000 Subject: [PATCH] GeoView : Some write simplification and pylint adjustment. svn: r13227 --- src/DataViews/GeoView.py | 200 +++++++++++++-------------------------- 1 file changed, 65 insertions(+), 135 deletions(-) diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py index 091aef608..26557f028 100644 --- a/src/DataViews/GeoView.py +++ b/src/DataViews/GeoView.py @@ -4,9 +4,10 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2007-2009 Serge Noiraud +# Copyright (C) 2008 Benny Malengier +# Copyright (C) 2009 Gerald Britton # Copyright (C) 2009 Helge GRAMPS # Copyright (C) 2009 Josip -# Copyright (C) 2008 Benny Malengier # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -90,6 +91,16 @@ NB_MARKERS_PER_PAGE = 200 # #------------------------------------------------------------------------- +_HTMLHEADER = ''' + + + + This is used to pass messages between javascript and python + + + + +''' + #------------------------------------------------------------------------- # # Functions @@ -189,18 +213,24 @@ def _get_sign(value): return 0 def _get_zoom_lat(value): + """ + return the zoom value for latitude depending on the distance. + """ zoomlat = 1 - for i, x in enumerate([80.0, 40.0, 20.0, 10.0, 3.0, + for i, distance in enumerate([80.0, 40.0, 20.0, 10.0, 3.0, 2.0, 1.0, 0.5, 0.2, 0.1]): - if value < x: + if value < distance: zoomlat = i+1 return zoomlat + 2 def _get_zoom_long(value): + """ + return the zoom value for longitude depending on the distance. + """ zoomlong = 1 - for i, x in enumerate([120.0, 60.0, 30.0, 15.0, 7.0, + for i, distance in enumerate([120.0, 60.0, 30.0, 15.0, 7.0, 4.0, 2.0, 1.0, .5, .2, .1]): - if value < x: + if value < distance: zoomlong = i+1 return zoomlong + 2 @@ -216,6 +246,7 @@ class GeoView(HtmlView): def __init__(self, dbstate, uistate): HtmlView.__init__(self, dbstate, uistate, title=_('GeoView')) + self.dbstate = dbstate self.dbstate.connect('database-changed', self._new_database) self.usedmap = "openstreetmap" self.displaytype = "person" @@ -224,6 +255,7 @@ class GeoView(HtmlView): self.nbpages = 0 self.yearinmarker = [] self.mustcenter = False + self.external_url = False self.centerlat = 0.0 self.centerlon = 0.0 self.setattr = True @@ -711,110 +743,16 @@ class GeoView(HtmlView): ) return - - self.mapview.write("\n") - self.mapview.write("\n") - self.mapview.write("\n") - + self.mapview.write( + _HTMLTRAILER.format( + ) + ) self.mapview.close() def _set_center_and_zoom(self, ptype): @@ -1017,7 +948,7 @@ class GeoView(HtmlView): if self.maxlon == 0.0 or 0.0 < tfb > self.maxlon: self.maxlon = tfb - def _create_markers(self, format, firstm, lastm): + def _create_markers(self, formatype, firstm, lastm): """ Create all markers for the specified person. """ @@ -1079,20 +1010,20 @@ class GeoView(HtmlView): divclose = False self.mapview.write("my_marker.setInfoBubble(\"
") - if format == 1: + if formatype == 1: self.mapview.write("%s
____________
" % \ mark[0]) self.mapview.write("
%s" % mark[5]) - elif format == 2: + elif formatype == 2: self.mapview.write("%s____________
" % mark[1]) self.mapview.write("
%s - %s" % (mark[7], mark[5])) - elif format == 3: + elif formatype == 3: self.mapview.write("%s
____________
" % \ mark[0]) self.mapview.write("
%s - %s" % (mark[7], mark[5])) - elif format == 4: + elif formatype == 4: self.mapview.write("%s
____________
" % \ mark[0]) self.mapview.write("
%s - %s" % (mark[7], @@ -1240,22 +1171,21 @@ class GeoView(HtmlView): self.center = True for place in dbstate.db.iter_places(): - 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, - descr1, self.center, None) - self.center = False - else: - self._append_to_places_without_coord(place.gramps_id, - descr) + 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, + descr1, self.center, None) + self.center = False + else: + self._append_to_places_without_coord(place.gramps_id, descr) if self.center: mess = _("Cannot center the map. No location with coordinates.") else: