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
try:
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):
"""
This method is used by the wxPython Demo Framework for integrating
@@ -11,33 +33,26 @@ try:
win = DrawFrame(NULL, -1, "FloatCanvas Drawing Window",wxDefaultPosition,wxSize(500,500))
frame.otherWin = win
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'
'http://sourceforge.net/projects/numpy'),
'Sorry', wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
from wxPython.lib import floatcanvas
from wxPython.wx import *
import wxPython.lib.colourdb
ID_ABOUT_MENU = wxNewId()
ID_EXIT_MENU = wxNewId()
ID_ZOOM_TO_FIT_MENU = wxNewId()
ID_DRAWTEST_MENU = wxNewId()
ID_LINETEST_MENU = wxNewId()
ID_DRAWMAP_MENU = wxNewId()
ID_DRAWMAP2_MENU = wxNewId()
ID_CLEAR_MENU = wxNewId()
colors = wxPython.lib.colourdb.getColourList()
from wxPython.lib import floatcanvas
import wxPython.lib.colourdb
LineStyles = floatcanvas.draw_object.LineStyleList.keys()
ID_ABOUT_MENU = wxNewId()
ID_EXIT_MENU = wxNewId()
ID_ZOOM_TO_FIT_MENU = wxNewId()
ID_DRAWTEST_MENU = wxNewId()
ID_LINETEST_MENU = wxNewId()
ID_DRAWMAP_MENU = wxNewId()
ID_DRAWMAP2_MENU = wxNewId()
ID_CLEAR_MENU = wxNewId()
class DrawFrame(wxFrame):
colors = wxPython.lib.colourdb.getColourList()
LineStyles = floatcanvas.draw_object.LineStyleList.keys()
class DrawFrame(wxFrame):
"""
@@ -250,34 +265,34 @@ class DrawFrame(wxFrame):
self.Canvas.ZoomToBB()
print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
## def LineTest(self,event = None):
## wxGetApp().Yield()
## import os, time
## import random
## Range = (-10,10)
## ## Test of drawing lots of lines
## self.Clear()
## start = time.clock()
## linepoints = []
## linecolors = []
## linewidths = []
## linestyles = []
## for i in range(500):
## points = (random.randint(Range[0],Range[1]),
## random.randint(Range[0],Range[1]))
## linepoints.append(points)
## points = (random.randint(Range[0],Range[1]),
## random.randint(Range[0],Range[1]))
## linepoints.append(points)
## linewidths.append(random.randint(1,10) )
## linecolors.append(colors[random.randint(0,len(colors)-1) ])
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
## def LineTest(self,event = None):
## wxGetApp().Yield()
## import os, time
## import random
## Range = (-10,10)
## ## Test of drawing lots of lines
## self.Clear()
## start = time.clock()
## linepoints = []
## linecolors = []
## linewidths = []
## linestyles = []
## for i in range(500):
## points = (random.randint(Range[0],Range[1]),
## random.randint(Range[0],Range[1]))
## linepoints.append(points)
## points = (random.randint(Range[0],Range[1]),
## random.randint(Range[0],Range[1]))
## linepoints.append(points)
## linewidths.append(random.randint(1,10) )
## linecolors.append(colors[random.randint(0,len(colors)-1) ])
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles))
## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
## start = time.clock()
## self.Canvas.ZoomToBB()
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles))
## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
## start = time.clock()
## self.Canvas.ZoomToBB()
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
def LineTest(self,event = None):
wxGetApp().Yield()
@@ -305,7 +320,7 @@ class DrawFrame(wxFrame):
self.Canvas.ZoomToBB()
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
class DemoApp(wxApp):
class DemoApp(wxApp):
"""
How the demo works:
@@ -362,7 +377,7 @@ class DemoApp(wxApp):
return True
def Read_MapGen(filename,stats = 0,AllLines=0):
def Read_MapGen(filename,stats = 0,AllLines=0):
"""
This function reads a MapGen Format file, and
returns a list of NumPy arrays with the line segments in them.
@@ -412,12 +427,16 @@ def Read_MapGen(filename,stats = 0,AllLines=0):
else:
return Shorelines
## for the wxPython demo:
overview = floatcanvas.FloatCanvas.__doc__
## for the wxPython demo:
overview = floatcanvas.FloatCanvas.__doc__
if __name__ == "__main__":
if not haveNumeric:
print errorText
else:
app = DemoApp(0)
app.MainLoop()