From 73593ecead2c9d5bc63e3291b9e1c296f62bb71e Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Sun, 6 Jan 2008 19:23:34 +0000 Subject: [PATCH] adding GoogleView in DataViews From now we can use the Googlemap API to see where our ancestors and living families members lives. svn: r9725 --- src/Config/_GrampsConfigKeys.py | 2 +- src/DataViews/GoogleView.py | 359 ++++++++++++++++++++++++++++++++ src/DataViews/Makefile.am | 1 + src/DataViews/__init__.py | 2 + 4 files changed, 363 insertions(+), 1 deletion(-) create mode 100644 src/DataViews/GoogleView.py diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index 0f90c7b29..df199ca44 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -284,7 +284,7 @@ default_value = { GENERATION_DEPTH : 15, DATA_VIEWS: ('MyGrampsView,PersonView,RelationshipView,FamilyListView,' 'PedigreeView,EventView,SourceView,PlaceView,MediaView,' - 'RepositoryView,NoteView'), + 'RepositoryView,NoteView,GoogleView'), ADDMEDIA_IMGDIR : '', ADDMEDIA_RELPATH : False, } diff --git a/src/DataViews/GoogleView.py b/src/DataViews/GoogleView.py new file mode 100644 index 000000000..c184bf336 --- /dev/null +++ b/src/DataViews/GoogleView.py @@ -0,0 +1,359 @@ +# -*- python -*- +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2001-2007 Donald N. Allingham, 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: GoogleView.py 9598 2007-12-27 15:24:30Z dsblank $ + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ +from cgi import escape +import math +import os + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +import gtk + +try: + import cairo + cairo_available = True +except: + cairo_available = False + +#------------------------------------------------------------------------- +# +# Gramps Modules +# +#------------------------------------------------------------------------- +import gen.lib +import PageView +#from BasicUtils import name_displayer +import Utils +#import DateHandler +#import ThumbNails +import Errors +#from ReportBase import ReportUtils +#from Editors import EditPerson, EditFamily +#from DdTargets import DdTargets +#import cPickle as pickle +#import Config +#from QuestionDialog import RunDatabaseRepair, ErrorDialog +import gtkmozembed +import urlparse + + +#------------------------------------------------------------------------- +# +# Constants +# +#------------------------------------------------------------------------- +MOZEMBED_PATH = "/tmp/" +MOZEMBED_SUBPATH = "browser" + +#------------------------------------------------------------------------- +# +# GoogleView +# +#------------------------------------------------------------------------- +class GoogleView(PageView.PersonNavView): + + def __init__(self,dbstate,uistate): + PageView.PersonNavView.__init__(self, _('GoogleView'), dbstate, uistate) + + self.func_list = { + 'J' : self.jump, + } + + self.dbstate = dbstate + + def _on_url(self, widget): + self.m.load_url(widget.get_text()) + + def _quit(self, widget): + gtk.main_quit() + + def set_mozembed_proxy(self): + proxy = os.environ['http_proxy'] + data = "" + if proxy: + host_port = None + parts = urlparse.urlparse(proxy) + if not parts[0] or parts[0] == 'http': + host_port = parts[1] + t = host_port.split(':') + host = t[0].strip() + if host: + try: + port = int(t[1]) + except: + user = host + u = t[1].split('@') + password = u[0] + host = u[1] + port = int(t[2]) + + if port and host: + port = str(port) + data += 'user_pref("network.proxy.type", 1);\r\n' + data += 'user_pref("network.proxy.http", "'+host+'");\r\n' + data += 'user_pref("network.proxy.http_port", '+port+');\r\n' + data += 'user_pref("network.proxy.no_proxies_on", "127.0.0.1,localhost,localhost.localdomain");\r\n' + data += 'user_pref("network.proxy.share_proxy_settings", true);\r\n' + data += 'user_pref("network.http.proxy.pipelining", true);\r\n' + fd = file(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js","w+") + fd.write(data) + fd.close() + + def change_page(self): + self.uistate.clear_filter_results() + + def init_parent_signals_cb(self, widget, event): + # 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. + self.notebook.disconnect(self.bootstrap_handler) + self.notebook.parent.connect("size-allocate", self.size_request_cb) + self.size_request_cb(widget.parent,event) + + def add_table_to_notebook( self, table): + frame = gtk.ScrolledWindow(None,None) + frame = gtk.ScrolledWindow(None,None) + frame.set_shadow_type(gtk.SHADOW_NONE) + frame.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + frame.add_with_viewport(table) + table.get_parent().set_shadow_type(gtk.SHADOW_NONE) + table.set_row_spacings(1) + table.set_col_spacings(0) + try: + self.notebook.append_page(frame,None) + except: + # for PyGtk < 2.4 + self.notebook.append_page(frame,gtk.Label("")) + + def set_active(self): + self.key_active_changed = self.dbstate.connect('active-changed', + self.goto_active_person) + + + def set_inactive(self): + PageView.PersonNavView.set_inactive(self) + self.dbstate.disconnect(self.key_active_changed) + + 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 with + GNOME as a stock icon. + """ + return 'gramps-place' + + def build_widget(self): + """ + Builds the interface and returns a gtk.Container type that + contains the interface. This containter will be inserted into + a gtk.Notebook page. + """ + self.tooltips = gtk.Tooltips() + self.tooltips.enable() + + self.notebook = gtk.Notebook() + self.notebook.set_show_border(False) + self.notebook.set_show_tabs(False) + + self.table_2 = gtk.Table(1,1,False) + self.add_table_to_notebook( self.table_2) + + if hasattr(gtkmozembed, 'set_profile_path'): + set_profile_path = gtkmozembed.set_profile_path + else: + set_profile_path = gtkmozembed.gtk_moz_embed_set_profile_path + set_profile_path(MOZEMBED_PATH, MOZEMBED_SUBPATH) + self.m = gtkmozembed.MozEmbed() + self.set_mozembed_proxy() + self.m.set_size_request(800,600) + self.table_2.add(self.m) + + #d = {} + #for iteration in dir(self.__class__): + # d[iteration]=getattr(self, iteration) + #ui.signal_autoconnect(d) + self.m.show() + return self.notebook + + def ui_definition(self): + """ + Specifies the UIManager XML code that defines the menus and buttons + associated with the interface. + """ + return ''' + + + + + + ''' + + def define_actions(self): + """ + Required define_actions function for PageView. Builds the action + group information required. We extend beyond the normal here, + since we want to have more than one action group for the PersonView. + Most PageViews really won't care about this. + + Special action groups for Forward and Back are created to allow the + handling of navigation buttons. Forward and Back allow the user to + advance or retreat throughout the history, and we want to have these + be able to toggle these when you are at the end of the history or + at the beginning of the history. + """ + self._add_action('GoogleMaps', gtk.STOCK_JUMP_TO, _('_GoogleMaps'), + callback=self.google_places, + tip=_("Attempt to map places on Google Maps")) + + PageView.PersonNavView.define_actions(self) + + def goto_active_person(self,handle=None): + self.google_places(handle) + + def google_places(self,htmlfile): + htmlfile = MOZEMBED_PATH+"/index.html" + self.createHtml() + self.m.load_url("file://"+htmlfile) + + def createHtml(self): + from PlaceUtils import conv_lat_lon + db=self.dbstate.db + tmpdir = MOZEMBED_PATH + google = "\n" + google += " \n" + google += " \n" + google += " \n" + google += " Google Maps JavaScript API Example\n" + google += " \n" + google += " \n" + google += " \n" + google += " \n" + google += "
\n" + google += " \n" + google += "\n" + fd = file(MOZEMBED_PATH+"/index.html","w+") + fd.write(google) + fd.close() diff --git a/src/DataViews/Makefile.am b/src/DataViews/Makefile.am index f03811c97..64c1a8dc1 100644 --- a/src/DataViews/Makefile.am +++ b/src/DataViews/Makefile.am @@ -17,6 +17,7 @@ pkgdata_PYTHON = \ PlaceView.py\ MediaView.py\ NoteView.py\ + GoogleView.py\ RepositoryView.py # _MapView.py diff --git a/src/DataViews/__init__.py b/src/DataViews/__init__.py index ead44e663..b7b10d147 100644 --- a/src/DataViews/__init__.py +++ b/src/DataViews/__init__.py @@ -37,6 +37,7 @@ from PlaceView import PlaceView from MediaView import MediaView from RepositoryView import RepositoryView from NoteView import NoteView +from GoogleView import GoogleView try: import Config @@ -57,6 +58,7 @@ except: #MapView, RepositoryView, NoteView, + GoogleView, ] def get_views():