From 77d8e18eb7914d5ae4b425f9f78815f4ecc50676 Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Wed, 16 May 2012 07:45:52 +0000 Subject: [PATCH] Geography : add a new layer to display dates on the map svn: r19537 --- src/plugins/lib/maps/datelayer.py | 154 ++++++++++++++++++++++++++++++ src/plugins/lib/maps/osmGps.py | 17 ++++ 2 files changed, 171 insertions(+) create mode 100644 src/plugins/lib/maps/datelayer.py diff --git a/src/plugins/lib/maps/datelayer.py b/src/plugins/lib/maps/datelayer.py new file mode 100644 index 000000000..7c1248f62 --- /dev/null +++ b/src/plugins/lib/maps/datelayer.py @@ -0,0 +1,154 @@ +# -*- python -*- +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2011-2012 Serge Noiraud +# +# 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: grampsmaps.py 18399 2011-11-02 17:15:20Z noirauds $ + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import os +import gobject +import operator +from math import * + +#------------------------------------------------------------------------ +# +# Set up logging +# +#------------------------------------------------------------------------ +import logging +_LOG = logging.getLogger("maps.datelayer") + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +import gtk + +#------------------------------------------------------------------------- +# +# Gramps Modules +# +#------------------------------------------------------------------------- +import const +import cairo + +#------------------------------------------------------------------------- +# +# osmGpsMap +# +#------------------------------------------------------------------------- + +try: + import osmgpsmap +except: + raise + +class DateLayer(gobject.GObject, osmgpsmap.GpsMapLayer): + """ + This is the layer used to display the two extreme dates on the top left of the view + """ + def __init__(self): + """ + Initialize the layer + """ + gobject.GObject.__init__(self) + self.first = " " + self.last = " " + self.color = "black" + self.font = "Arial" + self.size = 36 + + def clear_dates(self): + """ + reset the layer attributes. + """ + self.first = " " + self.last = " " + self.color = "black" + self.font = "Arial" + self.size = 36 + + def set_font_attributes(self, font, size, color): + """ + Set the font color, size and name + """ + self.color = color + self.font = font + self.size = size + + def add_date(self, date): + """ + Add a date + """ + if date == " " or date == "0000" or date == "9999": + return + if date < self.first or self.first == " ": + self.first = date + if date > self.last or self.last == " ": + self.last = date + + def do_draw(self, gpsmap, drawable): + """ + Draw the two extreme dates + """ + ctx = drawable.cairo_create() + ctx.select_font_face(self.font, + cairo.FONT_SLANT_NORMAL, + cairo.FONT_WEIGHT_NORMAL) + ctx.set_font_size(int(self.size)) + color = gtk.gdk.color_parse(self.color) + ctx.set_source_rgba(float(color.red / 65535.0), + float(color.green / 65535.0), + float(color.blue / 65535.0), + 0.6) # transparency + coord_x = 10 + coord_y = 15 + 2*int(self.size) # Display the oldest date + ctx.move_to(coord_x, coord_y) + ctx.show_text(self.first) + coord_y = 15 + 3*int(self.size) # Display the newest date + ctx.move_to(coord_x, coord_y) + ctx.show_text(self.last) + + def do_render(self, gpsmap): + """ + render the layer + """ + pass + + def do_busy(self): + """ + set the layer busy + """ + return False + + def do_button_press(self, gpsmap, gdkeventbutton): + """ + When we press a button. + """ + return False + +gobject.type_register(DateLayer) + diff --git a/src/plugins/lib/maps/osmGps.py b/src/plugins/lib/maps/osmGps.py index 3e57cfc27..e341e9a53 100644 --- a/src/plugins/lib/maps/osmGps.py +++ b/src/plugins/lib/maps/osmGps.py @@ -56,6 +56,7 @@ from dummylayer import DummyLayer from dummynogps import DummyMapNoGpsPoint from selectionlayer import SelectionLayer from lifewaylayer import LifeWayLayer +from datelayer import DateLayer from gen.ggettext import sgettext as _ from config import config from QuestionDialog import ErrorDialog @@ -83,6 +84,7 @@ class OsmGps(): self.zone_selection = False self.selection_layer = None self.lifeway_layer = None + self.date_layer = None self.context_id = 0 self.begin_selection = None self.end_selection = None @@ -136,6 +138,7 @@ class OsmGps(): self.osm.layer_add(DummyLayer()) self.selection_layer = self.add_selection_layer() self.lifeway_layer = self.add_lifeway_layer() + self.date_layer = self.add_date_layer() self.cross_map = osmgpsmap.GpsMapOsd( show_crosshair=False) self.set_crosshair(config.get("geography.show_cross")) self.osm.set_center_and_zoom(config.get("geography.center-lat"), @@ -164,6 +167,20 @@ class OsmGps(): """ return self.selection_layer + def add_date_layer(self): + """ + add the track or life ways layer + """ + date_layer = DateLayer() + self.osm.layer_add(date_layer) + return date_layer + + def get_date_layer(self): + """ + get the track or life ways layer + """ + return self.date_layer + def add_lifeway_layer(self): """ add the track or life ways layer