From 6be7146e38f660141fcd15fe4a57396e49c8aa1c Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Sun, 4 Jan 2009 23:42:20 +0000 Subject: [PATCH] GeoView : Cleaning code, solve resizing and back and forward problems. svn: r11570 --- src/DataViews/GeoView.py | 97 +++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py index 1a9e74c46..f98cc1c02 100644 --- a/src/DataViews/GeoView.py +++ b/src/DataViews/GeoView.py @@ -46,8 +46,6 @@ import time #------------------------------------------------------------------------- import gtk -#import pdb - #------------------------------------------------------------------------- # # Set up logging @@ -139,6 +137,9 @@ class Renderer(): """ return self.window + def get_uri(self): + return self.window.get_main_frame().get_uri() + def show_all(self): self.window.show_all() @@ -311,7 +312,7 @@ class HtmlView(PageView.PageView): #load a welcome html page urlhelp = self.create_start_page() - self.renderer.open(urlhelp) + self.open(urlhelp) self.renderer.show_all() return self.box @@ -330,13 +331,20 @@ class HtmlView(PageView.PageView): hbox.pack_start(button, False, False, 4) return hbox + def set_button_sensitivity(self): + self.forward_action.set_sensitive(self.renderer.can_go_forward()) + self.back_action.set_sensitive(self.renderer.can_go_back()) + + def open(self, url): + self.renderer.open(url) + self.set_button_sensitivity() + def _on_activate(self, object): url = self.urlfield.get_text() if url.find('://') == -1: url = 'http://'+ url - self.renderer.open(url) - self.forward_action.set_sensitive(self.renderer.can_go_forward()) - self.back_action.set_sensitive(self.renderer.can_go_back()) + self.external_url = True + self.open(url) def build_tree(self): """ @@ -405,6 +413,8 @@ class GeoView(HtmlView): self.usedmap = "openstreetmap" self.displaytype = "person" + self.external_url = False + self.need_to_resize = False # Create a temporary dot file (handle,self.htmlfile) = tempfile.mkstemp(".html","GeoV", @@ -427,14 +437,17 @@ class GeoView(HtmlView): self.box.parent.connect("size-allocate", self.size_request_for_map) self.size_request_for_map(widget.parent,event) - def request_resize(self): - self.size_request_for_map(self.box.parent,None,None) - self.geo_places(self.htmlfile,self.displaytype) - 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() + self.external_uri() + if self.need_to_resize != True: + try: + self.geo_places(self.htmlfile,self.displaytype) + except: + pass def set_active(self): self.key_active_changed = self.dbstate.connect('active-changed', @@ -458,15 +471,30 @@ class GeoView(HtmlView): def refresh(self,button): self.renderer.refresh(); + def external_uri(self): + uri = self.renderer.get_uri() + if self.external_url: + self.external_url = False + self.need_to_resize = True + else: + try: + if uri.find(self.htmlfile) == -1: + # external web page or start_page + self.need_to_resize = True + else: + self.need_to_resize = False + except: + pass + def go_back(self,button): self.renderer.go_back(); - self.forward_action.set_sensitive(self.renderer.can_go_forward()) - self.back_action.set_sensitive(self.renderer.can_go_back()) + self.set_button_sensitivity() + self.external_uri() def go_forward(self,button): self.renderer.go_forward(); - self.forward_action.set_sensitive(self.renderer.can_go_forward()) - self.back_action.set_sensitive(self.renderer.can_go_back()) + self.set_button_sensitivity() + self.external_uri() def ui_definition(self): """ @@ -619,12 +647,13 @@ class GeoView(HtmlView): """ Specifies the places to display with mapstraction. """ + self.external_url = False if htmlfile == None: htmlfile = MOZEMBED_PATH+"help.html" self.createHelp(htmlfile) else: self.createMapstraction(htmlfile,displaytype) - self.renderer.open("file://"+htmlfile) + self.open("file://"+htmlfile) def select_OpenStreetMap_map(self,handle=None): self.usedmap = "openstreetmap" @@ -858,8 +887,8 @@ class GeoView(HtmlView): def create_markers(self,format): self.centered = 0 margin = 10 - self.mapview.write("
\n" % - ( ( self.width - margin*4 ), ( self.height * 0.73 ), margin )) + self.mapview.write("
\n" % + ( ( self.width - margin*4 ), ( self.height * 0.74 ))) self.mapview.write("