From 592ca5067d9ed24185830dadb81b2883a0f0fdff Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Tue, 10 Feb 2009 23:21:46 +0000 Subject: [PATCH] GeoView : Code cleaning after pylint use. svn: r11958 --- src/DataViews/GeoView.py | 1065 +++++++++++++++++++++----------------- 1 file changed, 589 insertions(+), 476 deletions(-) diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py index 37e7b670e..e964a2121 100644 --- a/src/DataViews/GeoView.py +++ b/src/DataViews/GeoView.py @@ -23,21 +23,19 @@ # $Id$ +""" +Geo View +""" + #------------------------------------------------------------------------- # # Python modules # #------------------------------------------------------------------------- from gettext import gettext as _ -from cgi import escape -import math import os -import tempfile import urlparse import const -import gobject -import threading -import time import operator #------------------------------------------------------------------------- @@ -47,15 +45,6 @@ import operator #------------------------------------------------------------------------- import gtk -#------------------------------------------------------------------------- -# -# Set up logging -# -#------------------------------------------------------------------------- -import logging -LOG = logging.getLogger(".GeoView") -#LOG.setLevel(logging.DEBUG) - #------------------------------------------------------------------------- # # Gramps Modules @@ -98,14 +87,6 @@ if WebKit == NOWEB : Config.set(Config.GEOVIEW, False) raise ImportError, 'No GTK html plugin found' - -#------------------------------------------------------------------------- -# -# Gramps Modules -# -#------------------------------------------------------------------------- - - #------------------------------------------------------------------------- # # Constants @@ -118,7 +99,6 @@ MOZEMBED_SUBPATH = Utils.get_empty_tempdir('mozembed_gramps') GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview') NB_MARKERS_PER_PAGE = 200 - #------------------------------------------------------------------------- # # Renderer @@ -141,40 +121,63 @@ class Renderer(): return self.window def get_uri(self): + """ + Get the current url + """ raise NotImplementedError def show_all(self): + """ + show all in the main window. + """ self.window.show_all() def open(self, url): - """ open the webpage at url + """ + open the webpage at url """ raise NotImplementedError def refresh(self): + """ + We need to reload the page. + """ raise NotImplementedError def go_back(self): - self.window.go_back(); + """ + Go to the previous page. + """ + self.window.go_back() def can_go_back(self): + """ + is the browser able to go backward ? + """ return self.window.can_go_back() def go_forward(self): - self.window.go_forward(); + """ + Go to the next page. + """ + self.window.go_forward() def can_go_forward(self): + """ + is the browser able to go forward ? + """ return self.window.can_go_forward() def execute_script(self, url): - """ execute script in the current html page + """ + execute javascript in the current html page """ raise NotImplementedError def page_loaded(self): - raise NotImplementedError - - def page_begin_load(self): + """ + The page is completely loaded. + """ raise NotImplementedError def set_button_sensitivity(self): @@ -183,7 +186,6 @@ class Renderer(): """ self.fct() - #------------------------------------------------------------------------- # # Renderer with WebKit @@ -199,57 +201,36 @@ class RendererWebkit(Renderer): self.browser = WEBKIT self.frame = self.window.get_main_frame() self.frame.connect("load-done", self.page_loaded) - self.window.connect("load-started", self.page_begin_load) - self.window.connect("hovering-over-link", self.hover_link_cb) - #self.window.connect("navigation-requested", self.navigation) - self.window.connect("load-progress-changed", self.load_progress) - #self.window.connect("script-alert", self.script_alert_cb) - #self.window.connect("script-confirm", self.script_confirm_cb) - #self.window.connect("script-prompt", self.script_prompt_cb) - def page_loaded(self,obj,status): + def page_loaded(self, obj, status): + """ + We just loaded one page in the browser. + Set the button sensitivity + """ self.set_button_sensitivity() - def page_begin_load(self,view,frame): - if frame is self.frame: - LOG.debug("load-started : %s" % self.get_uri()) - pass - - def navigation(self,view,frame,networkrequest): - LOG.debug("navigation-requested : %s" % frame.get_uri()) - return 1 - - def load_progress(self,view,percent): - #LOG.debug(_("load-progress-changed : load %s : %s%%") % (view.get_main_frame().get_uri(), percent)) - pass - - def hover_link_cb(self,view,title,url): - if view and url: - LOG.debug("hovering-over-link : %s - %s" % (title, url)) - - def script_confirm_cb(self, view, frame, message, isConfirmed): - LOG.debug("script confirm") - pass - - def window_event_cb(self, view, event, message, fromwindow): - LOG.debug("event!", event, view, message ) - LOG.debug(event.get_event_type() ) - return True - - def script_prompt_cb(self, view, frame, message, default, text): - LOG.debug("script prompt") - pass - def open(self, url): + """ + We need to load the page in the browser. + """ self.window.open(url) def refresh(self): - self.window.reload(); + """ + We need to reload the page in the browser. + """ + self.window.reload() - def execute_script(self,url): - self.window.execute_script(url); + def execute_script(self, url): + """ + We need to execute a javascript function into the browser + """ + self.window.execute_script(url) def get_uri(self): + """ + What is the uri loaded in the browser ? + """ return self.window.get_main_frame().get_uri() class RendererMozilla(Renderer): @@ -267,26 +248,37 @@ class RendererMozilla(Renderer): self.window = gtkmozembed.MozEmbed() self.browser = MOZIL self.handler = self.window.connect("net-stop", self.page_loaded) - self.handler = self.window.connect("net-start", self.page_begin_load) - def page_loaded(self,obj): + def page_loaded(self, obj): + """ + We just loaded one page in the browser. + Set the button sensitivity + """ self.set_button_sensitivity() - def page_begin_load(self,obj): - LOG.debug("Loading - %s" % self.get_uri()) - pass - def open(self, url): + """ + We need to load the page in the browser. + """ self.window.load_url(url) - def execute_script(self,url): - self.window.load_url(url); + def execute_script(self, url): + """ + We need to execute a javascript function into the browser + """ + self.window.load_url(url) def get_uri(self): + """ + What is the uri loaded in the browser ? + """ return self.window.get_location() def refresh(self): - self.window.reload(0); + """ + We need to reload the page in the browser. + """ + self.window.reload(0) def __set_mozembed_proxy(self): """ @@ -298,34 +290,44 @@ class RendererMozilla(Renderer): proxy = os.environ['http_proxy'] if proxy: host_port = None - prefs = open(MOZEMBED_SUBPATH+"/prefs.js","w+") + prefs = open(MOZEMBED_SUBPATH+"/prefs.js", "w+") parts = urlparse.urlparse(proxy) if not parts[0] or parts[0] == 'http': host_port = parts[1] - t = host_port.split(':') - host = t[0].strip() + hport = host_port.split(':') + host = hport[0].strip() if host: try: - port = int(t[1]) + port = int(hport[1]) except: user = host - u = t[1].split('@') - password = u[0] - host = u[1] - port = int(t[2]) + uprox = hport[1].split('@') + password = uprox[0] + host = uprox[1] + port = int(hport[2]) if port and host: port = str(port) - prefs.write('user_pref("network.proxy.type", 1);\r\n') - prefs.write('user_pref("network.proxy.http", "'+host+'");\r\n') - prefs.write('user_pref("network.proxy.http_port", '+port+');\r\n') - prefs.write('user_pref("network.proxy.no_proxies_on", '\ - '"127.0.0.1,localhost,localhost.localdomain");\r\n') - prefs.write('user_pref("network.proxy.share_proxy_settings", true);\r\n') - prefs.write('user_pref("network.http.proxy.pipelining", true);\r\n') - prefs.write('user_pref("network.http.proxy.keep-alive", true);\r\n') - prefs.write('user_pref("network.http.proxy.version", 1.1);\r\n') - prefs.write('user_pref("network.http.sendRefererHeader, 0);\r\n') + prefs.write('user_pref("network.proxy') + prefs.write('.type", 1);\r\n') + prefs.write('user_pref("network.proxy') + prefs.write('.http", "'+host+'");\r\n') + prefs.write('user_pref("network.proxy') + prefs.write('.http_port", '+port+');\r\n') + prefs.write('user_pref("network.proxy') + prefs.write('.no_proxies_on",') + prefs.write(' "127.0.0.1,localhost,localhost') + prefs.write('.localdomain");\r\n') + prefs.write('user_pref("network.proxy') + prefs.write('.share_proxy_settings", true);\r\n') + prefs.write('user_pref("network.http') + prefs.write('.proxy.pipelining", true);\r\n') + prefs.write('user_pref("network.http') + prefs.write('.proxy.keep-alive", true);\r\n') + prefs.write('user_pref("network.http') + prefs.write('.proxy.version", 1.1);\r\n') + prefs.write('user_pref("network.http') + prefs.write('.sendRefererHeader, 0);\r\n') prefs.close() except: try: # trying to remove pref.js in case of proxy change. @@ -334,7 +336,6 @@ class RendererMozilla(Renderer): pass pass # We don't use a proxy or the http_proxy variable is not set. - #------------------------------------------------------------------------- # # HtmlView @@ -348,11 +349,17 @@ class HtmlView(PageView.PageView): def __init__(self, dbstate, uistate, title=_('HtmlView')): PageView.PageView.__init__(self, title, dbstate, uistate) - self.dbstate = dbstate - self.external_url = False self.need_to_resize = False + self.back_action = None + self.forward_action = None + self.renderer = None + self.urlfield = "" + self.htmlfile = "" + self.table = "" + self.bootstrap_handler = None + self.box = None def build_widget(self): """ @@ -361,49 +368,45 @@ class HtmlView(PageView.PageView): a gtk.Notebook page. """ global WebKit - self.box = gtk.VBox(False, 4) #top widget at the top - self.box.pack_start(self.top_widget(), False, False,0 ) + self.box.pack_start(self.top_widget(), False, False, 0 ) #web page under it in a scrolled window self.table = gtk.Table(1, 1, False) 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(self.table) - self.bootstrap_handler = self.box.connect("size-request", self.init_parent_signals_for_map) + self.bootstrap_handler = self.box.connect("size-request", + self.init_parent_signals_for_map) self.table.get_parent().set_shadow_type(gtk.SHADOW_NONE) self.table.set_row_spacings(1) self.table.set_col_spacings(0) - if (WebKit == WEBKIT) : # We use webkit self.renderer = RendererWebkit() elif (WebKit == MOZIL) : # We use gtkmozembed self.renderer = RendererMozilla() - self.table.add(self.renderer.get_window()) self.box.pack_start(frame, True, True, 0) - - # this is used to activate the back and forward button from the renderer class. + # this is used to activate the back and forward button + # from the renderer class. self.renderer.fct = self.set_button_sensitivity self.renderer.show_all() - #load a welcome html page urlhelp = self.create_start_page() self.open(urlhelp) - return self.box def top_widget(self): """ The default class gives a widget where user can type an url """ - hbox = gtk.HBox(False,4) + hbox = gtk.HBox(False, 4) self.urlfield = gtk.Entry() self.urlfield.set_text("http://gramps-project.org") - self.urlfield.connect('activate', self._on_activate); + self.urlfield.connect('activate', self._on_activate) hbox.pack_start(self.urlfield, True, True, 4) button = gtk.Button(stock=gtk.STOCK_APPLY) button.connect('clicked', self._on_activate) @@ -411,28 +414,44 @@ class HtmlView(PageView.PageView): return hbox def set_button_sensitivity(self): + """ + Set the backward and forward button in accordance to the browser. + """ self.forward_action.set_sensitive(self.renderer.can_go_forward()) self.back_action.set_sensitive(self.renderer.can_go_back()) def open(self, url): - """ open an url + """ + open an url """ self.renderer.open(url) def go_back(self, button): - self.renderer.go_back(); + """ + Go to the previous loaded url. + """ + self.renderer.go_back() self.set_button_sensitivity() self.external_uri() def go_forward(self, button): - self.renderer.go_forward(); + """ + Go to the next loaded url. + """ + self.renderer.go_forward() self.set_button_sensitivity() self.external_uri() - def refresh(self,button): - self.renderer.refresh(); + def refresh(self, button): + """ + Force to reload the page. + """ + self.renderer.refresh() def external_uri(self): + """ + used to resize or not resize depending on external or local file. + """ uri = self.renderer.get_uri() if self.external_url: self.external_url = False @@ -447,7 +466,10 @@ class HtmlView(PageView.PageView): except: pass - def _on_activate(self, object): + def _on_activate(self, nobject): + """ + Here when we activate the url button. + """ url = self.urlfield.get_text() if url.find('://') == -1: url = 'http://'+ url @@ -491,9 +513,12 @@ class HtmlView(PageView.PageView): HtmlView._define_actions_fw_bw(self) def _define_actions_fw_bw(self): - # add the Backward action to handle the Backward button - # accel doesn't work in webkit and gtkmozembed ! - # we must do that ... + """ + prepare the forward and backward buttons. + add the Backward action to handle the Backward button + accel doesn't work in webkit and gtkmozembed ! + we must do that ... + """ self.back_action = gtk.ActionGroup(self.title + '/Back') self.back_action.add_actions([ ('Back', gtk.STOCK_GO_BACK, _("_Back"), @@ -501,7 +526,6 @@ class HtmlView(PageView.PageView): self.go_back) ]) self._add_action_group(self.back_action) - # add the Forward action to handle the Forward button self.forward_action = gtk.ActionGroup(self.title + '/Forward') self.forward_action.add_actions([ @@ -510,7 +534,6 @@ class HtmlView(PageView.PageView): self.go_forward) ]) self._add_action_group(self.forward_action) - # add the Refresh action to handle the Refresh button self._add_action('Refresh', gtk.STOCK_REFRESH, _("_Refresh"), callback=self.refresh, @@ -518,9 +541,12 @@ class HtmlView(PageView.PageView): tip=_("Stop and reload the page.")) def init_parent_signals_for_map(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. + """ + 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. + """ pass def create_start_page(self): @@ -549,35 +575,58 @@ class HtmlView(PageView.PageView): 'For example: http://gramps-project.org

