GeoView : correction when no places with coordinates in the database.

svn: r11739
This commit is contained in:
Serge Noiraud
2009-01-26 22:30:13 +00:00
parent a9ca12e309
commit 4cd77671bd

View File

@@ -96,6 +96,7 @@ if WebKit == NOWEB :
Config.set(Config.GEOVIEW, False) Config.set(Config.GEOVIEW, False)
raise ImportError, 'No GTK html plugin found' raise ImportError, 'No GTK html plugin found'
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Modules # Gramps Modules
@@ -115,6 +116,7 @@ MOZEMBED_SUBPATH = Utils.get_empty_tempdir('mozembed_gramps')
GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview') GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview')
NB_MARKERS_PER_PAGE = 200 NB_MARKERS_PER_PAGE = 200
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Renderer # Renderer
@@ -135,18 +137,18 @@ class Renderer():
window window
""" """
return self.window return self.window
def get_uri(self): def get_uri(self):
raise NotImplementedError raise NotImplementedError
def show_all(self): def show_all(self):
self.window.show_all() self.window.show_all()
def open(self, url): def open(self, url):
""" open the webpage at url """ open the webpage at url
""" """
raise NotImplementedError raise NotImplementedError
def refresh(self): def refresh(self):
raise NotImplementedError raise NotImplementedError
@@ -166,17 +168,17 @@ class Renderer():
""" execute script in the current html page """ execute script in the current html page
""" """
raise NotImplementedError raise NotImplementedError
#def page_loaded(self,obj,status):
def page_loaded(self): def page_loaded(self):
raise NotImplementedError raise NotImplementedError
def set_button_sensitivity(self): def set_button_sensitivity(self):
""" """
We must set the back and forward button in the HtmlView class. We must set the back and forward button in the HtmlView class.
""" """
self.fct() self.fct()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Renderer with WebKit # Renderer with WebKit
@@ -194,16 +196,16 @@ class RendererWebkit(Renderer):
def page_loaded(self,obj,status): def page_loaded(self,obj,status):
self.set_button_sensitivity() self.set_button_sensitivity()
def open(self, url): def open(self, url):
self.window.open(url) self.window.open(url)
def refresh(self): def refresh(self):
self.window.reload(); self.window.reload();
def execute_script(self,url): def execute_script(self,url):
self.window.execute_script(url); self.window.execute_script(url);
def get_uri(self): def get_uri(self):
return self.window.get_main_frame().get_uri() return self.window.get_main_frame().get_uri()
@@ -222,16 +224,16 @@ class RendererMozilla(Renderer):
self.window = gtkmozembed.MozEmbed() self.window = gtkmozembed.MozEmbed()
self.browser = MOZIL self.browser = MOZIL
self.handler = self.window.connect("net-stop", self.page_loaded) self.handler = self.window.connect("net-stop", self.page_loaded)
def page_loaded(self,obj): def page_loaded(self,obj):
self.set_button_sensitivity() self.set_button_sensitivity()
def open(self, url): def open(self, url):
self.window.load_url(url) self.window.load_url(url)
def execute_script(self,url): def execute_script(self,url):
self.window.load_url(url); self.window.load_url(url);
def get_uri(self): def get_uri(self):
return self.window.get_location() return self.window.get_location()
@@ -284,6 +286,7 @@ class RendererMozilla(Renderer):
pass pass
pass # We don't use a proxy or the http_proxy variable is not set. pass # We don't use a proxy or the http_proxy variable is not set.
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# HtmlView # HtmlView
@@ -438,7 +441,7 @@ class HtmlView(PageView.PageView):
group information required. group information required.
""" """
HtmlView._define_actions_fw_bw(self) HtmlView._define_actions_fw_bw(self)
def _define_actions_fw_bw(self): def _define_actions_fw_bw(self):
# add the Backward action to handle the Backward button # add the Backward action to handle the Backward button
# accel doesn't work in webkit and gtkmozembed ! # accel doesn't work in webkit and gtkmozembed !
@@ -450,7 +453,7 @@ class HtmlView(PageView.PageView):
self.go_back) self.go_back)
]) ])
self._add_action_group(self.back_action) self._add_action_group(self.back_action)
# add the Forward action to handle the Forward button # add the Forward action to handle the Forward button
self.forward_action = gtk.ActionGroup(self.title + '/Forward') self.forward_action = gtk.ActionGroup(self.title + '/Forward')
self.forward_action.add_actions([ self.forward_action.add_actions([
@@ -459,7 +462,7 @@ class HtmlView(PageView.PageView):
self.go_forward) self.go_forward)
]) ])
self._add_action_group(self.forward_action) self._add_action_group(self.forward_action)
# add the Refresh action to handle the Refresh button # add the Refresh action to handle the Refresh button
self._add_action('Refresh', gtk.STOCK_REFRESH, _("_Refresh"), self._add_action('Refresh', gtk.STOCK_REFRESH, _("_Refresh"),
callback=self.refresh, callback=self.refresh,
@@ -471,7 +474,7 @@ class HtmlView(PageView.PageView):
# This handler is connected by build_widget. After the outside ViewManager # This handler is connected by build_widget. After the outside ViewManager
# has placed this widget we are able to access the parent container. # has placed this widget we are able to access the parent container.
pass pass
def create_start_page(self): def create_start_page(self):
""" """
This command creates a default start page, and returns the URL of this This command creates a default start page, and returns the URL of this
@@ -513,7 +516,7 @@ class GeoView(HtmlView):
def __init__(self,dbstate,uistate): def __init__(self,dbstate,uistate):
HtmlView.__init__(self, dbstate, uistate, title=_('GeoView')) HtmlView.__init__(self, dbstate, uistate, title=_('GeoView'))
self.usedmap = "openstreetmap" self.usedmap = "openstreetmap"
self.displaytype = "person" self.displaytype = "person"
self.nbmarkers = 0 self.nbmarkers = 0
@@ -538,7 +541,7 @@ class GeoView(HtmlView):
self.box.disconnect(self.bootstrap_handler) self.box.disconnect(self.bootstrap_handler)
self.box.parent.connect("size-allocate", self.size_request_for_map) 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): def size_request_for_map(self, widget, event, data=None):
v = widget.get_allocation() v = widget.get_allocation()
self.width = v.width self.width = v.width
@@ -554,11 +557,11 @@ class GeoView(HtmlView):
def set_active(self): def set_active(self):
self.key_active_changed = self.dbstate.connect('active-changed', self.key_active_changed = self.dbstate.connect('active-changed',
self.goto_active_person) self.goto_active_person)
def set_inactive(self): def set_inactive(self):
HtmlView.set_inactive(self) HtmlView.set_inactive(self)
self.dbstate.disconnect(self.key_active_changed) self.dbstate.disconnect(self.key_active_changed)
def get_stock(self): def get_stock(self):
""" """
Returns the name of the stock icon to use for the display. Returns the name of the stock icon to use for the display.
@@ -654,7 +657,6 @@ class GeoView(HtmlView):
callback=self.event_places, callback=self.event_places,
tip=_("Attempt to view places on the Map for all events.")) tip=_("Attempt to view places on the Map for all events."))
def goto_active_person(self,handle=None): def goto_active_person(self,handle=None):
self.geo_places(self.displaytype) self.geo_places(self.displaytype)
@@ -768,7 +770,7 @@ class GeoView(HtmlView):
modulo = intvl - ( intvl % 10 ) modulo = intvl - ( intvl % 10 )
if modulo == 0: if modulo == 0:
modulo = 10 modulo = 10
self.minyear=( self.minyear - ( self.minyear % 10 ) ) self.minyear=( self.minyear - ( self.minyear % 10 ) )
self.maxyear=( self.maxyear - ( self.maxyear % 10 ) ) self.maxyear=( self.maxyear - ( self.maxyear % 10 ) )
self.yearint=(self.maxyear-self.minyear)/self.maxgen self.yearint=(self.maxyear-self.minyear)/self.maxgen
@@ -890,7 +892,7 @@ class GeoView(HtmlView):
pass pass
# Select the center of the map and the zoom # Select the center of the map and the zoom
self.centered = False self.centered = False
if type == 2: if type == 2:
# Sort by year for events # Sort by year for events
self.sort = sorted(self.place_list, key=operator.itemgetter(7)) self.sort = sorted(self.place_list, key=operator.itemgetter(7))
else: else:
@@ -973,8 +975,8 @@ class GeoView(HtmlView):
# We center the map on a point at the center of all markers # We center the map on a point at the center of all markers
self.centerlat = maxlat/2 self.centerlat = maxlat/2
self.centerlon = maxlong/2 self.centerlon = maxlong/2
latit = self.centerlat latit = 0.0
longt = self.centerlon longt = 0.0
for mark in self.sort: for mark in self.sort:
cent = int(mark[6]) cent = int(mark[6])
if cent: if cent:
@@ -991,9 +993,11 @@ class GeoView(HtmlView):
longt = self.maxlon+self.centerlon longt = self.maxlon+self.centerlon
else: else:
longt = self.maxlon-self.centerlon longt = self.maxlon-self.centerlon
self.latit = latit self.mustcenter = False
self.longt = longt if latit != 0.0 or longt != 0.0:
self.mustcenter = True self.latit = latit
self.longt = longt
self.mustcenter = True
for page in range(0,pages,1): for page in range(0,pages,1):
self.nbpages += 1 self.nbpages += 1
if type == 1: if type == 1:
@@ -1163,40 +1167,40 @@ class GeoView(HtmlView):
self.yearinmarker = [] self.yearinmarker = []
self.mapview.write("mapstraction.addMarker(my_marker);") self.mapview.write("mapstraction.addMarker(my_marker);")
self.setattr = False self.setattr = False
if not self.centered: if self.nbmarkers > 0:
# We have no valid geographic point to center the map. if self.setattr:
# So you'll see the street where I live. years = ""
# I think another place should be better : if mark[2]:
# Where is the place where the gramps project began ? for y in self.yearinmarker:
# years += "%d " % y
# I think we should put here all gramps developpers. years += "end"
# not only me ... self.mapview.write("my_marker.setAttribute('year','%s');" % years)
# self.yearinmarker = []
longitude = -1.568792 years=""
latitude = 47.257971 self.mapview.write("mapstraction.addMarker(my_marker);")
self.mapview.write("\nvar point = new LatLonPoint(%s,%s);\n"%(latitude,longitude))
self.mapview.write(" mapstraction.setCenterAndZoom(point, %d);\n"%2)
self.mapview.write(" my_marker = new Marker(point);\n")
self.mapview.write(" my_marker.setLabel(\"%s\");\n"%_("The author of this module."))
self.mapview.write(" my_marker.setInfoBubble(\"<div style='white-space:nowrap;' >")
self.mapview.write("Serge Noiraud<br>Nantes, France<br>")
self.mapview.write("%s</div>\");\n"%_("This request has no geolocation associated."))
self.mapview.write(" mapstraction.addMarker(my_marker);")
self.setattr = False self.setattr = False
if self.setattr: else:
years = "" # We have no valid geographic point to center the map.
if mark[2]: # So you'll see the street where I live.
for y in self.yearinmarker: # I think another place should be better :
years += "%d " % y # Where is the place where the gramps project began ?
years += "end" #
self.mapview.write("my_marker.setAttribute('year','%s');" % years) # I think we should put here all gramps developpers.
self.yearinmarker = [] # not only me ...
years="" #
self.mapview.write("mapstraction.addMarker(my_marker);") longitude = -1.568792
latitude = 47.257971
self.mapview.write("\nvar point = new LatLonPoint(%s,%s);\n"%(latitude,longitude))
self.mapview.write(" mapstraction.setCenterAndZoom(point, %d);\n"%2)
self.mapview.write(" my_marker = new Marker(point);\n")
self.mapview.write(" my_marker.setLabel(\"%s\");\n"%_("The author of this module."))
self.mapview.write(" my_marker.setInfoBubble(\"<div style='white-space:nowrap;' >")
self.mapview.write("Serge Noiraud<br>Nantes, France<br>")
self.mapview.write("%s</div>\");\n"%_("This request has no geolocation associated."))
self.mapview.write(" mapstraction.addMarker(my_marker);")
self.setattr = False self.setattr = False
self.mapview.write("\n </script>\n") self.mapview.write("\n </script>\n")
def createPersonMarkers(self,db,person,comment): def createPersonMarkers(self,db,person,comment):
""" """
This function create all markers for the specified person. This function create all markers for the specified person.
@@ -1303,7 +1307,7 @@ class GeoView(HtmlView):
self.maxlon = float(0.0) self.maxlon = float(0.0)
self.minyear = int(9999) self.minyear = int(9999)
self.maxyear = int(0) self.maxyear = int(0)
latitude = "" latitude = ""
longitude = "" longitude = ""
self.center = True self.center = True