diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py index 97a4fec9b..c09a0a98e 100644 --- a/src/DataViews/GeoView.py +++ b/src/DataViews/GeoView.py @@ -55,7 +55,7 @@ import gtk #------------------------------------------------------------------------- import logging LOG = logging.getLogger(".GeoView") -LOG.setLevel(logging.DEBUG) +#LOG.setLevel(logging.DEBUG) #------------------------------------------------------------------------- # @@ -97,7 +97,7 @@ if WebKit == NOWEB: pass #no interfaces present, raise Error so that options for GeoView do not show -if WebKit == 0 : +if WebKit == NOWEB : Config.set(Config.GEOVIEW, False) LOG.warning(_("GeoView not enabled, no html plugin for GTK found.")) raise ImportError, 'No GTK html plugin found' @@ -147,11 +147,11 @@ class Renderer(): """ raise NotImplementedError - if (self.browser == WEBKIT): - self.m.open("file://"+htmlfile) - elif (self.browser == MOZIL): - self.m.load_url("file://"+htmlfile) - + def execute_script(self, url): + """ execute script in the current html page + """ + raise NotImplementedError + #------------------------------------------------------------------------- # # Renderer with WebKit @@ -164,10 +164,14 @@ class RendererWebkit(Renderer): def __init__(self): Renderer.__init__(self) self.window = webkit.WebView() + self.browser = WEBKIT def open(self, url): self.window.open(url) + def execute_script(self,url): + self.window.execute_script(url); + class RendererMozilla(Renderer): """ Implementation of Renderer with gtkmozembed @@ -182,10 +186,14 @@ class RendererMozilla(Renderer): self.__set_mozembed_proxy() self.window = gtkmozembed.MozEmbed() self.window.set_size_request(800, 600) + self.browser = MOZIL def open(self, url): self.window.load_url(url) + def execute_script(self,url): + self.window.load_url(url); + def __set_mozembed_proxy(self): """ Try to see if we have some proxy environment variable. @@ -194,9 +202,9 @@ class RendererMozilla(Renderer): """ try: proxy = os.environ['http_proxy'] - data = "" if proxy: host_port = None + prefs = open(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js","w+") parts = urlparse.urlparse(proxy) if not parts[0] or parts[0] == 'http': host_port = parts[1] @@ -214,19 +222,17 @@ class RendererMozilla(Renderer): 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' - data += 'user_pref("network.http.proxy.keep-alive", true);\r\n' - data += 'user_pref("network.http.proxy.version", 1.1);\r\n' - data += 'user_pref("network.http.sendRefererHeader, 0);\r\n' - fd = file(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js","w+") - fd.write(data) - fd.close() + 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") @@ -267,13 +273,11 @@ class HtmlView(PageView.PageView): 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.table.get_parent().set_shadow_type(gtk.SHADOW_NONE) self.table.set_row_spacings(1) self.table.set_col_spacings(0) - gobject.threads_init() - self.count = 0 - if (WebKit == WEBKIT) : # We use webkit self.renderer = RendererWebkit() @@ -327,6 +331,12 @@ class HtmlView(PageView.PageView): def define_actions(self): 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. + pass + def create_start_page(self): """ This command creates a default start page, and returns the URL of this @@ -365,76 +375,50 @@ class HtmlView(PageView.PageView): # GeoView # #------------------------------------------------------------------------- -class GeoView(PageView.PersonNavView): +class GeoView(HtmlView): def __init__(self,dbstate,uistate): - PageView.PersonNavView.__init__(self, _('GeoView'), dbstate, uistate) + HtmlView.__init__(self, dbstate, uistate) - global WebKit - - self.dbstate = dbstate self.usedmap = "openstreetmap" self.displaytype = "person" - self.minyear = int(9999) - self.maxyear = int(0) # Create a temporary dot file (handle,self.htmlfile) = tempfile.mkstemp(".html","GeoV", MOZEMBED_PATH ) - # needs to be solved. where to remove it ? - def __del__(self): + def on_delete(self): """ - How to do this the best way. We don't go here. - We need to suppress this temporary file. + We need to suppress the html temporary file. """ try: os.remove(self.htmlfile) except: pass - #def _quit(self, widget): - # gtk.main_quit() - - #def change_page(self): - # self.uistate.clear_filter_results() - 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. - self.notebook.disconnect(self.bootstrap_handler) - self.notebook.parent.connect("size-allocate", self.size_request_for_map) + 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) def request_resize(self): - self.size_request_for_map(self.notebook.parent,None,None) + 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 - def add_table_to_notebook( self, table): - 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) + HtmlView.set_inactive(self) self.dbstate.disconnect(self.key_active_changed) def get_stock(self): @@ -445,71 +429,8 @@ class GeoView(PageView.PersonNavView): """ return 'gramps-geo' - def call(self): - self.count = self.count+1 - gobject.idle_add(self.idle_call_js ,self.count) - - def idle_call_js(self,count): - if (self.browser == 1): - self.m.execute_script("javascript:callFromPython("+str(count)+")"); - #self.m.zoom_in(); # make text bigger - elif (self.browser == 2): - self.m.load_url("javascript:callFromPython("+str(count)+")"); - def change_map(self): - if (self.browser == 1): - self.m.execute_script("javascript:mapstraction.swap(map,'"+self.usedmap+"')"); - elif (self.browser == 2): - self.m.load_url("javascript:mapstraction.swap(map,'"+self.usedmap+"')"); - - 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. - """ - global WebKit - - self.tooltips = gtk.Tooltips() - self.tooltips.enable() - - self.notebook = gtk.Notebook() - self.notebook.set_show_border(False) - self.notebook.set_show_tabs(False) - self.bootstrap_handler = self.notebook.connect("size-request", self.init_parent_signals_for_map) - - self.table_2 = gtk.Table(1,1,False) - self.add_table_to_notebook( self.table_2) - gobject.threads_init() - self.count = 0 - self.browser = 0 - - if (WebKit == 1) : - # We use webkit - self.browser=1 - self.m = webkit.WebView() - elif (WebKit == 2) : - # We use gtkmozembed - self.browser=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 - if os.path.isdir(MOZEMBED_PATH+MOZEMBED_SUBPATH): - pass - else: - os.system("mkdir -p "+MOZEMBED_PATH+MOZEMBED_SUBPATH) - set_profile_path(MOZEMBED_PATH, MOZEMBED_SUBPATH) - self.set_mozembed_proxy() - self.m = gtkmozembed.MozEmbed() - self.m.set_size_request(800, 600) - - self.table_2.add(self.m) - self.geo_places(None,self.displaytype) - - self.m.show_all() - - return self.notebook + self.renderer.execute_script("javascript:mapstraction.swap(map,'"+self.usedmap+"')"); def ui_definition(self): """ @@ -594,7 +515,7 @@ class GeoView(PageView.PersonNavView): callback=self.event_places, tip=_("Attempt to view places on the Map for all events.")) - PageView.PersonNavView.define_actions(self) + HtmlView.define_actions(self) def goto_active_person(self,handle=None): self.geo_places(self.htmlfile,self.displaytype) @@ -636,14 +557,7 @@ class GeoView(PageView.PersonNavView): self.createHelp(htmlfile) else: self.createMapstraction(htmlfile,displaytype) - LOG.debug("geo_places : in appel page") - if (self.browser == 1): - self.m.open("file://"+htmlfile) - elif (self.browser == 2): - self.m.load_url("file://"+htmlfile) - - if (self.browser != 0): - self.m.show_all() + self.renderer.open("file://"+htmlfile) def select_OpenStreetMap_map(self,handle=None): self.usedmap = "openstreetmap" @@ -686,6 +600,7 @@ class GeoView(PageView.PersonNavView): 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': @@ -704,20 +619,18 @@ class GeoView(PageView.PersonNavView): 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' - data += 'user_pref("network.http.proxy.keep-alive", true);\r\n' - data += 'user_pref("network.http.proxy.version", 1.1);\r\n' - data += 'user_pref("network.http.sendRefererHeader, 0);\r\n' - fd = file(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js","w+") - fd.write(data) - fd.close() + 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: # tryng to remove pref.js in case of proxy change. + try: # trying to remove pref.js in case of proxy change. os.remove(MOZEMBED_PATH+MOZEMBED_SUBPATH+"/prefs.js") except: pass @@ -743,86 +656,85 @@ class GeoView(PageView.PersonNavView): self.yearint=10 LOG.debug("period = %d, intvl = %d, interval = %d" % (period, intvl, self.yearint)) - self.geo += " var step = %s;\n" % self.yearint - self.geo += " \n" - self.geo += " \n" - self.geo += "
\n" + self.mapview.write(" var step = %s;\n" % self.yearint) + self.mapview.write(" \n") + self.mapview.write(" \n") + self.mapview.write(" \n") if self.displaytype != "places": - self.geo += "