Hi all,
I'm trying to refresh a map within a gtk application everytime a button is pressed. But whatever I do, it doesn't work. Somehow I need to clear the axes. But even that doesn't work. A short hint what I'm missing would be great.
Here comes the reduced code:
#!/usr/bin/env python
import pygtk
import gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from mpl_toolkits.basemap import Basemap
class BGui:
def destroy(self, widget, data=None):
gtk.main_quit()
def change_zoom(self,button,zoom):
self.plot_map(zoom)
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
self.zoom = 1.
self.table = gtk.Table(2,1,True)
self.window.add(self.table)
self.plot_map(self.zoom)
self.table.attach(self.canvasMap, 0,1,0,1)
self.button = gtk.Button("Change Zoom")
self.button.connect("clicked", self.change_zoom, self.zoom+1.)
self.table.attach(self.button,0,1,1,2)
self.window.show_all()
def plot_map(self,zoom):
print "plot_map called with zoom:" , zoom
w = 1.2e6/zoom
h = 1.2e6/zoom
self.figMap = Figure()
self.canvasMap = FigureCanvas(self.figMap) # a gtk.DrawingArea
self.canvasMap.set_size_request(200, 200)
self.axMap = self.figMap.add_axes([0.02, 0.02, 0.96, 0.96])
#if hasattr(self,'map'):
#print "clearing axes"
#del(self.map)
self.map = Basemap(projection='tmerc', resolution='c',\
lat_0=52., lon_0=9.5, width=w,height=h,ax=self.axMap)
self.map.fillcontinents(color='green')
self.canvasMap.draw()
self.canvasMap.Refresh(True)
if __name__ == "__main__":
bah = BGui()
gtk.main()
Thanks in advance.
Cheers
Mario
···
--
Dr. Mario Mech
Institute for Geophysics and Meteorology
University of Cologne
Zuelpicher Str. 49a
50674 Cologne
Germany
t: +49 (0)221 - 470 - 1776
f: +49 (0)221 - 470 - 5198
e: mech@...2927...
w: http://www.uni-koeln.de/~mmech/