From: <js...@us...> - 2008-11-20 12:27:48
|
Revision: 6418 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6418&view=rev Author: jswhit Date: 2008-11-20 12:27:42 +0000 (Thu, 20 Nov 2008) Log Message: ----------- added new embedding_map_in_wx.py example, courtesy of Mauro Cavalcanti. Modified Paths: -------------- trunk/toolkits/basemap/Changelog trunk/toolkits/basemap/MANIFEST.in trunk/toolkits/basemap/README trunk/toolkits/basemap/examples/README trunk/toolkits/basemap/examples/run_all.py Added Paths: ----------- trunk/toolkits/basemap/examples/embedding_map_in_wx.py Modified: trunk/toolkits/basemap/Changelog =================================================================== --- trunk/toolkits/basemap/Changelog 2008-11-19 15:16:26 UTC (rev 6417) +++ trunk/toolkits/basemap/Changelog 2008-11-20 12:27:42 UTC (rev 6418) @@ -1,4 +1,6 @@ version 0.99.2 (not yet released) + * Added embedding_map_in_wx.py example (courtesy of + Mauro Cavalcanti). * Added masked array support to shiftgrid function (thanks to Jesper Larsen). * defer import of netcdf stuff till it is needed (in NetCDFFile Modified: trunk/toolkits/basemap/MANIFEST.in =================================================================== --- trunk/toolkits/basemap/MANIFEST.in 2008-11-19 15:16:26 UTC (rev 6417) +++ trunk/toolkits/basemap/MANIFEST.in 2008-11-20 12:27:42 UTC (rev 6418) @@ -11,6 +11,7 @@ include setup.cfg include setupegg.py include src/* +include examples/embedding_map_in_wx.py include examples/cubed_sphere.py include examples/simpletest.py include examples/hires.py Modified: trunk/toolkits/basemap/README =================================================================== --- trunk/toolkits/basemap/README 2008-11-19 15:16:26 UTC (rev 6417) +++ trunk/toolkits/basemap/README 2008-11-20 12:27:42 UTC (rev 6418) @@ -122,5 +122,6 @@ Jesper Larsen Ryan May David Huard +Mauro Cavalcanti for valuable contributions. Modified: trunk/toolkits/basemap/examples/README =================================================================== --- trunk/toolkits/basemap/examples/README 2008-11-19 15:16:26 UTC (rev 6417) +++ trunk/toolkits/basemap/examples/README 2008-11-20 12:27:42 UTC (rev 6418) @@ -117,3 +117,6 @@ run_all.py is a driver script that runs all the examples except fcstmaps.py, testgdal.py, geos_demo_2.py, warpimage.py, and pnganim.py (which rely on external dependencies and/or an internet connection). + +embedding_map_in_wx.py is an example of how to embed Basemap using wx or wxagg +in a GUI application. Added: trunk/toolkits/basemap/examples/embedding_map_in_wx.py =================================================================== --- trunk/toolkits/basemap/examples/embedding_map_in_wx.py (rev 0) +++ trunk/toolkits/basemap/examples/embedding_map_in_wx.py 2008-11-20 12:27:42 UTC (rev 6418) @@ -0,0 +1,75 @@ +#!/usr/bin/env python +""" +An example of how to use wx or wxagg in an application with the Basemap module +""" + +from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas +from matplotlib.backends.backend_wx import NavigationToolbar2Wx +from matplotlib.figure import Figure + +from mpl_toolkits.basemap import Basemap + +from wx import * + +class CanvasFrame(Frame): + + def __init__(self): + Frame.__init__(self,None,-1, + 'CanvasFrame',size=(550,350)) + + self.SetBackgroundColour(NamedColor("WHITE")) + + self.figure = Figure() + + self.canvas = FigureCanvas(self, -1, self.figure) + self.ax = self.figure.add_subplot(111) + + self.sizer = BoxSizer(VERTICAL) + self.sizer.Add(self.canvas, 1, LEFT | TOP | GROW) + self.SetSizer(self.sizer) + self.Fit() + + self.add_toolbar() # comment this out for no toolbar + + self.plot_map() + + def add_toolbar(self): + self.toolbar = NavigationToolbar2Wx(self.canvas) + self.toolbar.Realize() + if Platform == '__WXMAC__': + # Mac platform (OSX 10.3, MacPython) does not seem to cope with + # having a toolbar in a sizer. This work-around gets the buttons + # back, but at the expense of having the toolbar at the top + self.SetToolBar(self.toolbar) + else: + # On Windows platform, default window size is incorrect, so set + # toolbar width to figure width. + tw, th = self.toolbar.GetSizeTuple() + fw, fh = self.canvas.GetSizeTuple() + # By adding toolbar in sizer, we are able to put it at the bottom + # of the frame - so appearance is closer to GTK version. + # As noted above, doesn't work for Mac. + self.toolbar.SetSize(Size(fw, th)) + self.sizer.Add(self.toolbar, 0, LEFT | EXPAND) + # update the axes menu on the toolbar + self.toolbar.update() + + def plot_map(self): + map = Basemap(ax=self.ax) + map.drawcoastlines() + map.drawcountries() + map.drawmapboundary() + map.fillcontinents(color='lime', lake_color='aqua') + map.drawmapboundary(fill_color='aqua') + self.figure.canvas.draw() + +class App(App): + + def OnInit(self): + 'Create the main window and insert the custom frame' + frame = CanvasFrame() + frame.Show(True) + return True + +app = App(0) +app.MainLoop() Modified: trunk/toolkits/basemap/examples/run_all.py =================================================================== --- trunk/toolkits/basemap/examples/run_all.py 2008-11-19 15:16:26 UTC (rev 6417) +++ trunk/toolkits/basemap/examples/run_all.py 2008-11-20 12:27:42 UTC (rev 6418) @@ -6,6 +6,7 @@ test_files.remove('pnganim.py') test_files.remove('geos_demo_2.py') test_files.remove('plotsst.py') +test_files.remove('embedding_map_in_wx.py') print test_files py_path = os.environ.get('PYTHONPATH') if py_path is None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |