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:
@@ -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,33 +33,26 @@ 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'
|
|
||||||
'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()
|
self.Canvas.ZoomToBB()
|
||||||
print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
|
print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
|
||||||
|
|
||||||
## def LineTest(self,event = None):
|
## def LineTest(self,event = None):
|
||||||
## wxGetApp().Yield()
|
## wxGetApp().Yield()
|
||||||
## import os, time
|
## import os, time
|
||||||
## import random
|
## import random
|
||||||
## Range = (-10,10)
|
## Range = (-10,10)
|
||||||
## ## Test of drawing lots of lines
|
## ## Test of drawing lots of lines
|
||||||
## self.Clear()
|
## self.Clear()
|
||||||
## start = time.clock()
|
## start = time.clock()
|
||||||
## linepoints = []
|
## linepoints = []
|
||||||
## linecolors = []
|
## linecolors = []
|
||||||
## linewidths = []
|
## linewidths = []
|
||||||
## linestyles = []
|
## linestyles = []
|
||||||
## for i in range(500):
|
## for i in range(500):
|
||||||
## points = (random.randint(Range[0],Range[1]),
|
## points = (random.randint(Range[0],Range[1]),
|
||||||
## random.randint(Range[0],Range[1]))
|
## random.randint(Range[0],Range[1]))
|
||||||
## linepoints.append(points)
|
## linepoints.append(points)
|
||||||
## points = (random.randint(Range[0],Range[1]),
|
## points = (random.randint(Range[0],Range[1]),
|
||||||
## random.randint(Range[0],Range[1]))
|
## random.randint(Range[0],Range[1]))
|
||||||
## linepoints.append(points)
|
## linepoints.append(points)
|
||||||
## linewidths.append(random.randint(1,10) )
|
## linewidths.append(random.randint(1,10) )
|
||||||
## linecolors.append(colors[random.randint(0,len(colors)-1) ])
|
## linecolors.append(colors[random.randint(0,len(colors)-1) ])
|
||||||
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
|
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
|
||||||
|
|
||||||
## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles))
|
## 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) )
|
## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
|
||||||
## start = time.clock()
|
## start = time.clock()
|
||||||
## self.Canvas.ZoomToBB()
|
## self.Canvas.ZoomToBB()
|
||||||
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
||||||
|
|
||||||
def LineTest(self,event = None):
|
def LineTest(self,event = None):
|
||||||
wxGetApp().Yield()
|
wxGetApp().Yield()
|
||||||
@@ -305,7 +320,7 @@ class DrawFrame(wxFrame):
|
|||||||
self.Canvas.ZoomToBB()
|
self.Canvas.ZoomToBB()
|
||||||
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
||||||
|
|
||||||
class DemoApp(wxApp):
|
class DemoApp(wxApp):
|
||||||
"""
|
"""
|
||||||
How the demo works:
|
How the demo works:
|
||||||
|
|
||||||
@@ -362,7 +377,7 @@ class DemoApp(wxApp):
|
|||||||
|
|
||||||
return True
|
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
|
This function reads a MapGen Format file, and
|
||||||
returns a list of NumPy arrays with the line segments in them.
|
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:
|
else:
|
||||||
return Shorelines
|
return Shorelines
|
||||||
|
|
||||||
## for the wxPython demo:
|
## for the wxPython demo:
|
||||||
overview = floatcanvas.FloatCanvas.__doc__
|
overview = floatcanvas.FloatCanvas.__doc__
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
if not haveNumeric:
|
||||||
|
print errorText
|
||||||
|
else:
|
||||||
app = DemoApp(0)
|
app = DemoApp(0)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user