Fix sample so it works correctly when NUmeric is not installed.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@23913 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-09-25 19:43:59 +00:00
parent a8a844ded4
commit 4f62b37a95

View File

@@ -1,8 +1,30 @@
#!/usr/bin/env python2.2
from wxPython.wx import *
## Stuff to integrate FloatCanvas into wxPython Demo ## Stuff to integrate FloatCanvas into wxPython Demo
try: try:
import Numeric import Numeric
haveNumeric = True
except ImportError:
haveNumeric = False
if not haveNumeric:
errorText = """\
The FloatCanvas requires the Numeric module:
You can get it at:
http://sourceforge.net/projects/numpy
"""
def runTest(frame, nb, log):
dlg = wxMessageDialog(frame, errorText,
'Sorry', wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
overview = ""
else:
def runTest(frame, nb, log): def runTest(frame, nb, log):
""" """
This method is used by the wxPython Demo Framework for integrating This method is used by the wxPython Demo Framework for integrating
@@ -11,413 +33,410 @@ try:
win = DrawFrame(NULL, -1, "FloatCanvas Drawing Window",wxDefaultPosition,wxSize(500,500)) win = DrawFrame(NULL, -1, "FloatCanvas Drawing Window",wxDefaultPosition,wxSize(500,500))
frame.otherWin = win frame.otherWin = win
win.Show(True) win.Show(True)
except ImportError:
def runTest(frame, nb, log):
dlg = wxMessageDialog(frame, ('The FloatCanvas requires the Numeric module:\n'
'You can get it at:\n' from wxPython.lib import floatcanvas
'http://sourceforge.net/projects/numpy'), import wxPython.lib.colourdb
'Sorry', wxOK | wxICON_INFORMATION)
dlg.ShowModal() ID_ABOUT_MENU = wxNewId()
dlg.Destroy() ID_EXIT_MENU = wxNewId()
ID_ZOOM_TO_FIT_MENU = wxNewId()
from wxPython.lib import floatcanvas ID_DRAWTEST_MENU = wxNewId()
from wxPython.wx import * ID_LINETEST_MENU = wxNewId()
import wxPython.lib.colourdb ID_DRAWMAP_MENU = wxNewId()
ID_DRAWMAP2_MENU = wxNewId()
ID_ABOUT_MENU = wxNewId() ID_CLEAR_MENU = wxNewId()
ID_EXIT_MENU = wxNewId()
ID_ZOOM_TO_FIT_MENU = wxNewId() colors = wxPython.lib.colourdb.getColourList()
ID_DRAWTEST_MENU = wxNewId()
ID_LINETEST_MENU = wxNewId() LineStyles = floatcanvas.draw_object.LineStyleList.keys()
ID_DRAWMAP_MENU = wxNewId()
ID_DRAWMAP2_MENU = wxNewId() class DrawFrame(wxFrame):
ID_CLEAR_MENU = wxNewId()
"""
colors = wxPython.lib.colourdb.getColourList()
A frame used for the FloatCanvas Demo
LineStyles = floatcanvas.draw_object.LineStyleList.keys()
"""
class DrawFrame(wxFrame):
def __init__(self,parent, id,title,position,size):
""" wxFrame.__init__(self,parent, id,title,position, size)
A frame used for the FloatCanvas Demo ## Set up the MenuBar
""" MenuBar = wxMenuBar()
def __init__(self,parent, id,title,position,size): file_menu = wxMenu()
wxFrame.__init__(self,parent, id,title,position, size) file_menu.Append(ID_EXIT_MENU, "&Close","Close this frame")
EVT_MENU(self, ID_EXIT_MENU, self.OnQuit)
## Set up the MenuBar MenuBar.Append(file_menu, "&File")
MenuBar = wxMenuBar() draw_menu = wxMenu()
draw_menu.Append(ID_DRAWTEST_MENU, "&Draw Test","Run a test of drawing random components")
file_menu = wxMenu() EVT_MENU(self, ID_DRAWTEST_MENU,self.DrawTest)
file_menu.Append(ID_EXIT_MENU, "&Close","Close this frame") draw_menu.Append(ID_LINETEST_MENU, "&Line Test","Run a test of drawing random lines")
EVT_MENU(self, ID_EXIT_MENU, self.OnQuit) EVT_MENU(self, ID_LINETEST_MENU,self.LineTest)
MenuBar.Append(file_menu, "&File") draw_menu.Append(ID_DRAWMAP_MENU, "Draw &Map","Run a test of drawing a map")
EVT_MENU(self, ID_DRAWMAP_MENU,self.DrawMap)
draw_menu = wxMenu() draw_menu.Append(ID_CLEAR_MENU, "&Clear","Clear the Canvas")
draw_menu.Append(ID_DRAWTEST_MENU, "&Draw Test","Run a test of drawing random components") EVT_MENU(self, ID_CLEAR_MENU,self.Clear)
EVT_MENU(self, ID_DRAWTEST_MENU,self.DrawTest) MenuBar.Append(draw_menu, "&Draw")
draw_menu.Append(ID_LINETEST_MENU, "&Line Test","Run a test of drawing random lines")
EVT_MENU(self, ID_LINETEST_MENU,self.LineTest)
draw_menu.Append(ID_DRAWMAP_MENU, "Draw &Map","Run a test of drawing a map") view_menu = wxMenu()
EVT_MENU(self, ID_DRAWMAP_MENU,self.DrawMap) view_menu.Append(ID_ZOOM_TO_FIT_MENU, "Zoom to &Fit","Zoom to fit the window")
draw_menu.Append(ID_CLEAR_MENU, "&Clear","Clear the Canvas") EVT_MENU(self, ID_ZOOM_TO_FIT_MENU,self.ZoomToFit)
EVT_MENU(self, ID_CLEAR_MENU,self.Clear) MenuBar.Append(view_menu, "&View")
MenuBar.Append(draw_menu, "&Draw")
help_menu = wxMenu()
help_menu.Append(ID_ABOUT_MENU, "&About",
view_menu = wxMenu() "More information About this program")
view_menu.Append(ID_ZOOM_TO_FIT_MENU, "Zoom to &Fit","Zoom to fit the window") EVT_MENU(self, ID_ABOUT_MENU, self.OnAbout)
EVT_MENU(self, ID_ZOOM_TO_FIT_MENU,self.ZoomToFit) MenuBar.Append(help_menu, "&Help")
MenuBar.Append(view_menu, "&View")
self.SetMenuBar(MenuBar)
help_menu = wxMenu()
help_menu.Append(ID_ABOUT_MENU, "&About", self.CreateStatusBar()
"More information About this program") self.SetStatusText("")
EVT_MENU(self, ID_ABOUT_MENU, self.OnAbout)
MenuBar.Append(help_menu, "&Help") EVT_CLOSE(self, self.OnCloseWindow)
self.SetMenuBar(MenuBar) # Other event handlers:
EVT_RIGHT_DOWN(self, self.RightButtonEvent)
self.CreateStatusBar()
self.SetStatusText("") # Add the Canvas
self.Canvas = floatcanvas.FloatCanvas(self,-1,(500,500),
EVT_CLOSE(self, self.OnCloseWindow) ProjectionFun = 'FlatEarth',
Debug = 1,
# Other event handlers: EnclosingFrame = self,
EVT_RIGHT_DOWN(self, self.RightButtonEvent) BackgroundColor = "DARK SLATE BLUE",
UseBackground = 0,
# Add the Canvas UseToolbar = 1)
self.Canvas = floatcanvas.FloatCanvas(self,-1,(500,500), self.Show(True)
ProjectionFun = 'FlatEarth',
Debug = 1, self.object_list = []
EnclosingFrame = self,
BackgroundColor = "DARK SLATE BLUE", return None
UseBackground = 0,
UseToolbar = 1) def RightButtonEvent(self,event):
self.Show(True) print "Right Button has been clicked in DrawFrame"
print "coords are: %i, %i"%(event.GetX(),event.GetY())
self.object_list = [] event.Skip()
return None def OnAbout(self, event):
dlg = wxMessageDialog(self, "This is a small program to demonstrate\n"
def RightButtonEvent(self,event): "the use of the FloatCanvas\n",
print "Right Button has been clicked in DrawFrame" "About Me", wxOK | wxICON_INFORMATION)
print "coords are: %i, %i"%(event.GetX(),event.GetY()) dlg.ShowModal()
event.Skip() dlg.Destroy()
def OnAbout(self, event): def SetMode(self,event):
dlg = wxMessageDialog(self, "This is a small program to demonstrate\n" for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]:
"the use of the FloatCanvas\n", self.ToolBar.ToggleTool(id,0)
"About Me", wxOK | wxICON_INFORMATION) self.ToolBar.ToggleTool(event.GetId(),1)
dlg.ShowModal() if event.GetId() == ID_ZOOM_IN_BUTTON:
dlg.Destroy() self.Canvas.SetGUIMode("ZoomIn")
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
def SetMode(self,event): self.Canvas.SetGUIMode("ZoomOut")
for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]: elif event.GetId() == ID_MOVE_MODE_BUTTON:
self.ToolBar.ToggleTool(id,0) self.Canvas.SetGUIMode("Move")
self.ToolBar.ToggleTool(event.GetId(),1)
if event.GetId() == ID_ZOOM_IN_BUTTON: def ZoomToFit(self,event):
self.Canvas.SetGUIMode("ZoomIn") self.Canvas.ZoomToBB()
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
self.Canvas.SetGUIMode("ZoomOut") def Clear(self,event = None):
elif event.GetId() == ID_MOVE_MODE_BUTTON: self.Canvas.RemoveObjects(self.object_list)
self.Canvas.SetGUIMode("Move") self.object_list = []
self.Canvas.Draw()
def ZoomToFit(self,event):
self.Canvas.ZoomToBB() def OnQuit(self,event):
self.Close(True)
def Clear(self,event = None):
self.Canvas.RemoveObjects(self.object_list) def OnCloseWindow(self, event):
self.object_list = [] self.Destroy()
self.Canvas.Draw()
def DrawTest(self,event):
def OnQuit(self,event): wxGetApp().Yield()
self.Close(True) import random
import RandomArray
def OnCloseWindow(self, event): Range = (-10,10)
self.Destroy()
Canvas = self.Canvas
def DrawTest(self,event): object_list = self.object_list
wxGetApp().Yield()
import random ## Random tests of everything:
import RandomArray
Range = (-10,10) # Rectangles
for i in range(5):
Canvas = self.Canvas x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
object_list = self.object_list lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
## Random tests of everything: h = random.randint(1,5)
w = random.randint(1,5)
# Rectangles object_list.append(Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf]))
for i in range(5):
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) # Ellipses
lw = random.randint(1,5) for i in range(5):
cf = random.randint(0,len(colors)-1) x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
h = random.randint(1,5) lw = random.randint(1,5)
w = random.randint(1,5) cf = random.randint(0,len(colors)-1)
object_list.append(Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf])) h = random.randint(1,5)
w = random.randint(1,5)
# Ellipses object_list.append(Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf]))
for i in range(5):
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) # Dots
lw = random.randint(1,5) for i in range(5):
cf = random.randint(0,len(colors)-1) x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
h = random.randint(1,5) D = random.randint(1,50)
w = random.randint(1,5) lw = random.randint(1,5)
object_list.append(Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf])) cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
# Dots object_list.append(Canvas.AddDot(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf]))
for i in range(5):
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) # Circles
D = random.randint(1,50) for i in range(5):
lw = random.randint(1,5) x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
cf = random.randint(0,len(colors)-1) D = random.randint(1,5)
cl = random.randint(0,len(colors)-1) lw = random.randint(1,5)
object_list.append(Canvas.AddDot(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])) cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
# Circles object_list.append(Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf]))
for i in range(5): self.object_list.append(self.Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackGround = None,Position = "cc"))
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5) # Lines
lw = random.randint(1,5) for i in range(5):
cf = random.randint(0,len(colors)-1) points = []
cl = random.randint(0,len(colors)-1) for j in range(random.randint(2,10)):
object_list.append(Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])) point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
self.object_list.append(self.Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackGround = None,Position = "cc")) points.append(point)
lw = random.randint(1,10)
# Lines cf = random.randint(0,len(colors)-1)
for i in range(5): cl = random.randint(0,len(colors)-1)
points = [] self.object_list.append(self.Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl]))
for j in range(random.randint(2,10)):
point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1])) # Polygons
points.append(point) for i in range(3):
lw = random.randint(1,10) points = []
cf = random.randint(0,len(colors)-1) for j in range(random.randint(2,6)):
cl = random.randint(0,len(colors)-1) point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
self.object_list.append(self.Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl])) points.append(point)
lw = random.randint(1,6)
# Polygons cf = random.randint(0,len(colors)-1)
for i in range(3): cl = random.randint(0,len(colors)-1)
points = [] self.object_list.append(self.Canvas.AddPolygon(points,
for j in range(random.randint(2,6)): LineWidth = lw,
point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) LineColor = colors[cl],
points.append(point) FillColor = colors[cf],
lw = random.randint(1,6) FillStyle = 'Solid'))
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
self.object_list.append(self.Canvas.AddPolygon(points, ## Pointset
LineWidth = lw, for i in range(4):
LineColor = colors[cl], points = []
FillColor = colors[cf], points = RandomArray.uniform(Range[0],Range[1],(100,2))
FillStyle = 'Solid')) cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
self.object_list.append(self.Canvas.AddPointSet(points, Color = colors[cf], Diameter = D))
## Pointset
for i in range(4): # Text
points = [] String = "Some text"
points = RandomArray.uniform(Range[0],Range[1],(100,2)) for i in range(10):
cf = random.randint(0,len(colors)-1) ts = random.randint(10,40)
D = random.randint(1,4) cf = random.randint(0,len(colors)-1)
self.object_list.append(self.Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)) x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
self.object_list.append(self.Canvas.AddText(String,x,y,Size = ts,ForeGround = colors[cf],Position = "cc"))
# Text
String = "Some text" self.Canvas.ZoomToBB()
for i in range(10):
ts = random.randint(10,40) def DrawMap(self,event = None):
cf = random.randint(0,len(colors)-1) wxGetApp().Yield()
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) import os, time
self.object_list.append(self.Canvas.AddText(String,x,y,Size = ts,ForeGround = colors[cf],Position = "cc")) ## Test of Actual Map Data
self.Clear()
self.Canvas.ZoomToBB() start = time.clock()
Shorelines = Read_MapGen(os.path.join("data",'world.dat'),stats = 0)
def DrawMap(self,event = None): print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) )
wxGetApp().Yield() start = time.clock()
import os, time for segment in Shorelines:
## Test of Actual Map Data self.object_list.append(self.Canvas.AddLine(segment))
self.Clear() print "It took %f seconds to add %i shorelines"%(time.clock() - start,len(Shorelines) )
start = time.clock() start = time.clock()
Shorelines = Read_MapGen(os.path.join("data",'world.dat'),stats = 0) self.Canvas.ZoomToBB()
print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) ) print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
start = time.clock()
for segment in Shorelines: ## def LineTest(self,event = None):
self.object_list.append(self.Canvas.AddLine(segment)) ## wxGetApp().Yield()
print "It took %f seconds to add %i shorelines"%(time.clock() - start,len(Shorelines) ) ## import os, time
start = time.clock() ## import random
self.Canvas.ZoomToBB() ## Range = (-10,10)
print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) ) ## ## Test of drawing lots of lines
## self.Clear()
## def LineTest(self,event = None): ## start = time.clock()
## wxGetApp().Yield() ## linepoints = []
## import os, time ## linecolors = []
## import random ## linewidths = []
## Range = (-10,10) ## linestyles = []
## ## Test of drawing lots of lines ## for i in range(500):
## self.Clear() ## points = (random.randint(Range[0],Range[1]),
## start = time.clock() ## random.randint(Range[0],Range[1]))
## linepoints = [] ## linepoints.append(points)
## linecolors = [] ## points = (random.randint(Range[0],Range[1]),
## linewidths = [] ## random.randint(Range[0],Range[1]))
## linestyles = [] ## linepoints.append(points)
## for i in range(500): ## linewidths.append(random.randint(1,10) )
## points = (random.randint(Range[0],Range[1]), ## linecolors.append(colors[random.randint(0,len(colors)-1) ])
## random.randint(Range[0],Range[1])) ## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
## linepoints.append(points)
## points = (random.randint(Range[0],Range[1]), ## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles))
## random.randint(Range[0],Range[1])) ## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
## linepoints.append(points) ## start = time.clock()
## linewidths.append(random.randint(1,10) ) ## self.Canvas.ZoomToBB()
## linecolors.append(colors[random.randint(0,len(colors)-1) ]) ## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
def LineTest(self,event = None):
## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles)) wxGetApp().Yield()
## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) ) import os, time
## start = time.clock() import random
## self.Canvas.ZoomToBB() Range = (-10,10)
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) ) ## Test of drawing lots of lines
self.Clear()
def LineTest(self,event = None): start = time.clock()
wxGetApp().Yield() linepoints = []
import os, time linecolors = []
import random linewidths = []
Range = (-10,10) for i in range(2000):
## Test of drawing lots of lines points = (random.randint(Range[0],Range[1]),
self.Clear() random.randint(Range[0],Range[1]),
start = time.clock() random.randint(Range[0],Range[1]),
linepoints = [] random.randint(Range[0],Range[1]))
linecolors = [] linepoints.append(points)
linewidths = [] linewidths.append(random.randint(1,10) )
for i in range(2000): linecolors.append(random.randint(0,len(colors)-1) )
points = (random.randint(Range[0],Range[1]), for (points,color,width) in zip(linepoints,linecolors,linewidths):
random.randint(Range[0],Range[1]), self.object_list.append(self.Canvas.AddLine((points[0:2],points[2:4]), LineWidth = width, LineColor = colors[color]))
random.randint(Range[0],Range[1]), print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
random.randint(Range[0],Range[1])) start = time.clock()
linepoints.append(points) self.Canvas.ZoomToBB()
linewidths.append(random.randint(1,10) ) print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
linecolors.append(random.randint(0,len(colors)-1) )
for (points,color,width) in zip(linepoints,linecolors,linewidths): class DemoApp(wxApp):
self.object_list.append(self.Canvas.AddLine((points[0:2],points[2:4]), LineWidth = width, LineColor = colors[color])) """
print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) ) How the demo works:
start = time.clock()
self.Canvas.ZoomToBB() Under the Draw menu, there are three options:
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
*Draw Test: will put up a picture of a bunch of randomly generated
class DemoApp(wxApp): objects, of each kind supported.
"""
How the demo works: *Draw Map: will draw a map of the world. Be patient, it is a big map,
with a lot of data, and will take a while to load and draw (about 10 sec
Under the Draw menu, there are three options: on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
performance is not very good for large drawings.
*Draw Test: will put up a picture of a bunch of randomly generated
objects, of each kind supported. *Clear: Clears the Canvas.
*Draw Map: will draw a map of the world. Be patient, it is a big map, Once you have a picture drawn, you can zoom in and out and move about
with a lot of data, and will take a while to load and draw (about 10 sec the picture. There is a tool bar with three tools that can be
on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the selected.
performance is not very good for large drawings.
The magnifying glass with the plus is the zoom in tool. Once selected,
*Clear: Clears the Canvas. if you click the image, it will zoom in, centered on where you
clicked. If you click and drag the mouse, you will get a rubber band
Once you have a picture drawn, you can zoom in and out and move about box, and the image will zoom to fit that box when you release it.
the picture. There is a tool bar with three tools that can be
selected. The magnifying glass with the minus is the zoom out tool. Once selected,
if you click the image, it will zoom out, centered on where you
The magnifying glass with the plus is the zoom in tool. Once selected, clicked. (note that this takes a while when you are looking at the map,
if you click the image, it will zoom in, centered on where you as it has a LOT of lines to be drawn. The image is double buffered, so
clicked. If you click and drag the mouse, you will get a rubber band you don't see the drawing in progress)
box, and the image will zoom to fit that box when you release it.
The hand is the move tool. Once selected, if you click and drag on the
The magnifying glass with the minus is the zoom out tool. Once selected, image, it will move so that the part you clicked on ends up where you
if you click the image, it will zoom out, centered on where you release the mouse. Nothing is changed while you are dragging. The
clicked. (note that this takes a while when you are looking at the map, drawing is too slow for that.
as it has a LOT of lines to be drawn. The image is double buffered, so
you don't see the drawing in progress) I'd like the cursor to change as you change tools, but the stock
wxCursors didn't include anything I liked, so I stuck with the
The hand is the move tool. Once selected, if you click and drag on the pointer. Pleae let me know if you have any nice cursor images for me to
image, it will move so that the part you clicked on ends up where you use.
release the mouse. Nothing is changed while you are dragging. The
drawing is too slow for that.
Any bugs, comments, feedback, questions, and especially code are welcome:
I'd like the cursor to change as you change tools, but the stock
wxCursors didn't include anything I liked, so I stuck with the -Chris Barker
pointer. Pleae let me know if you have any nice cursor images for me to
use. Chris.Barker@noaa.gov
"""
Any bugs, comments, feedback, questions, and especially code are welcome:
def OnInit(self):
-Chris Barker frame = DrawFrame(NULL, -1, "FloatCanvas Demo App",wxDefaultPosition,wxSize(700,700))
Chris.Barker@noaa.gov self.SetTopWindow(frame)
""" return True
def OnInit(self): def Read_MapGen(filename,stats = 0,AllLines=0):
frame = DrawFrame(NULL, -1, "FloatCanvas Demo App",wxDefaultPosition,wxSize(700,700)) """
This function reads a MapGen Format file, and
self.SetTopWindow(frame) returns a list of NumPy arrays with the line segments in them.
return True Each NumPy array in the list is an NX2 array of Python Floats.
def Read_MapGen(filename,stats = 0,AllLines=0): The demo should have come with a file, "world.dat" that is the
""" shorelines of the whole world, in MapGen format.
This function reads a MapGen Format file, and
returns a list of NumPy arrays with the line segments in them. """
import string
Each NumPy array in the list is an NX2 array of Python Floats. from Numeric import array
file = open(filename,'rt')
The demo should have come with a file, "world.dat" that is the data = file.readlines()
shorelines of the whole world, in MapGen format. data = map(string.strip,data)
""" Shorelines = []
import string segment = []
from Numeric import array for line in data:
file = open(filename,'rt') if line:
data = file.readlines() if line == "# -b": #New segment begining
data = map(string.strip,data) if segment: Shorelines.append(array(segment))
segment = []
Shorelines = [] else:
segment = [] segment.append(map(float,string.split(line)))
for line in data: if segment: Shorelines.append(array(segment))
if line:
if line == "# -b": #New segment begining if stats:
if segment: Shorelines.append(array(segment)) NumSegments = len(Shorelines)
segment = [] NumPoints = 0
else: for segment in Shorelines:
segment.append(map(float,string.split(line))) NumPoints = NumPoints + len(segment)
if segment: Shorelines.append(array(segment)) AvgPoints = NumPoints / NumSegments
print "Number of Segments: ", NumSegments
if stats: print "Average Number of Points per segment: ",AvgPoints
NumSegments = len(Shorelines) if AllLines:
NumPoints = 0 Lines = []
for segment in Shorelines: for segment in Shorelines:
NumPoints = NumPoints + len(segment) Lines.append(segment[0])
AvgPoints = NumPoints / NumSegments for point in segment[1:-1]:
print "Number of Segments: ", NumSegments Lines.append(point)
print "Average Number of Points per segment: ",AvgPoints Lines.append(point)
if AllLines: Lines.append(segment[-1])
Lines = [] #print Shorelines
for segment in Shorelines: #for point in Lines: print point
Lines.append(segment[0]) return Lines
for point in segment[1:-1]: else:
Lines.append(point) return Shorelines
Lines.append(point)
Lines.append(segment[-1]) ## for the wxPython demo:
#print Shorelines overview = floatcanvas.FloatCanvas.__doc__
#for point in Lines: print point
return Lines
else:
return Shorelines
## for the wxPython demo:
overview = floatcanvas.FloatCanvas.__doc__
if __name__ == "__main__": if __name__ == "__main__":
app = DemoApp(0) if not haveNumeric:
app.MainLoop() print errorText
else:
app = DemoApp(0)
app.MainLoop()