FloatCanvas patch from Chris Barker.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29711 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,92 +1,39 @@
|
|||||||
#!/usr/bin/env python2.3
|
#!/usr/bin/env python2.3
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
##First, make sure Numeric or numarray can be imported.
|
||||||
try:
|
try:
|
||||||
import Numeric
|
import Numeric
|
||||||
import RandomArray
|
import RandomArray
|
||||||
haveNumeric = True
|
haveNumeric = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
# Numeric isn't there, let's try numarray
|
||||||
try:
|
try:
|
||||||
import numarray as Numeric
|
import numarray as Numeric
|
||||||
import numarray.random_array as RandomArray
|
import numarray.random_array as RandomArray
|
||||||
haveNumeric = True
|
haveNumeric = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
# numarray isn't there either
|
||||||
haveNumeric = False
|
haveNumeric = False
|
||||||
|
errorText = (
|
||||||
if not haveNumeric:
|
"The FloatCanvas requires either the Numeric or numarray module\n\n"
|
||||||
errorText = """
|
"You can get them at:\n"
|
||||||
The FloatCanvas requires either the Numeric or Numarray module:
|
"http://sourceforge.net/projects/numpy\n\n"
|
||||||
You can get them at:
|
"NOTE: The Numeric module is substantially faster than numarray for this\n"
|
||||||
http://sourceforge.net/projects/numpy
|
"purpose, if you have lots of objects\n"
|
||||||
|
)
|
||||||
NOTE: The Numeric module is substantially faster than numarray for this
|
|
||||||
purpose, if you have lot's of objects
|
|
||||||
"""
|
|
||||||
|
|
||||||
StartUpDemo = "all"
|
|
||||||
if __name__ == "__main__": # parse options if run stand-alone
|
|
||||||
# check options:
|
|
||||||
import sys, getopt
|
|
||||||
optlist, args = getopt.getopt(sys.argv[1:],'l',["local","all","text","map","stext","hit","hitf","animate","speed","temp","props"])
|
|
||||||
|
|
||||||
for opt in optlist:
|
|
||||||
if opt[0] == "--all":
|
|
||||||
StartUpDemo = "all"
|
|
||||||
elif opt[0] == "--text":
|
|
||||||
StartUpDemo = "text"
|
|
||||||
elif opt[0] == "--map":
|
|
||||||
StartUpDemo = "map"
|
|
||||||
elif opt[0] == "--stext":
|
|
||||||
StartUpDemo = "stext"
|
|
||||||
elif opt[0] == "--hit":
|
|
||||||
StartUpDemo = "hit"
|
|
||||||
elif opt[0] == "--hitf":
|
|
||||||
StartUpDemo = "hitf"
|
|
||||||
elif opt[0] == "--animate":
|
|
||||||
StartUpDemo = "animate"
|
|
||||||
elif opt[0] == "--speed":
|
|
||||||
StartUpDemo = "speed"
|
|
||||||
elif opt[0] == "--temp":
|
|
||||||
StartUpDemo = "temp"
|
|
||||||
elif opt[0] == "--props":
|
|
||||||
StartUpDemo = "props"
|
|
||||||
import wx
|
|
||||||
import time, random
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
class TestPanel(wx.Panel):
|
def BuildDrawFrame(): # this gets called when needed, rather than on import
|
||||||
def __init__(self, parent, log):
|
|
||||||
self.log = log
|
|
||||||
wx.Panel.__init__(self, parent, -1)
|
|
||||||
|
|
||||||
b = wx.Button(self, -1, "Show the FloatCanvas sample", (50,50))
|
|
||||||
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
||||||
|
|
||||||
|
|
||||||
def OnButton(self, evt):
|
|
||||||
if not haveNumeric:
|
|
||||||
dlg = wx.MessageDialog(self, errorText, 'Sorry', wx.OK |
|
|
||||||
wx.ICON_INFORMATION)
|
|
||||||
dlg.ShowModal()
|
|
||||||
dlg.Destroy()
|
|
||||||
|
|
||||||
else:
|
|
||||||
win = DrawFrame(None, -1, "FloatCanvas Drawing Window",wx.DefaultPosition,(500,500))
|
|
||||||
win.Show(True)
|
|
||||||
win.DrawTest()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
if haveNumeric:
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from floatcanvas import NavCanvas, FloatCanvas
|
from floatcanvas import NavCanvas, FloatCanvas
|
||||||
except ImportError: # if it's not there locally, try the wxPython lib.
|
except ImportError: # if it's not there locally, try the wxPython lib.
|
||||||
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
||||||
|
|
||||||
import wxPython.lib.colourdb
|
import wx.lib.colourdb
|
||||||
|
import time, random
|
||||||
|
|
||||||
class DrawFrame(wx.Frame):
|
class DrawFrame(wx.Frame):
|
||||||
|
|
||||||
@@ -133,6 +80,9 @@ if haveNumeric:
|
|||||||
self.Bind(wx.EVT_MENU, self.SpeedTest, item)
|
self.Bind(wx.EVT_MENU, self.SpeedTest, item)
|
||||||
item = draw_menu.Append(-1, "Change &Properties","Run a test of Changing Object Properties")
|
item = draw_menu.Append(-1, "Change &Properties","Run a test of Changing Object Properties")
|
||||||
self.Bind(wx.EVT_MENU, self.PropertiesChangeTest, item)
|
self.Bind(wx.EVT_MENU, self.PropertiesChangeTest, item)
|
||||||
|
item = draw_menu.Append(-1, "&Arrows","Run a test of Arrows")
|
||||||
|
self.Bind(wx.EVT_MENU, self.ArrowTest, item)
|
||||||
|
|
||||||
MenuBar.Append(draw_menu, "&Tests")
|
MenuBar.Append(draw_menu, "&Tests")
|
||||||
|
|
||||||
view_menu = wx.Menu()
|
view_menu = wx.Menu()
|
||||||
@@ -164,8 +114,8 @@ if haveNumeric:
|
|||||||
self.EventsAreBound = False
|
self.EventsAreBound = False
|
||||||
|
|
||||||
## getting all the colors and linestyles for random objects
|
## getting all the colors and linestyles for random objects
|
||||||
wxPython.lib.colourdb.updateColourDB()
|
wx.lib.colourdb.updateColourDB()
|
||||||
self.colors = wxPython.lib.colourdb.getColourList()
|
self.colors = wx.lib.colourdb.getColourList()
|
||||||
#self.LineStyles = FloatCanvas.DrawObject.LineStyleList.keys()
|
#self.LineStyles = FloatCanvas.DrawObject.LineStyleList.keys()
|
||||||
|
|
||||||
|
|
||||||
@@ -190,7 +140,20 @@ if haveNumeric:
|
|||||||
self.EventsAreBound = True
|
self.EventsAreBound = True
|
||||||
|
|
||||||
def UnBindAllMouseEvents(self):
|
def UnBindAllMouseEvents(self):
|
||||||
## Here is how you catch FloatCanvas mouse events
|
## Here is how you unbind FloatCanvas mouse events
|
||||||
|
FloatCanvas.EVT_LEFT_DOWN(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_LEFT_UP(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_LEFT_DCLICK(self.Canvas, None)
|
||||||
|
|
||||||
|
FloatCanvas.EVT_MIDDLE_DOWN(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_MIDDLE_UP(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_MIDDLE_DCLICK(self.Canvas, None )
|
||||||
|
|
||||||
|
FloatCanvas.EVT_RIGHT_DOWN(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_RIGHT_UP(self.Canvas, None )
|
||||||
|
FloatCanvas.EVT_RIGHT_DCLICK(self.Canvas, None )
|
||||||
|
|
||||||
|
FloatCanvas.EVT_MOUSEWHEEL(self.Canvas, None )
|
||||||
FloatCanvas.EVT_LEFT_DOWN(self.Canvas, None )
|
FloatCanvas.EVT_LEFT_DOWN(self.Canvas, None )
|
||||||
FloatCanvas.EVT_LEFT_UP(self.Canvas, None )
|
FloatCanvas.EVT_LEFT_UP(self.Canvas, None )
|
||||||
FloatCanvas.EVT_LEFT_DCLICK(self.Canvas, None)
|
FloatCanvas.EVT_LEFT_DCLICK(self.Canvas, None)
|
||||||
@@ -250,10 +213,18 @@ if haveNumeric:
|
|||||||
def OnWheel(self, event):
|
def OnWheel(self, event):
|
||||||
print "Mouse Wheel Moved in DrawFrame"
|
print "Mouse Wheel Moved in DrawFrame"
|
||||||
self.PrintCoords(event)
|
self.PrintCoords(event)
|
||||||
|
Rot = event.GetWheelRotation()
|
||||||
|
print "Wheel Rotation is:", Rot
|
||||||
|
print "Wheel Delta is:", event.GetWheelDelta()
|
||||||
|
Rot = Rot / abs(Rot) * 0.1
|
||||||
|
if event.ControlDown(): # move left-right
|
||||||
|
self.Canvas.MoveImage( (Rot, 0), "Panel" )
|
||||||
|
else: # move up-down
|
||||||
|
self.Canvas.MoveImage( (0, Rot), "Panel" )
|
||||||
|
|
||||||
def OnMove(self, event):
|
def OnMove(self, event):
|
||||||
"""
|
"""
|
||||||
Updates the staus bar with the world coordinates
|
Updates the status bar with the world coordinates
|
||||||
"""
|
"""
|
||||||
self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))
|
self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))
|
||||||
|
|
||||||
@@ -283,8 +254,7 @@ if haveNumeric:
|
|||||||
|
|
||||||
def DrawTest(self,event=None):
|
def DrawTest(self,event=None):
|
||||||
wx.GetApp().Yield()
|
wx.GetApp().Yield()
|
||||||
# import random
|
|
||||||
# import RandomArray
|
|
||||||
Range = (-10,10)
|
Range = (-10,10)
|
||||||
colors = self.colors
|
colors = self.colors
|
||||||
|
|
||||||
@@ -320,7 +290,6 @@ if haveNumeric:
|
|||||||
D = random.randint(1,50)
|
D = random.randint(1,50)
|
||||||
cf = random.randint(0,len(colors)-1)
|
cf = random.randint(0,len(colors)-1)
|
||||||
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
|
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
|
||||||
|
|
||||||
# Circles
|
# Circles
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||||
@@ -330,7 +299,6 @@ if haveNumeric:
|
|||||||
cl = random.randint(0,len(colors)-1)
|
cl = random.randint(0,len(colors)-1)
|
||||||
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])
|
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])
|
||||||
Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackgroundColor = None,Position = "cc")
|
Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackgroundColor = None,Position = "cc")
|
||||||
|
|
||||||
# Lines
|
# Lines
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
points = []
|
points = []
|
||||||
@@ -341,7 +309,6 @@ if haveNumeric:
|
|||||||
cf = random.randint(0,len(colors)-1)
|
cf = random.randint(0,len(colors)-1)
|
||||||
cl = random.randint(0,len(colors)-1)
|
cl = random.randint(0,len(colors)-1)
|
||||||
Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl])
|
Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl])
|
||||||
|
|
||||||
# Polygons
|
# Polygons
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
points = []
|
points = []
|
||||||
@@ -381,6 +348,17 @@ if haveNumeric:
|
|||||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||||
Canvas.AddScaledText(String, x, y, Size = ts, Color = colors[cf], Position = "cc")
|
Canvas.AddScaledText(String, x, y, Size = ts, Color = colors[cf], Position = "cc")
|
||||||
|
|
||||||
|
# Arrows
|
||||||
|
N = 5
|
||||||
|
Points = RandomArray.uniform(Range[0], Range[1], (N,2) )
|
||||||
|
for i in range(N):
|
||||||
|
Canvas.AddArrow(Points[i],
|
||||||
|
random.uniform(20,100),
|
||||||
|
Direction = random.uniform(0,360),
|
||||||
|
LineWidth = random.uniform(1,5),
|
||||||
|
LineColor = colors[random.randint(0,len(colors)-1)],
|
||||||
|
ArrowHeadAngle = random.uniform(20,90))
|
||||||
|
|
||||||
Canvas.ZoomToBB()
|
Canvas.ZoomToBB()
|
||||||
|
|
||||||
def TestAnimation(self,event=None):
|
def TestAnimation(self,event=None):
|
||||||
@@ -518,7 +496,7 @@ if haveNumeric:
|
|||||||
Canvas.ClearAll()
|
Canvas.ClearAll()
|
||||||
Canvas.SetProjectionFun(None)
|
Canvas.SetProjectionFun(None)
|
||||||
|
|
||||||
#Add a HitAble rectangle
|
#Add a Hit-able rectangle
|
||||||
w, h = 60, 20
|
w, h = 60, 20
|
||||||
|
|
||||||
dx = 80
|
dx = 80
|
||||||
@@ -941,7 +919,7 @@ if haveNumeric:
|
|||||||
self.Canvas.ClearAll()
|
self.Canvas.ClearAll()
|
||||||
self.Canvas.SetProjectionFun("FlatEarth")
|
self.Canvas.SetProjectionFun("FlatEarth")
|
||||||
#start = time.clock()
|
#start = time.clock()
|
||||||
Shorelines = Read_MapGen(os.path.join("data",'world.dat'),stats = 0)
|
Shorelines = self.Read_MapGen(os.path.join("data",'world.dat'),stats = 0)
|
||||||
#print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) )
|
#print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) )
|
||||||
#start = time.clock()
|
#start = time.clock()
|
||||||
for segment in Shorelines:
|
for segment in Shorelines:
|
||||||
@@ -1147,6 +1125,52 @@ if haveNumeric:
|
|||||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||||
w,h = random.randint(1,5), random.randint(1,5)
|
w,h = random.randint(1,5), random.randint(1,5)
|
||||||
Object.SetShape(x,y,w,h)
|
Object.SetShape(x,y,w,h)
|
||||||
|
self.Canvas.Draw(Force = True)
|
||||||
|
|
||||||
|
def ArrowTest(self,event=None):
|
||||||
|
wx.GetApp().Yield()
|
||||||
|
self.UnBindAllMouseEvents()
|
||||||
|
Canvas = self.Canvas
|
||||||
|
|
||||||
|
Canvas.ClearAll()
|
||||||
|
Canvas.SetProjectionFun(None)
|
||||||
|
|
||||||
|
# put in a rectangle to get a bounding box
|
||||||
|
Canvas.AddRectangle(0,0,20,20,LineColor = None)
|
||||||
|
|
||||||
|
# Draw some Arrows
|
||||||
|
Canvas.AddArrow((10,10),Length = 40, Direction = 0)
|
||||||
|
Canvas.AddArrow((10,10),Length = 50, Direction = 45 ,LineWidth = 2, LineColor = "Black", ArrowHeadAngle = 20)
|
||||||
|
Canvas.AddArrow((10,10),Length = 60, Direction = 90 ,LineWidth = 3, LineColor = "Red", ArrowHeadAngle = 30)
|
||||||
|
Canvas.AddArrow((10,10),Length = 70, Direction = 135,LineWidth = 4, LineColor = "Red", ArrowHeadAngle = 40)
|
||||||
|
Canvas.AddArrow((10,10),Length = 80, Direction = 180,LineWidth = 5, LineColor = "Blue", ArrowHeadAngle = 50)
|
||||||
|
Canvas.AddArrow((10,10),Length = 90, Direction = 225,LineWidth = 4, LineColor = "Blue", ArrowHeadAngle = 60)
|
||||||
|
Canvas.AddArrow((10,10),Length = 100,Direction = 270,LineWidth = 3, LineColor = "Green", ArrowHeadAngle = 70)
|
||||||
|
Canvas.AddArrow((10,10),Length = 110,Direction = 315,LineWidth = 2, LineColor = "Green", ArrowHeadAngle = 90 )
|
||||||
|
|
||||||
|
Canvas.AddText("Clickable Arrow",4,18,Position = "bc")
|
||||||
|
Arrow = Canvas.AddArrow((4,18), 80, Direction = 90 ,LineWidth = 3, LineColor = "Red", ArrowHeadAngle = 30)
|
||||||
|
Arrow.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.ArrowClicked)
|
||||||
|
|
||||||
|
Canvas.AddText("Changable Arrow",16,4,Position = "cc")
|
||||||
|
self.RotArrow = Canvas.AddArrow((16,4), 80, Direction = 0 ,LineWidth = 3, LineColor = "Green", ArrowHeadAngle = 30)
|
||||||
|
self.RotArrow.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RotateArrow)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Canvas.ZoomToBB()
|
||||||
|
|
||||||
|
def ArrowClicked(self,event):
|
||||||
|
print "The Arrow was Clicked"
|
||||||
|
|
||||||
|
def RotateArrow(self,event):
|
||||||
|
print "The Changeable Arrow was Clicked"
|
||||||
|
## You can do them either one at a time, or both at once
|
||||||
|
## Doing them both at once prevents the arrow points from being calculated twice
|
||||||
|
#self.RotArrow.SetDirection(self.RotArrow.Direction + random.uniform(-90,90))
|
||||||
|
#self.RotArrow.SetLength(self.RotArrow.Length + random.randint(-20,20))
|
||||||
|
self.RotArrow.SetLengthDirection(self.RotArrow.Length + random.randint(-20,20),
|
||||||
|
self.RotArrow.Direction + random.uniform(-90,90) )
|
||||||
|
|
||||||
self.Canvas.Draw(Force = True)
|
self.Canvas.Draw(Force = True)
|
||||||
|
|
||||||
@@ -1202,7 +1226,95 @@ if haveNumeric:
|
|||||||
print "Point Num: %i Hit"%Point.VerticeNum
|
print "Point Num: %i Hit"%Point.VerticeNum
|
||||||
self.SelectedPoint = Point
|
self.SelectedPoint = Point
|
||||||
|
|
||||||
|
def Read_MapGen(self, 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.
|
||||||
|
|
||||||
|
Each NumPy array in the list is an NX2 array of Python Floats.
|
||||||
|
|
||||||
|
The demo should have come with a file, "world.dat" that is the
|
||||||
|
shorelines of the whole world, in MapGen format.
|
||||||
|
|
||||||
|
"""
|
||||||
|
import string
|
||||||
|
file = open(filename,'rt')
|
||||||
|
data = file.readlines()
|
||||||
|
data = map(string.strip,data)
|
||||||
|
|
||||||
|
Shorelines = []
|
||||||
|
segment = []
|
||||||
|
for line in data:
|
||||||
|
if line:
|
||||||
|
if line == "# -b": #New segment beginning
|
||||||
|
if segment: Shorelines.append(Numeric.array(segment))
|
||||||
|
segment = []
|
||||||
|
else:
|
||||||
|
segment.append(map(float,string.split(line)))
|
||||||
|
if segment: Shorelines.append(Numeric.array(segment))
|
||||||
|
|
||||||
|
if stats:
|
||||||
|
NumSegments = len(Shorelines)
|
||||||
|
NumPoints = 0
|
||||||
|
for segment in Shorelines:
|
||||||
|
NumPoints = NumPoints + len(segment)
|
||||||
|
AvgPoints = NumPoints / NumSegments
|
||||||
|
print "Number of Segments: ", NumSegments
|
||||||
|
print "Average Number of Points per segment: ",AvgPoints
|
||||||
|
if AllLines:
|
||||||
|
Lines = []
|
||||||
|
for segment in Shorelines:
|
||||||
|
Lines.append(segment[0])
|
||||||
|
for point in segment[1:-1]:
|
||||||
|
Lines.append(point)
|
||||||
|
Lines.append(point)
|
||||||
|
Lines.append(segment[-1])
|
||||||
|
return Lines
|
||||||
|
else:
|
||||||
|
return Shorelines
|
||||||
|
return DrawFrame
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# check options:
|
||||||
|
import sys, getopt
|
||||||
|
optlist, args = getopt.getopt(sys.argv[1:],'l',["local","all","text","map","stext","hit","hitf","animate","speed","temp","props","arrow"])
|
||||||
|
|
||||||
|
if not haveNumeric:
|
||||||
|
raise ImportError(errorText)
|
||||||
|
StartUpDemo = "all" # the default
|
||||||
|
for opt in optlist:
|
||||||
|
if opt[0] == "--all":
|
||||||
|
StartUpDemo = "all"
|
||||||
|
elif opt[0] == "--text":
|
||||||
|
StartUpDemo = "text"
|
||||||
|
elif opt[0] == "--map":
|
||||||
|
StartUpDemo = "map"
|
||||||
|
elif opt[0] == "--stext":
|
||||||
|
StartUpDemo = "stext"
|
||||||
|
elif opt[0] == "--hit":
|
||||||
|
StartUpDemo = "hit"
|
||||||
|
elif opt[0] == "--hitf":
|
||||||
|
StartUpDemo = "hitf"
|
||||||
|
elif opt[0] == "--animate":
|
||||||
|
StartUpDemo = "animate"
|
||||||
|
elif opt[0] == "--speed":
|
||||||
|
StartUpDemo = "speed"
|
||||||
|
elif opt[0] == "--temp":
|
||||||
|
StartUpDemo = "temp"
|
||||||
|
elif opt[0] == "--props":
|
||||||
|
StartUpDemo = "props"
|
||||||
|
elif opt[0] == "--arrow":
|
||||||
|
StartUpDemo = "arrow"
|
||||||
|
try:
|
||||||
|
import fixdc
|
||||||
|
except ImportError:
|
||||||
|
print ("\n *************Notice*************\n"
|
||||||
|
"The fixdc module fixes the DC API for wxPython2.5.1.6 You can get the module from:\n"
|
||||||
|
"http://prdownloads.sourceforge.net/wxpython/fixdc.py?download\n"
|
||||||
|
" It will set up the DC methods to match both older and upcoming versions\n")
|
||||||
|
raise
|
||||||
|
|
||||||
class DemoApp(wx.App):
|
class DemoApp(wx.App):
|
||||||
"""
|
"""
|
||||||
@@ -1259,6 +1371,7 @@ if haveNumeric:
|
|||||||
|
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
wx.InitAllImageHandlers()
|
wx.InitAllImageHandlers()
|
||||||
|
DrawFrame = BuildDrawFrame()
|
||||||
frame = DrawFrame(None, -1, "FloatCanvas Demo App",wx.DefaultPosition,(700,700))
|
frame = DrawFrame(None, -1, "FloatCanvas Demo App",wx.DefaultPosition,(700,700))
|
||||||
|
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
@@ -1290,98 +1403,72 @@ if haveNumeric:
|
|||||||
elif StartUpDemo == "props":
|
elif StartUpDemo == "props":
|
||||||
"starting PropertiesChange Test"
|
"starting PropertiesChange Test"
|
||||||
frame.PropertiesChangeTest()
|
frame.PropertiesChangeTest()
|
||||||
|
elif StartUpDemo == "arrow":
|
||||||
|
"starting arrow Test"
|
||||||
|
frame.ArrowTest()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Each NumPy array in the list is an NX2 array of Python Floats.
|
|
||||||
|
|
||||||
The demo should have come with a file, "world.dat" that is the
|
|
||||||
shorelines of the whole world, in MapGen format.
|
|
||||||
|
|
||||||
"""
|
|
||||||
import string
|
|
||||||
file = open(filename,'rt')
|
|
||||||
data = file.readlines()
|
|
||||||
data = map(string.strip,data)
|
|
||||||
|
|
||||||
Shorelines = []
|
|
||||||
segment = []
|
|
||||||
for line in data:
|
|
||||||
if line:
|
|
||||||
if line == "# -b": #New segment beginning
|
|
||||||
if segment: Shorelines.append(Numeric.array(segment))
|
|
||||||
segment = []
|
|
||||||
else:
|
|
||||||
segment.append(map(float,string.split(line)))
|
|
||||||
if segment: Shorelines.append(Numeric.array(segment))
|
|
||||||
|
|
||||||
if stats:
|
|
||||||
NumSegments = len(Shorelines)
|
|
||||||
NumPoints = 0
|
|
||||||
for segment in Shorelines:
|
|
||||||
NumPoints = NumPoints + len(segment)
|
|
||||||
AvgPoints = NumPoints / NumSegments
|
|
||||||
print "Number of Segments: ", NumSegments
|
|
||||||
print "Average Number of Points per segment: ",AvgPoints
|
|
||||||
if AllLines:
|
|
||||||
Lines = []
|
|
||||||
for segment in Shorelines:
|
|
||||||
Lines.append(segment[0])
|
|
||||||
for point in segment[1:-1]:
|
|
||||||
Lines.append(point)
|
|
||||||
Lines.append(point)
|
|
||||||
Lines.append(segment[-1])
|
|
||||||
return Lines
|
|
||||||
else:
|
|
||||||
return Shorelines
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
## for the wxPython demo:
|
|
||||||
|
|
||||||
def runTest(frame, nb, log):
|
|
||||||
win = TestPanel(nb, log)
|
|
||||||
return win
|
|
||||||
|
|
||||||
|
|
||||||
if haveNumeric:
|
|
||||||
try:
|
|
||||||
import floatcanvas
|
|
||||||
except ImportError: # if it's not there locally, try the wxPython lib.
|
|
||||||
from wx.lib import floatcanvas
|
|
||||||
|
|
||||||
overview = floatcanvas.__doc__
|
|
||||||
|
|
||||||
else:
|
|
||||||
overview = ""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if not haveNumeric:
|
|
||||||
print errorText
|
|
||||||
else:
|
|
||||||
app = DemoApp(False)# put in True if you want output to go to it's own window.
|
app = DemoApp(False)# put in True if you want output to go to it's own window.
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# It's not running stand-alone, set up for wxPython demo.
|
||||||
|
if not haveNumeric:
|
||||||
|
## TestPanel and runTest used for integration into wxPython Demo
|
||||||
|
class TestPanel(wx.Panel):
|
||||||
|
def __init__(self, parent, log):
|
||||||
|
self.log = log
|
||||||
|
wx.Panel.__init__(self, parent, -1)
|
||||||
|
|
||||||
|
import images
|
||||||
|
|
||||||
|
note1 = wx.StaticText(self, -1, errorText)
|
||||||
|
note2 = wx.StaticText(self, -1, "This is what the FloatCanvas can look like:")
|
||||||
|
S = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
S.Add((10, 10), 1)
|
||||||
|
S.Add(note1, 0, wx.ALIGN_CENTER)
|
||||||
|
S.Add(note2, 0, wx.ALIGN_CENTER | wx.BOTTOM, 4)
|
||||||
|
S.Add(wx.StaticBitmap(self,-1,images.getFloatCanvasBitmap()),0,wx.ALIGN_CENTER)
|
||||||
|
S.Add((10, 10), 1)
|
||||||
|
self.SetSizer(S)
|
||||||
|
self.Layout()
|
||||||
|
|
||||||
|
else:
|
||||||
|
## TestPanel and runTest used for integration into wxPython Demo
|
||||||
|
class TestPanel(wx.Panel):
|
||||||
|
def __init__(self, parent, log):
|
||||||
|
self.log = log
|
||||||
|
wx.Panel.__init__(self, parent, -1)
|
||||||
|
note1 = wx.StaticText(self, -1, "The FloatCanvas Demo needs")
|
||||||
|
note2 = wx.StaticText(self, -1, "a separate frame")
|
||||||
|
b = wx.Button(self, -1, "Open Demo Frame Now")
|
||||||
|
b.Bind(wx.EVT_BUTTON, self.OnButton)
|
||||||
|
|
||||||
|
S = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
S.Add((10, 10), 1)
|
||||||
|
S.Add(note1, 0, wx.ALIGN_CENTER)
|
||||||
|
S.Add(note2, 0, wx.ALIGN_CENTER | wx.BOTTOM, 5)
|
||||||
|
S.Add(b, 0, wx.ALIGN_CENTER | wx.ALL, 5)
|
||||||
|
S.Add((10, 10), 1)
|
||||||
|
self.SetSizer(S)
|
||||||
|
self.Layout()
|
||||||
|
|
||||||
|
def OnButton(self, evt):
|
||||||
|
DrawFrame = BuildDrawFrame()
|
||||||
|
frame = DrawFrame(None, -1, "FloatCanvas Drawing Window",wx.DefaultPosition,(500,500))
|
||||||
|
|
||||||
|
#win = wx.lib.plot.TestFrame(self, -1, "PlotCanvas Demo")
|
||||||
|
frame.Show()
|
||||||
|
frame.DrawTest()
|
||||||
|
|
||||||
|
def runTest(frame, nb, log):
|
||||||
|
win = TestPanel(nb, log)
|
||||||
|
return win
|
||||||
|
|
||||||
|
# import to get the doc
|
||||||
|
from wx.lib import floatcanvas
|
||||||
|
overview = floatcanvas.__doc__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BIN
wxPython/demo/bmp_source/floatcanvas.png
Normal file
BIN
wxPython/demo/bmp_source/floatcanvas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
@@ -78,9 +78,9 @@ command_lines = [
|
|||||||
"-a -u -n Blom13 bmp_source/toblom13.png images.py",
|
"-a -u -n Blom13 bmp_source/toblom13.png images.py",
|
||||||
"-a -u -n Blom14 bmp_source/toblom14.png images.py",
|
"-a -u -n Blom14 bmp_source/toblom14.png images.py",
|
||||||
"-a -u -n Blom15 bmp_source/toblom15.png images.py",
|
"-a -u -n Blom15 bmp_source/toblom15.png images.py",
|
||||||
|
|
||||||
"-a -u -n Blom10Masked -m #FFFFFF bmp_source/toblom10.png images.py",
|
"-a -u -n Blom10Masked -m #FFFFFF bmp_source/toblom10.png images.py",
|
||||||
|
|
||||||
|
"-a -u -n FloatCanvas bmp_source/floatcanvas.png images.py",
|
||||||
|
|
||||||
" -u -c bmp_source/001.png throbImages.py",
|
" -u -c bmp_source/001.png throbImages.py",
|
||||||
"-a -u -c bmp_source/002.png throbImages.py",
|
"-a -u -c bmp_source/002.png throbImages.py",
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,10 @@
|
|||||||
try:
|
try:
|
||||||
from Numeric import array,asarray,Float,cos,pi,sum,minimum,maximum,Int32,zeros, ones, concatenate, sqrt, argmin, power, absolute
|
from Numeric import array,asarray,Float,cos, sin, pi,sum,minimum,maximum,Int32,zeros, ones, concatenate, sqrt, argmin, power, absolute, matrixmultiply, transpose, sometrue
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from numarray import array, asarray, Float, cos, pi, sum, minimum, maximum, Int32, zeros, concatenate
|
try:
|
||||||
|
from numarray import array, asarray, Float, cos, sin, pi, sum, minimum, maximum, Int32, zeros, concatenate, matrixmultiply, transpose, sometrue
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError("I could not import either Numeric or numarray")
|
||||||
|
|
||||||
from time import clock, sleep
|
from time import clock, sleep
|
||||||
|
|
||||||
@@ -17,10 +20,11 @@ global ScreenPPI
|
|||||||
|
|
||||||
## a custom Exceptions:
|
## a custom Exceptions:
|
||||||
|
|
||||||
class FloatCanvasException(Exception):
|
class FloatCanvasError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## Create all the mouse events
|
## Create all the mouse events
|
||||||
|
# I don't see a need for these two, but maybe some day!
|
||||||
#EVT_FC_ENTER_WINDOW = wx.NewEventType()
|
#EVT_FC_ENTER_WINDOW = wx.NewEventType()
|
||||||
#EVT_FC_LEAVE_WINDOW = wx.NewEventType()
|
#EVT_FC_LEAVE_WINDOW = wx.NewEventType()
|
||||||
EVT_FC_LEFT_DOWN = wx.NewEventType()
|
EVT_FC_LEFT_DOWN = wx.NewEventType()
|
||||||
@@ -92,8 +96,9 @@ class _MouseEvent(wx.PyCommandEvent):
|
|||||||
self._NativeEvent = NativeEvent
|
self._NativeEvent = NativeEvent
|
||||||
self.Coords = Coords
|
self.Coords = Coords
|
||||||
|
|
||||||
def SetCoords(self,Coords):
|
# I don't think this is used.
|
||||||
self.Coords = Coords
|
# def SetCoords(self,Coords):
|
||||||
|
# self.Coords = Coords
|
||||||
|
|
||||||
def GetCoords(self):
|
def GetCoords(self):
|
||||||
return self.Coords
|
return self.Coords
|
||||||
@@ -294,7 +299,6 @@ class DrawObject:
|
|||||||
self._Canvas.MakeHitDict()
|
self._Canvas.MakeHitDict()
|
||||||
self._Canvas.HitDict[Event][self.HitColor] = (self) # put the object in the hit dict, indexed by it's color
|
self._Canvas.HitDict[Event][self.HitColor] = (self) # put the object in the hit dict, indexed by it's color
|
||||||
|
|
||||||
|
|
||||||
def UnBindAll(self):
|
def UnBindAll(self):
|
||||||
## fixme: this only removes one from each list, there could be more.
|
## fixme: this only removes one from each list, there could be more.
|
||||||
if self._Canvas.HitDict:
|
if self._Canvas.HitDict:
|
||||||
@@ -421,6 +425,10 @@ class XYObjectMixin:
|
|||||||
self.XY = array( (x, y), Float)
|
self.XY = array( (x, y), Float)
|
||||||
self.CalcBoundingBox()
|
self.CalcBoundingBox()
|
||||||
|
|
||||||
|
def CalcBoundingBox(self):
|
||||||
|
## This may get overwritten in some subclasses
|
||||||
|
self.BoundingBox = array( (self.XY, self.XY), Float )
|
||||||
|
|
||||||
def SetPoint(self, xy):
|
def SetPoint(self, xy):
|
||||||
self.XY = array( xy, Float)
|
self.XY = array( xy, Float)
|
||||||
self.XY.shape = (2,)
|
self.XY.shape = (2,)
|
||||||
@@ -601,6 +609,98 @@ class Line(DrawObject,PointsObjectMixin,LineOnlyMixin):
|
|||||||
HTdc.SetPen(self.HitPen)
|
HTdc.SetPen(self.HitPen)
|
||||||
HTdc.DrawLines(Points)
|
HTdc.DrawLines(Points)
|
||||||
|
|
||||||
|
class Arrow(DrawObject,XYObjectMixin,LineOnlyMixin):
|
||||||
|
"""
|
||||||
|
|
||||||
|
Arrow(XY, # coords of origin of arrow (x,y)
|
||||||
|
Length, # length of arrow in pixels
|
||||||
|
theta, # angle of arrow in degrees: zero is straight up
|
||||||
|
# angle is to the right
|
||||||
|
LineColor = "Black",
|
||||||
|
LineStyle = "Solid",
|
||||||
|
LineWidth = 1,
|
||||||
|
ArrowHeadSize = 4,
|
||||||
|
ArrowHeadAngle = 45,
|
||||||
|
InForeground = False):
|
||||||
|
|
||||||
|
It will draw an arrow , starting at the point, (X,Y) pointing in
|
||||||
|
direction, theta.
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
def __init__(self,
|
||||||
|
XY,
|
||||||
|
Length,
|
||||||
|
Direction,
|
||||||
|
LineColor = "Black",
|
||||||
|
LineStyle = "Solid",
|
||||||
|
LineWidth = 2, # pixels
|
||||||
|
ArrowHeadSize = 8, # pixels
|
||||||
|
ArrowHeadAngle = 30, # degrees
|
||||||
|
InForeground = False):
|
||||||
|
|
||||||
|
DrawObject.__init__(self, InForeground)
|
||||||
|
|
||||||
|
self.XY = array(XY, Float)
|
||||||
|
self.XY.shape = (2,) # Make sure it is a 1X2 array, even if there is only one point
|
||||||
|
self.Length = Length
|
||||||
|
self.Direction = float(Direction)
|
||||||
|
self.ArrowHeadSize = ArrowHeadSize
|
||||||
|
self.ArrowHeadAngle = float(ArrowHeadAngle)
|
||||||
|
|
||||||
|
self.CalcArrowPoints()
|
||||||
|
self.CalcBoundingBox()
|
||||||
|
|
||||||
|
self.LineColor = LineColor
|
||||||
|
self.LineStyle = LineStyle
|
||||||
|
self.LineWidth = LineWidth
|
||||||
|
|
||||||
|
self.SetPen(LineColor,LineStyle,LineWidth)
|
||||||
|
|
||||||
|
##fixme: How should the HitTest be drawn?
|
||||||
|
self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
|
||||||
|
|
||||||
|
def SetDirection(self, Direction):
|
||||||
|
self.Direction = float(Direction)
|
||||||
|
self.CalcArrowPoints()
|
||||||
|
|
||||||
|
def SetLength(self, Length):
|
||||||
|
self.Length = Length
|
||||||
|
self.CalcArrowPoints()
|
||||||
|
|
||||||
|
def SetLengthDirection(self, Length, Direction):
|
||||||
|
self.Direction = float(Direction)
|
||||||
|
self.Length = Length
|
||||||
|
self.CalcArrowPoints()
|
||||||
|
|
||||||
|
def SetLength(self, Length):
|
||||||
|
self.Length = Length
|
||||||
|
self.CalcArrowPoints()
|
||||||
|
|
||||||
|
def CalcArrowPoints(self):
|
||||||
|
L = self.Length
|
||||||
|
S = self.ArrowHeadSize
|
||||||
|
phi = self.ArrowHeadAngle * pi / 360
|
||||||
|
theta = (self.Direction-90.0) * pi / 180
|
||||||
|
ArrowPoints = array( ( (0, L, L - S*cos(phi),L, L - S*cos(phi) ),
|
||||||
|
(0, 0, S*sin(phi), 0, -S*sin(phi) ) ),
|
||||||
|
Float )
|
||||||
|
RotationMatrix = array( ( ( cos(theta), -sin(theta) ),
|
||||||
|
( sin(theta), cos(theta) ) ),
|
||||||
|
Float
|
||||||
|
)
|
||||||
|
ArrowPoints = matrixmultiply(RotationMatrix, ArrowPoints)
|
||||||
|
self.ArrowPoints = transpose(ArrowPoints)
|
||||||
|
|
||||||
|
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||||
|
dc.SetPen(self.Pen)
|
||||||
|
xy = WorldToPixel(self.XY)
|
||||||
|
ArrowPoints = xy + self.ArrowPoints
|
||||||
|
dc.DrawLines(ArrowPoints)
|
||||||
|
if HTdc and self.HitAble:
|
||||||
|
HTdc.SetPen(self.HitPen)
|
||||||
|
HTdc.DrawLines(ArrowPoints)
|
||||||
|
|
||||||
##class LineSet(DrawObject, ObjectSetMixin):
|
##class LineSet(DrawObject, ObjectSetMixin):
|
||||||
## """
|
## """
|
||||||
## The LineSet class takes a list of 2-tuples, or a NX2 NumPy array of point coordinates.
|
## The LineSet class takes a list of 2-tuples, or a NX2 NumPy array of point coordinates.
|
||||||
@@ -755,8 +855,6 @@ class Point(DrawObject,XYObjectMixin,ColorOnlyMixin):
|
|||||||
def SetDiameter(self,Diameter):
|
def SetDiameter(self,Diameter):
|
||||||
self.Diameter = Diameter
|
self.Diameter = Diameter
|
||||||
|
|
||||||
def CalcBoundingBox(self):
|
|
||||||
self.BoundingBox = array( (self.XY, self.XY), Float )
|
|
||||||
|
|
||||||
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||||
dc.SetPen(self.Pen)
|
dc.SetPen(self.Pen)
|
||||||
@@ -821,9 +919,6 @@ class RectEllipse(DrawObject, XYObjectMixin,LineAndFillMixin):
|
|||||||
|
|
||||||
|
|
||||||
class Rectangle(RectEllipse):
|
class Rectangle(RectEllipse):
|
||||||
# def __init__(*args, **kwargs):
|
|
||||||
# RectEllipse.__init__(*args, **kwargs)
|
|
||||||
# raise "an error"
|
|
||||||
|
|
||||||
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||||
( XY, WH ) = self.SetUpDraw(dc,
|
( XY, WH ) = self.SetUpDraw(dc,
|
||||||
@@ -993,10 +1088,6 @@ class Text(DrawObject, TextObjectMixin):
|
|||||||
(self.TextWidth, self.TextHeight) = (None, None)
|
(self.TextWidth, self.TextHeight) = (None, None)
|
||||||
self.ShiftFun = self.ShiftFunDict[Position]
|
self.ShiftFun = self.ShiftFunDict[Position]
|
||||||
|
|
||||||
def CalcBoundingBox(self):
|
|
||||||
self.BoundingBox = array((self.XY, self.XY),Float)
|
|
||||||
|
|
||||||
|
|
||||||
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||||
XY = WorldToPixel(self.XY)
|
XY = WorldToPixel(self.XY)
|
||||||
dc.SetFont(self.Font)
|
dc.SetFont(self.Font)
|
||||||
@@ -1321,7 +1412,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
elif ProjectionFun is None:
|
elif ProjectionFun is None:
|
||||||
self.ProjectionFun = lambda x=None: array( (1,1), Float)
|
self.ProjectionFun = lambda x=None: array( (1,1), Float)
|
||||||
else:
|
else:
|
||||||
raise FloatCanvasException('Projectionfun must be either: "FlatEarth", None, or a function that takes the ViewPortCenter and returns a MapProjectionVector')
|
raise FloatCanvasError('Projectionfun must be either: "FlatEarth", None, or a function that takes the ViewPortCenter and returns a MapProjectionVector')
|
||||||
|
|
||||||
def FlatEarthProjection(self,CenterPoint):
|
def FlatEarthProjection(self,CenterPoint):
|
||||||
return array((cos(pi*CenterPoint[1]/180),1),Float)
|
return array((cos(pi*CenterPoint[1]/180),1),Float)
|
||||||
@@ -1330,7 +1421,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
if Mode in ["ZoomIn","ZoomOut","Move","Mouse",None]:
|
if Mode in ["ZoomIn","ZoomOut","Move","Mouse",None]:
|
||||||
self.GUIMode = Mode
|
self.GUIMode = Mode
|
||||||
else:
|
else:
|
||||||
raise FloatCanvasException('"%s" is Not a valid Mode'%Mode)
|
raise FloatCanvasError('"%s" is Not a valid Mode'%Mode)
|
||||||
|
|
||||||
def MakeHitDict(self):
|
def MakeHitDict(self):
|
||||||
##fixme: Should this just be None if nothing has been bound?
|
##fixme: Should this just be None if nothing has been bound?
|
||||||
@@ -1465,7 +1556,8 @@ class FloatCanvas(wx.Panel):
|
|||||||
self._RaiseMouseEvent(event, EventType)
|
self._RaiseMouseEvent(event, EventType)
|
||||||
|
|
||||||
def WheelEvent(self,event):
|
def WheelEvent(self,event):
|
||||||
if self.GUIMode == "Mouse":
|
##if self.GUIMode == "Mouse":
|
||||||
|
## Why not always raise this?
|
||||||
self._RaiseMouseEvent(event, EVT_FC_MOUSEWHEEL)
|
self._RaiseMouseEvent(event, EVT_FC_MOUSEWHEEL)
|
||||||
|
|
||||||
|
|
||||||
@@ -1516,7 +1608,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
StartMove = self.StartMove
|
StartMove = self.StartMove
|
||||||
EndMove = array((event.GetX(),event.GetY()))
|
EndMove = array((event.GetX(),event.GetY()))
|
||||||
if sum((StartMove-EndMove)**2) > 16:
|
if sum((StartMove-EndMove)**2) > 16:
|
||||||
self.Move(StartMove-EndMove,'Pixel')
|
self.MoveImage(StartMove-EndMove,'Pixel')
|
||||||
self.StartMove = None
|
self.StartMove = None
|
||||||
elif self.GUIMode == "Mouse":
|
elif self.GUIMode == "Mouse":
|
||||||
EventType = EVT_FC_LEFT_UP
|
EventType = EVT_FC_LEFT_UP
|
||||||
@@ -1694,8 +1786,9 @@ class FloatCanvas(wx.Panel):
|
|||||||
animation, for instance.
|
animation, for instance.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
#print "In Draw"
|
# print "in Draw", self.PanelSize
|
||||||
if self.PanelSize < (1,1): # it's possible for this to get called before being properly initialized.
|
if sometrue(self.PanelSize < 1 ): # it's possible for this to get called before being properly initialized.
|
||||||
|
# if self.PanelSize < (1,1): # it's possible for this to get called before being properly initialized.
|
||||||
return
|
return
|
||||||
if self.Debug: start = clock()
|
if self.Debug: start = clock()
|
||||||
ScreenDC = wx.ClientDC(self)
|
ScreenDC = wx.ClientDC(self)
|
||||||
@@ -1779,7 +1872,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
## else:
|
## else:
|
||||||
## return False
|
## return False
|
||||||
|
|
||||||
def Move(self,shift,CoordType):
|
def MoveImage(self,shift,CoordType):
|
||||||
"""
|
"""
|
||||||
move the image in the window.
|
move the image in the window.
|
||||||
|
|
||||||
@@ -1798,7 +1891,8 @@ class FloatCanvas(wx.Panel):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
shift = array(shift,Float)
|
shift = asarray(shift,Float)
|
||||||
|
#print "shifting by:", shift
|
||||||
if CoordType == 'Panel':# convert from panel coordinates
|
if CoordType == 'Panel':# convert from panel coordinates
|
||||||
shift = shift * array((-1,1),Float) *self.PanelSize/self.TransformVector
|
shift = shift * array((-1,1),Float) *self.PanelSize/self.TransformVector
|
||||||
elif CoordType == 'Pixel': # convert from pixel coordinates
|
elif CoordType == 'Pixel': # convert from pixel coordinates
|
||||||
@@ -1806,7 +1900,9 @@ class FloatCanvas(wx.Panel):
|
|||||||
elif CoordType == 'World': # No conversion
|
elif CoordType == 'World': # No conversion
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise FloatCanvasException('CoordType must be either "Panel", "Pixel", or "World"')
|
raise FloatCanvasError('CoordType must be either "Panel", "Pixel", or "World"')
|
||||||
|
|
||||||
|
#print "shifting by:", shift
|
||||||
|
|
||||||
self.ViewPortCenter = self.ViewPortCenter + shift
|
self.ViewPortCenter = self.ViewPortCenter + shift
|
||||||
self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter)
|
self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter)
|
||||||
@@ -2010,7 +2106,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
NumBetweenBlits = self.NumBetweenBlits # for speed
|
NumBetweenBlits = self.NumBetweenBlits # for speed
|
||||||
for i, Object in enumerate(self._ShouldRedraw(DrawList, ViewPortBB)):
|
for i, Object in enumerate(self._ShouldRedraw(DrawList, ViewPortBB)):
|
||||||
Object._Draw(dc, WorldToPixel, ScaleWorldToPixel, HTdc)
|
Object._Draw(dc, WorldToPixel, ScaleWorldToPixel, HTdc)
|
||||||
if i % NumBetweenBlits == 0:
|
if i+1 % NumBetweenBlits == 0:
|
||||||
Blit(0, 0, PanelSize0, PanelSize1, dc, 0, 0)
|
Blit(0, 0, PanelSize0, PanelSize1, dc, 0, 0)
|
||||||
dc.EndDrawing()
|
dc.EndDrawing()
|
||||||
|
|
||||||
@@ -2035,7 +2131,7 @@ class FloatCanvas(wx.Panel):
|
|||||||
|
|
||||||
def _makeFloatCanvasAddMethods(): ## lrk's code for doing this in module __init__
|
def _makeFloatCanvasAddMethods(): ## lrk's code for doing this in module __init__
|
||||||
classnames = ["Circle", "Ellipse", "Rectangle", "ScaledText", "Polygon",
|
classnames = ["Circle", "Ellipse", "Rectangle", "ScaledText", "Polygon",
|
||||||
"Line", "Text", "PointSet","Point"]
|
"Line", "Text", "PointSet","Point", "Arrow"]
|
||||||
for classname in classnames:
|
for classname in classnames:
|
||||||
klass = globals()[classname]
|
klass = globals()[classname]
|
||||||
def getaddshapemethod(klass=klass):
|
def getaddshapemethod(klass=klass):
|
||||||
|
@@ -3,18 +3,10 @@ A Panel that includes the FloatCanvas and Navigation controls
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#from Numeric import array,Float,cos,pi,sum,minimum,maximum,Int32
|
|
||||||
|
|
||||||
#from time import clock, sleep
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
#import types
|
|
||||||
#import os
|
|
||||||
|
|
||||||
import FloatCanvas, Resources
|
import FloatCanvas, Resources
|
||||||
|
|
||||||
|
|
||||||
ID_ZOOM_IN_BUTTON = wx.NewId()
|
ID_ZOOM_IN_BUTTON = wx.NewId()
|
||||||
ID_ZOOM_OUT_BUTTON = wx.NewId()
|
ID_ZOOM_OUT_BUTTON = wx.NewId()
|
||||||
ID_ZOOM_TO_FIT_BUTTON = wx.NewId()
|
ID_ZOOM_TO_FIT_BUTTON = wx.NewId()
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
This is the floatcanvas package. It provides two primary modules, and a
|
This is the floatcanvas package. It provides two primary modules, and a
|
||||||
support module.
|
support module.
|
||||||
|
|
||||||
FloatCanvas.py contains the main FloatCanvas class, and it's supporting
|
FloatCanvas.py contains the main FloatCanvas class, and its supporting
|
||||||
classes. NavCanvas.py contains a wrapper for the FloatCanvas that
|
classes. NavCanvas.py contains a wrapper for the FloatCanvas that
|
||||||
provides the canvas and a toolbar with tools that allow you to navigate
|
provides the canvas and a toolbar with tools that allow you to navigate
|
||||||
the canvas (zooming, panning, etc.) Resources.py is a module that
|
the canvas (zooming, panning, etc.) Resources.py is a module that
|
||||||
@@ -73,6 +73,10 @@ just like the regular mouse events, but include an extra attribute:
|
|||||||
Event.GetCoords(), that returns the (x,y) position in world coordinates,
|
Event.GetCoords(), that returns the (x,y) position in world coordinates,
|
||||||
as a length-2 NumPy vector of Floats.
|
as a length-2 NumPy vector of Floats.
|
||||||
|
|
||||||
|
There are also a full set of bindings to mouse events on objects, so
|
||||||
|
that you can specify a given function be called when an objects is
|
||||||
|
clicked, mouse-over'd, etc.
|
||||||
|
|
||||||
See the Demo for what it can do, and how to use it.
|
See the Demo for what it can do, and how to use it.
|
||||||
|
|
||||||
Copyright: Christopher Barker
|
Copyright: Christopher Barker
|
||||||
@@ -90,6 +94,6 @@ Chris.Barker@noaa.gov
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.8.5"
|
__version__ = "0.8.7"
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user