') } filename = os.path.join(tmpdir, 'startpage') - fd = file(filename,"w+") - fd.write(data) - fd.close() + ufd = file(filename, "w+") + ufd.write(data) + ufd.close() return 'file://'+filename - #------------------------------------------------------------------------- # # GeoView # #------------------------------------------------------------------------- class GeoView(HtmlView): + """ + The view used to render html pages. + """ - def __init__(self,dbstate,uistate): + def __init__(self, dbstate, uistate): HtmlView.__init__(self, dbstate, uistate, title=_('GeoView')) - self.usedmap = "openstreetmap" self.displaytype = "person" self.nbmarkers = 0 self.without = 0 self.nbpages = 0 - - # We use the top_widget method defined in HtmlView. - #def top_widget(self): - # """ - # The top widget to use, for GeoView, none - # """ - # return gtk.Label() - + self.yearinmarker = [] + self.mustcenter = False + self.centerlat = 0.0 + self.centerlon = 0.0 + self.setattr = True + self.latit = 0.0 + self.longt = 0.0 + self.maxlat = 0.0 + self.maxlon = 0.0 + self.height = 0.0 + self.width = 0.0 + self.zoom = 1 + self.minyear = 1 + self.maxyear = 1 + self.maxgen = 1 + self.mapview = None + self.yearint = 0 + self.centered = True + self.center = True + self.place_list = [] + self.htmlfile = "" + self.places = [] + self.sort = [] + self.without_coord_file = [] + self.place_without_coordinates = [] + self.minlat = float(0.0) + self.maxlat = float(0.0) + self.minlon = float(0.0) + self.key_active_changed = None + def on_delete(self): """ We need to suppress temporary files here. @@ -585,18 +634,24 @@ class GeoView(HtmlView): pass def init_parent_signals_for_map(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. + """ + 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.box.disconnect(self.bootstrap_handler) self.box.parent.connect("size-allocate", self.size_request_for_map) - self.size_request_for_map(widget.parent,event) + self.size_request_for_map(widget.parent, event) def size_request_for_map(self, widget, event, data=None): - v = widget.get_allocation() - self.width = v.width - self.height = v.height - uri = self.renderer.get_uri() + """ + We need to resize the map + """ + gws = widget.get_allocation() + self.width = gws.width + self.height = gws.height + #uri = self.renderer.get_uri() self.external_uri() if self.need_to_resize != True: try: @@ -605,10 +660,16 @@ class GeoView(HtmlView): pass def set_active(self): + """ + Here when we enter in this view. + """ self.key_active_changed = self.dbstate.connect('active-changed', self.goto_active_person) def set_inactive(self): + """ + Here when we go to another view. + """ HtmlView.set_inactive(self) self.dbstate.disconnect(self.key_active_changed) @@ -620,15 +681,18 @@ class GeoView(HtmlView): """ return 'gramps-geo' - def change_map(self,usedmap): - self.renderer.execute_script("javascript:mapstraction.swap(map,'"+usedmap+"')"); + def change_map(self, usedmap): + """ + Ask to the browser to change the current map. + """ + self.renderer.execute_script( + "javascript:mapstraction.swap(map,'"+usedmap+"')") def ui_definition(self): """ Specifies the UIManager XML code that defines the menus and buttons associated with the interface. """ - if Config.get(Config.GEOVIEW_GOOGLEMAPS): alternate_map = "GoogleMaps" elif Config.get(Config.GEOVIEW_OPENLAYERS): @@ -661,13 +725,12 @@ class GeoView(HtmlView): Required define_actions function for PageView. Builds the action group information required. """ - HtmlView._define_actions_fw_bw(self) self.forward_action.set_sensitive(False) self.back_action.set_sensitive(False) - - self._add_action('OpenStreetMap', 'gramps-openstreetmap', _('_OpenStreetMap'), - callback=self.select_OpenStreetMap_map, + self._add_action('OpenStreetMap', 'gramps-openstreetmap', + _('_OpenStreetMap'), + callback=self.select_openstreetmap_map, tip=_("Select OpenStreetMap Maps")) if Config.get(Config.GEOVIEW_GOOGLEMAPS): self._add_action('GoogleMaps', 'gramps-alternate-map', @@ -689,129 +752,99 @@ class GeoView(HtmlView): _('_Microsoft Maps'), callback=self.select_microsoft_map, tip=_("Select Microsoft Maps")) - self._add_action('AllPlacesMaps', gtk.STOCK_HOME, _('_All Places'), - callback=self.all_places, - tip=_("Attempt to view all places in the family tree.")) + callback=self.all_places, + tip=_("Attempt to view all places in the family tree.")) self._add_action('PersonMaps', 'gramps-person', _('_Person'), - callback=self.person_places, - tip=_("Attempt to view all the places where the selected people lived.")) + callback=self.person_places, + tip=_("Attempt to view all the places where the selected people lived.")) self._add_action('FamilyMaps', 'gramps-parents-add', _('_Family'), - callback=self.family_places, - tip=_("Attempt to view places of the selected people's family.")) + callback=self.family_places, + tip=_("Attempt to view places of the selected people's family.")) self._add_action('EventMaps', 'gramps-event', _('_Event'), - callback=self.event_places, - tip=_("Attempt to view places connected to all events.")) + callback=self.event_places, + tip=_("Attempt to view places connected to all events.")) - def goto_active_person(self,handle=None): + def goto_active_person(self, handle=None): + """ + Here when the GeoView page is loaded + """ self.geo_places(self.displaytype) - def all_places(self,handle=None): + def all_places(self, hanle=None): """ Specifies the place for the home person to display with mapstraction. """ self.displaytype = "places" self.geo_places(self.displaytype) - def person_places(self,handle=None): + def person_places(self, handle=None): """ Specifies the person places. """ self.displaytype = "person" self.geo_places(self.displaytype) - def family_places(self,handle=None): + def family_places(self, hanle=None): """ Specifies the family places to display with mapstraction. """ self.displaytype = "family" self.geo_places(self.displaytype) - def event_places(self,handle=None): + def event_places(self, hanle=None): """ Specifies all event places to display with mapstraction. """ self.displaytype = "event" self.geo_places(self.displaytype) - def geo_places(self,displaytype): + def geo_places(self, displaytype): """ Specifies the places to display with mapstraction. """ self.external_url = False self.nbmarkers = 0 self.without = 0 - self.createMapstraction(displaytype) + self.createmapstraction(displaytype) self.open("file://"+self.htmlfile) - def select_OpenStreetMap_map(self,handle=None): + def select_openstreetmap_map(self): + """ + Specifies openstreetmap is the default map + """ self.usedmap = "openstreetmap" self.change_map("openstreetmap") - def select_openlayers_map(self,handle=None): + def select_openlayers_map(self): + """ + Specifies openstreetmap is the default map + """ self.usedmap = "openlayers" self.change_map("openlayers") - def select_google_map(self,handle=None): + def select_google_map(self): + """ + Specifies google is the default map + """ self.usedmap = "google" self.change_map("google") - def select_yahoo_map(self,handle=None): + def select_yahoo_map(self): + """ + Specifies yahoo map is the default map + """ self.usedmap = "yahoo" self.change_map("yahoo") - def select_microsoft_map(self,handle=None): + def select_microsoft_map(self): + """ + Specifies microsoft is the default map + """ self.usedmap = "microsoft" self.change_map("microsoft") - def set_mozembed_proxy(self): - """ - Try to see if we have some proxy environment variable. - http_proxy in our case. - The standard format is : http://[user:password@]proxy:port/ - This function is only used with gtkmozembed. - """ - try: - proxy = os.environ['http_proxy'] - data = "" - if proxy: - prefs = open(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js","w") - 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) - prefs.write('user_pref("network.proxy.type", 1);\r\n') - prefs.write('user_pref("network.proxy.http", "'+host+'");\r\n') - prefs.write('user_pref("network.proxy.http_port", '+port+');\r\n') - prefs.write('user_pref("network.proxy.no_proxies_on", "127.0.0.1,localhost,localhost.localdomain");\r\n') - prefs.write('user_pref("network.proxy.share_proxy_settings", true);\r\n') - prefs.write('user_pref("network.http.proxy.pipelining", true);\r\n') - prefs.write('user_pref("network.http.proxy.keep-alive", true);\r\n') - prefs.write('user_pref("network.http.proxy.version", 1.1);\r\n') - prefs.write('user_pref("network.http.sendRefererHeader, 0);\r\n') - prefs.close() - except: - try: # trying to remove pref.js in case of proxy change. - os.remove(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js") - except: - pass - pass # We don't use a proxy or the http_proxy variable is not set. - - def create_page_for_places_without_coordinates(self): + def createpageforplaceswithoutcoord(self): """ This command creates a page with the list of all places without coordinates page. @@ -836,35 +869,42 @@ class GeoView(HtmlView): """ - fd = open(self.without_coord_file,"w+") - fd.write(data) + ufd = open(self.without_coord_file, "w+") + ufd.write(data) self.places = sorted(self.place_without_coordinates) i = 1 - fd.write("") + ufd.write("
NBGramps IDPlace
") + ufd.write("") for place in self.places: - fd.write("" % ( i, place[0], place[1] )) + ufd.write("" + % ( i, place[0], place[1] )) i += 1 - fd.write(end) - fd.close() + ufd.write(end) + ufd.close() - def createMapstractionPostHeader(self,h3mess,h4mess,maxpages,curpage,ftype): - self.maxgen=Config.get(Config.GENERATION_DEPTH) + def createmapstractionpostheader(self, h3mess, h4mess, + maxpages, curpage, ftype): + """ + 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. + """ + self.maxgen = Config.get(Config.GENERATION_DEPTH) if self.maxyear == 0: - self.maxyear=2100 + self.maxyear = 2100 if self.minyear == 9999: - self.minyear=1500 + self.minyear = 1500 period = (self.maxyear-self.minyear) intvl = (period/self.maxgen) modulo = intvl - ( intvl % 10 ) if modulo == 0: modulo = 10 - - self.minyear=( self.minyear - ( self.minyear % 10 ) ) - self.maxyear=( self.maxyear - ( self.maxyear % 10 ) ) - self.yearint=(self.maxyear-self.minyear)/self.maxgen - self.yearint=( self.yearint - ( self.yearint % modulo ) ) + self.minyear = ( self.minyear - ( self.minyear % 10 ) ) + self.maxyear = ( self.maxyear - ( self.maxyear % 10 ) ) + self.yearint = (self.maxyear-self.minyear)/self.maxgen + self.yearint = ( self.yearint - ( self.yearint % modulo ) ) if self.yearint == 0: - self.yearint=10 + self.yearint = 10 self.mapview.write(" var step = %s;\n" % self.yearint) self.mapview.write(" \n") self.mapview.write(" \n") @@ -875,82 +915,110 @@ class GeoView(HtmlView): maxpages, NB_MARKERS_PER_PAGE)) self.mapview.write("
%s
\n" % message) if curpage != 1: - priorfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,curpage-1) + priorfile = GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % \ + (ftype, curpage-1) self.mapview.write("--" % priorfile) else: self.mapview.write(" --") - for page in range(1,maxpages+1,1): + for page in range(1, maxpages+1, 1): if page == curpage: self.mapview.write(" %d" % page) else: if ( page < curpage + 11 ) and ( page > curpage - 11 ): - nextfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,page) - self.mapview.write(" %d" % (nextfile, page)) + nextfile = GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % \ + (ftype, page) + self.mapview.write(" %d" % \ + (nextfile, page)) if curpage != maxpages: - nextfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,curpage+1) + nextfile = GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % \ + (ftype, curpage+1) self.mapview.write(" ++" % nextfile) else: self.mapview.write(" ++") self.mapview.write("\n
\n") if self.without != 0: self.without_coord_file = GEOVIEW_SUBPATH+"/without_coord.html" - self.mapview.write("\n" ) - self.create_page_for_places_without_coordinates() + self.mapview.write("\n" ) + self.createpageforplaceswithoutcoord() if self.displaytype != "places": self.mapview.write("
\n") self.mapview.write("
\n") - self.mapview.write(" All\n") - for year in range(self.minyear,self.maxyear+self.yearint,self.yearint): - self.mapview.write(" %s\n" % ( year, year )) + self.mapview.write(" All\n") + for year in range(self.minyear, self.maxyear+self.yearint, + self.yearint): + self.mapview.write(" %s\n" % ( year, year )) self.mapview.write("
\n") self.mapview.write("

%s

" % h3mess) if h4mess: self.mapview.write("

%s

" % h4mess) - def createMapstractionHeader(self,filename): - self.mapview = open(filename,"w+") - self.mapview.write("\n") + def createmapstractionheader(self, filename): + """ + Create the html header of the page. + """ + self.mapview = open(filename, "w+") + self.mapview.write("\n") self.mapview.write("\n") self.mapview.write(" \n") - self.mapview.write(" \n") - self.mapview.write(" Geo Maps JavaScript API for Gramps\n") - self.mapview.write(" \n") + self.mapview.write(" \n") + self.mapview.write(" Geo Maps Java Script ") + self.mapview.write("API for Gramps\n") + self.mapview.write(" \n") self.mapview.write(" \n") if self.usedmap == "microsoft": self.mapview.write(" \n") elif self.usedmap == "yahoo": self.mapview.write(" \n") elif self.usedmap == "openlayers": self.mapview.write(" \n") else: # openstreetmap and google self.mapview.write(" \n") self.mapview.write(" \n") - def createPersonMarkers(self,db,person,comment): + def createpersonmarkers(self, dbstate, person, comment): """ This function create all markers for the specified person. """ @@ -1324,64 +1428,72 @@ class GeoView(HtmlView): if person: birth_ref = person.get_birth_ref() if birth_ref: - birth = db.db.get_event_from_handle(birth_ref.ref) + birth = dbstate.db.get_event_from_handle(birth_ref.ref) birthdate = birth.get_date_object() birthyear = birthdate.get_year() bplace_handle = birth.get_place_handle() if bplace_handle: - place = db.db.get_place_from_handle(bplace_handle) + place = dbstate.db.get_place_from_handle(bplace_handle) longitude = place.get_longitude() latitude = place.get_latitude() - latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") + latitude, longitude = conv_lat_lon(latitude, + longitude, "D.D8") if comment: - descr1= _("%(comment)s : birth place.") % { + descr1 = _("%(comment)s : birth place.") % { 'comment': comment} else: - descr1=_("birth place.") + descr1 = _("birth place.") descr = place.get_title() - city = place.get_main_location().get_city() - country = place.get_main_location().get_country() - # place.get_longitude and place.get_latitude return one string. - # We have coordinates when the two values contains non null string. + # 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, gen.lib.EventType.BIRTH, - _nd.display(person), latitude, longitude, - descr1, int(self.center), birthyear) + self.append_to_places_list(descr, + gen.lib.EventType.BIRTH, + _nd.display(person), + latitude, longitude, + descr1, int(self.center), + birthyear) self.center = False else: - self.append_to_places_without_coordinates(place.gramps_id,descr) + self.append_to_places_without_coord(place.gramps_id, + descr) latitude = "" longitude = "" death_ref = person.get_death_ref() if death_ref: - death = db.db.get_event_from_handle(death_ref.ref) + death = dbstate.db.get_event_from_handle(death_ref.ref) deathdate = death.get_date_object() deathyear = deathdate.get_year() dplace_handle = death.get_place_handle() if dplace_handle: - place = db.db.get_place_from_handle(dplace_handle) + place = dbstate.db.get_place_from_handle(dplace_handle) longitude = place.get_longitude() latitude = place.get_latitude() - latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") + latitude, longitude = conv_lat_lon(latitude, + longitude, "D.D8") descr = place.get_title() if comment: - descr1= _("%(comment)s : death place.") % { + descr1 = _("%(comment)s : death place.") % { 'comment': comment} else: - descr1=_("death place.") - city = place.get_main_location().get_city() - country = place.get_main_location().get_country() - # place.get_longitude and place.get_latitude return one string. - # We have coordinates when the two values contains non null string. + 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 ): - self.append_to_places_list(descr, gen.lib.EventType.DEATH, - _nd.display(person), latitude, longitude, - descr1, int(self.center), deathyear) + self.append_to_places_list(descr, + gen.lib.EventType.DEATH, + _nd.display(person), + latitude, longitude, + descr1, int(self.center), + deathyear) self.center = False else: - self.append_to_places_without_coordinates(place.gramps_id,descr) + self.append_to_places_without_coord(place.gramps_id, + descr) - def createMapstractionPlaces(self,db): + def createmapstractionplaces(self, dbstate): """ This function create the marker for each place in the database which has a lat/lon. @@ -1394,22 +1506,20 @@ class GeoView(HtmlView): self.maxlon = float(0.0) self.minyear = int(9999) self.maxyear = int(0) - latitude = "" longitude = "" self.center = True - for place_handle in db.db.get_place_handles(): - place = db.db.get_place_from_handle( place_handle) + for place_handle in dbstate.db.get_place_handles(): + place = dbstate.db.get_place_from_handle( place_handle) if place: 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") - city = place.get_main_location().get_city() - country = place.get_main_location().get_country() - # place.get_longitude and place.get_latitude return one string. - # We have coordinates when the two values contains non null string. + # 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, "", @@ -1417,16 +1527,17 @@ class GeoView(HtmlView): descr1, self.center, None) self.center = False else: - self.append_to_places_without_coordinates(place.gramps_id, + self.append_to_places_without_coord(place.gramps_id, descr) if self.center: mess = _("Cannot center the map. No location with coordinates.") else: mess = "" - self.create_pages(1,_("All places in the family tree with coordinates."), + self.create_pages(1, + _("All places in the family tree with coordinates."), mess) - def createMapstractionEvents(self,db): + def createmapstractionevents(self, dbstate): """ This function create one marker for each place associated with an event in the database which has a lat/lon. @@ -1439,12 +1550,11 @@ class GeoView(HtmlView): self.maxlon = float(0.0) self.minyear = int(9999) self.maxyear = int(0) - latitude = "" longitude = "" self.center = True - for event_handle in db.db.get_event_handles(): - event = db.db.get_event_from_handle( event_handle) + for event_handle in dbstate.db.get_event_handles(): + event = dbstate.db.get_event_from_handle( event_handle) if event: pl_id = event.get_place_handle() eventdate = event.get_date_object() @@ -1453,20 +1563,21 @@ class GeoView(HtmlView): 'id' : event.gramps_id, 'year' : eventyear} if pl_id: - place = db.db.get_place_from_handle(pl_id) + place = dbstate.db.get_place_from_handle(pl_id) longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") city = place.get_main_location().get_city() country = place.get_main_location().get_country() - descr2 = "%s; %s" % (city,country) - # place.get_longitude and place.get_latitude return one string. - # We have coordinates when the two values contains non null string. + descr2 = "%s; %s" % (city, country) + # 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 = [db.db.get_person_from_handle(ref_handle) + person_list = [dbstate.db.get_person_from_handle(ref_handle) for (ref_type, ref_handle) in \ - db.db.find_backlink_handles(event_handle) + dbstate.db.find_backlink_handles(event_handle) if ref_type == 'Person' ] if person_list: @@ -1488,19 +1599,21 @@ class GeoView(HtmlView): self.append_to_places_list(descr1, descr, descr, latitude, longitude, - descr2, self.center, eventyear) + descr2, self.center, + eventyear) self.center = False else: descr = place.get_title() - self.append_to_places_without_coordinates(place.gramps_id,descr) + self.append_to_places_without_coord(place.gramps_id, + descr) if self.center: mess = _("Cannot center the map. No location with coordinates.") else: mess = "" - self.create_pages(2,_("All events in the family tree with coordinates." + self.create_pages(2, _("All events in the family tree with coordinates." ), mess) - def createMapstractionFamily(self, db): + def createmapstractionfamily(self, dbstate): """ This function create all markers for each people of a family in the database which has a lat/lon. @@ -1515,50 +1628,51 @@ class GeoView(HtmlView): self.maxyear = int(0) self.center = True person = None - if db.active: - person = db.active + if dbstate.active: + person = dbstate.active if person is not None: family_list = person.get_family_handle_list() if len(family_list) > 0: fhandle = family_list[0] # first is primary - fam = db.db.get_family_from_handle(fhandle) + fam = dbstate.db.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() - father = db.db.get_person_from_handle(father_handle) + father = dbstate.db.get_person_from_handle(father_handle) if father: comment = _("Id : Father : %s") % father.gramps_id - self.createPersonMarkers(db,father,comment) + self.createpersonmarkers(dbstate, father, comment) mother_handle = fam.get_mother_handle() - mother = db.db.get_person_from_handle(mother_handle) + mother = dbstate.db.get_person_from_handle(mother_handle) if mother: comment = _("Id : Mother : %s") % mother.gramps_id - self.createPersonMarkers(db,mother,comment) + self.createpersonmarkers(dbstate, mother, comment) index = 0 child_ref_list = fam.get_child_ref_list() if child_ref_list: for child_ref in child_ref_list: - child = db.db.get_person_from_handle(child_ref.ref) + child = dbstate.db.get_person_from_handle(child_ref.ref) if child: index += 1 comment = _("Id : Child : %(id)s %(index)d") % { 'id' : child.gramps_id, 'index': index} - self.createPersonMarkers(db,child,comment) + self.createpersonmarkers(dbstate, child, comment) if self.center: mess = _("Cannot center the map. No location with coordinates.") if person is not None: self.create_pages(3, _("The active person's family members " - "have no places with coordinates."), + "have no places with coordinates."), mess) else: self.create_pages(3, _("No active person set."), mess) else: mess = "" - self.create_pages(3, ( _("All %(name)s people's family places in the " - "family tree with coordinates.") % { + self.create_pages(3, + ( _("All %(name)s people's family places in the " + "family tree with coordinates.") % { 'name' :_nd.display(person) }), mess) - def createMapstractionPerson(self,db): + def createmapstractionperson(self, dbstate): """ This function create all markers for each people's event in the database which has a lat/lon. @@ -1571,12 +1685,11 @@ class GeoView(HtmlView): self.maxlon = float(0.0) self.minyear = int(9999) self.maxyear = int(0) - latitude = "" longitude = "" person = None - if db.active: - person = db.active + if dbstate.active: + person = dbstate.active self.center = True if person is not None: # For each event, if we have a place, set a marker. @@ -1586,24 +1699,24 @@ class GeoView(HtmlView): if event_ref.role != gen.lib.EventRoleType.PRIMARY: # Only match primaries, no witnesses continue - event = db.db.get_event_from_handle(event_ref.ref) + event = dbstate.db.get_event_from_handle(event_ref.ref) eventdate = event.get_date_object() eventyear = eventdate.get_year() place_handle = event.get_place_handle() if place_handle: - place = db.db.get_place_from_handle(place_handle) + place = dbstate.db.get_place_from_handle(place_handle) longitude = place.get_longitude() latitude = place.get_latitude() - latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") + latitude, longitude = conv_lat_lon(latitude, + longitude, "D.D8") descr = place.get_title() - city = place.get_main_location().get_city() - country = place.get_main_location().get_country() - evt=gen.lib.EventType(event.get_type()) - descr1=_("%(eventtype)s : %(name)s") % { + 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. + # 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, evt, _nd.display(person), @@ -1612,8 +1725,8 @@ class GeoView(HtmlView): eventyear) self.center = False else: - self.append_to_places_without_coordinates( - place.gramps_id,descr) + self.append_to_places_without_coord( + place.gramps_id, descr) if self.center: mess = _("Cannot center the map. No location with coordinates.") if person is not None: @@ -1623,10 +1736,10 @@ class GeoView(HtmlView): self.create_pages(4, _("No active person set."), mess) else: mess = "" - self.create_pages(4,( _("All event places for %s.") % + self.create_pages(4, ( _("All event places for %s.") % _nd.display(person) ), mess) - def createMapstractionNotImplemented(self,db): + def createmapnotimplemented(self): """ This function is used to inform the user this work is not implemented. """
NBGramps IDPlace
%d%s%s
%d%s%s