mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 03:20:08 +01:00
Trim trailing space samples directory
This commit is contained in:
@@ -44,16 +44,16 @@ ID_TEST = 500
|
||||
class DrawFrame(wx.Frame):
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
|
||||
## Set up the MenuBar
|
||||
|
||||
|
||||
MenuBar = wx.MenuBar()
|
||||
|
||||
|
||||
file_menu = wx.Menu()
|
||||
exit = file_menu.Append(wx.ID_EXIT, "", "Terminate the program")
|
||||
self.Bind(wx.EVT_MENU, self.OnQuit, exit)
|
||||
MenuBar.Append(file_menu, "&File")
|
||||
|
||||
|
||||
draw_menu = wx.Menu()
|
||||
draw = draw_menu.Append(wx.ID_ANY,
|
||||
"&Draw Test",
|
||||
@@ -65,68 +65,68 @@ class DrawFrame(wx.Frame):
|
||||
clear = draw_menu.Append(wx.ID_ANY, "&Clear","Clear the Canvas")
|
||||
self.Bind(wx.EVT_MENU, self.Clear, clear)
|
||||
MenuBar.Append(draw_menu, "&Draw")
|
||||
|
||||
|
||||
|
||||
|
||||
view_menu = wx.Menu()
|
||||
zoom = view_menu.Append(wx.ID_ANY, "Zoom to &Fit","Zoom to fit the window")
|
||||
self.Bind(wx.EVT_MENU, self.ZoomToFit, zoom)
|
||||
MenuBar.Append(view_menu, "&View")
|
||||
|
||||
|
||||
help_menu = wx.Menu()
|
||||
about = help_menu.Append(wx.ID_ABOUT, "",
|
||||
"More information About this program")
|
||||
self.Bind(wx.EVT_MENU, self.OnAbout, about)
|
||||
MenuBar.Append(help_menu, "&Help")
|
||||
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("")
|
||||
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
|
||||
# Other event handlers:
|
||||
self.Bind(wx.EVT_RIGHT_DOWN, self.RightButtonEvent)
|
||||
|
||||
|
||||
# Add the Canvas
|
||||
self.Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
Debug = False,
|
||||
BackgroundColor = "WHITE").Canvas
|
||||
self.Canvas.NumBetweenBlits = 1000
|
||||
self.Show(True)
|
||||
|
||||
|
||||
self.DrawTest(None)
|
||||
return None
|
||||
|
||||
|
||||
def RightButtonEvent(self,event):
|
||||
print("Right Button has been clicked in DrawFrame")
|
||||
print("coords are: %i, %i"%(event.GetX(),event.GetY()))
|
||||
event.Skip()
|
||||
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
|
||||
"the use of the FloatCanvas\n",
|
||||
"About Me", wx.OK | wx.ICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def ZoomToFit(self,event):
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
|
||||
def Clear(self,event = None):
|
||||
self.Canvas.ClearAll()
|
||||
self.Canvas.Draw()
|
||||
|
||||
|
||||
def OnQuit(self,event):
|
||||
self.Close(True)
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def DrawTest(self,event = None):
|
||||
import random
|
||||
import numpy.random as RandomArray
|
||||
|
||||
|
||||
Range = (-10,10)
|
||||
|
||||
colors = ["AQUAMARINE", "BLACK", "BLUE", "BLUE VIOLET", "BROWN",
|
||||
@@ -143,7 +143,7 @@ class DrawFrame(wx.Frame):
|
||||
"ORCHID", "PALE GREEN", "PINK", "PLUM", "PURPLE", "RED",
|
||||
"SALMON", "SEA GREEN", "SIENNA", "SKY BLUE", "SLATE BLUE",
|
||||
"SPRING GREEN", "STEEL BLUE", "TAN", "THISTLE", "TURQUOISE",
|
||||
"VIOLET", "VIOLET RED", "WHEAT", "WHITE", "YELLOW", "YELLOW GREEN"]
|
||||
"VIOLET", "VIOLET RED", "WHEAT", "WHITE", "YELLOW", "YELLOW GREEN"]
|
||||
Canvas = self.Canvas
|
||||
|
||||
# Some Polygons in the background:
|
||||
@@ -161,17 +161,17 @@ class DrawFrame(wx.Frame):
|
||||
FillColor = colors[cf],
|
||||
FillStyle = 'Solid',
|
||||
InForeground = False)
|
||||
|
||||
|
||||
## Pointset
|
||||
print("Adding Points to Foreground" )
|
||||
for i in range(1):
|
||||
points = RandomArray.uniform(-100,100,(1000,2))
|
||||
D = 2
|
||||
self.LEs = self.Canvas.AddPointSet(points, Color = "Black", Diameter = D, InForeground = True)
|
||||
|
||||
|
||||
self.Canvas.AddRectangle((-200,-200), (400,400))
|
||||
Canvas.ZoomToBB()
|
||||
|
||||
|
||||
def RunMovie(self,event = None):
|
||||
import numpy.random as RandomArray
|
||||
start = clock()
|
||||
@@ -184,80 +184,80 @@ class DrawFrame(wx.Frame):
|
||||
self.Canvas.Draw()
|
||||
wx.GetApp().Yield(True)
|
||||
print("running the movie took %f seconds"%(clock() - start))
|
||||
|
||||
|
||||
class DemoApp(wx.App):
|
||||
"""
|
||||
How the demo works:
|
||||
|
||||
|
||||
Under the Draw menu, there are three options:
|
||||
|
||||
|
||||
*Draw Test: will put up a picture of a bunch of randomly generated
|
||||
objects, of each kind supported.
|
||||
|
||||
|
||||
*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
|
||||
with a lot of data, and will take a while to load and draw (about 10 sec
|
||||
on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
|
||||
performance is not very good for large drawings.
|
||||
|
||||
|
||||
*Clear: Clears the Canvas.
|
||||
|
||||
|
||||
Once you have a picture drawn, you can zoom in and out and move about
|
||||
the picture. There is a tool bar with three tools that can be
|
||||
selected.
|
||||
|
||||
selected.
|
||||
|
||||
The magnifying glass with the plus is the zoom in tool. Once selected,
|
||||
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
|
||||
box, and the image will zoom to fit that box when you release it.
|
||||
|
||||
|
||||
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
|
||||
clicked. (note that this takes a while when you are looking at the map,
|
||||
as it has a LOT of lines to be drawn. The image is double buffered, so
|
||||
you don't see the drawing in progress)
|
||||
|
||||
|
||||
The hand is the move tool. Once selected, if you click and drag on the
|
||||
image, it will move so that the part you clicked on ends up where you
|
||||
release the mouse. Nothing is changed while you are dragging. The
|
||||
drawing is too slow for that.
|
||||
|
||||
|
||||
I'd like the cursor to change as you change tools, but the stock
|
||||
wx.Cursors didn't include anything I liked, so I stuck with the
|
||||
pointer. Pleae let me know if you have any nice cursor images for me to
|
||||
use.
|
||||
|
||||
|
||||
|
||||
|
||||
Any bugs, comments, feedback, questions, and especially code are welcome:
|
||||
|
||||
|
||||
-Chris Barker
|
||||
|
||||
|
||||
ChrisHBarker@home.net
|
||||
http://members.home.net/barkerlohmann
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def OnInit(self):
|
||||
frame = DrawFrame(None, -1, "Simple Drawing Window",wx.DefaultPosition, (700,700) )
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def Read_MapGen(filename,stats = False):
|
||||
"""
|
||||
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 worls, in MapGen format.
|
||||
|
||||
|
||||
"""
|
||||
from numpy import array
|
||||
file = open(filename,'rt')
|
||||
data = file.readlines()
|
||||
data = [s.strip() for s in data]
|
||||
data = [s.strip() for s in data]
|
||||
|
||||
Shorelines = []
|
||||
segment = []
|
||||
@@ -268,7 +268,7 @@ def Read_MapGen(filename,stats = False):
|
||||
else:
|
||||
segment.append(map(float,string.split(line)))
|
||||
if segment: Shorelines.append(array(segment))
|
||||
|
||||
|
||||
if stats:
|
||||
NumSegments = len(Shorelines)
|
||||
NumPoints = False
|
||||
@@ -277,20 +277,20 @@ def Read_MapGen(filename,stats = False):
|
||||
AvgPoints = NumPoints / NumSegments
|
||||
print("Number of Segments: ", NumSegments)
|
||||
print("Average Number of Points per segment: ",AvgPoints)
|
||||
|
||||
|
||||
return Shorelines
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app = DemoApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ def BB_HitTest(self, event, HitEvent):
|
||||
xy = self.PixelToWorld( xy_p ) #Convert to the correct coords
|
||||
for key2 in self.HitDict[HitEvent].keys():
|
||||
#Get Mouse Event Position
|
||||
bb = self.HitDict[HitEvent][key2].BoundingBox
|
||||
if bb.PointInside(xy):
|
||||
bb = self.HitDict[HitEvent][key2].BoundingBox
|
||||
if bb.PointInside(xy):
|
||||
Object = self.HitDict[HitEvent][key2]
|
||||
objects.append(Object)
|
||||
try:
|
||||
@@ -44,7 +44,7 @@ def BB_HitTest(self, event, HitEvent):
|
||||
Object = self.HitDict[HitEvent][key2]
|
||||
if len(objects) > 0: #If no objects then do nothing
|
||||
#Get the highest index object
|
||||
highest_object = objects[object_index_list.index(max(object_index_list))]
|
||||
highest_object = objects[object_index_list.index(max(object_index_list))]
|
||||
highest_object.HitCoords = xy
|
||||
highest_object.HitCoordsPixel = xy_p
|
||||
highest_object.CallBackFuncs[HitEvent](highest_object)
|
||||
@@ -74,10 +74,10 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
Point = (45,40)
|
||||
Text = Canvas.AddScaledText("A String",
|
||||
@@ -118,10 +118,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class BNAData:
|
||||
self.Types = None
|
||||
if Filename is not None:
|
||||
self.Load(Filename)
|
||||
|
||||
|
||||
def __getitem__(self,index):
|
||||
return (self.PointsData[index], self.Names[index])
|
||||
|
||||
@@ -121,7 +121,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
self.Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
Debug = 0,
|
||||
@@ -130,8 +130,8 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
wx.EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
|
||||
FloatCanvas.EVT_LEFT_UP(self.Canvas, self.OnLeftUp )
|
||||
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
|
||||
FloatCanvas.EVT_LEFT_UP(self.Canvas, self.OnLeftUp )
|
||||
FloatCanvas.EVT_LEFT_DOWN(self.Canvas, self.OnLeftDown)
|
||||
|
||||
try:
|
||||
@@ -153,7 +153,7 @@ class DrawFrame(wx.Frame):
|
||||
if self.SelectedPoly:
|
||||
self.DeSelectPoly()
|
||||
self.Canvas.Draw()
|
||||
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
|
||||
"the use of the FloatCanvas\n",
|
||||
@@ -244,7 +244,7 @@ class DrawFrame(wx.Frame):
|
||||
Canvas.RemoveObject(self.SelectedPoly)
|
||||
Canvas.RemoveObject(self.SelectedPoints)
|
||||
self.ResetSelections()
|
||||
|
||||
|
||||
def SelectPoly(self, Object):
|
||||
Canvas = self.Canvas
|
||||
if Object is self.SelectedPolyOrig:
|
||||
@@ -306,7 +306,7 @@ class BNAEditor(wx.App):
|
||||
"""
|
||||
Once you have a picture drawn, you can zoom in and out and move about
|
||||
the picture. There is a tool bar with three tools that can be
|
||||
selected.
|
||||
selected.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -329,10 +329,10 @@ class BNAEditor(wx.App):
|
||||
app = BNAEditor(False)# put in True if you want output to go to it's own window.
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ MaxValue = 2000
|
||||
def YScaleFun(center):
|
||||
"""
|
||||
Function that returns a scaling vector to scale y data to same range as x data
|
||||
|
||||
|
||||
This is used by FloatCanvas as a "projection function", so that you can have
|
||||
a different scale for X and Y. With the default projection, X and Y are the same scale.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# center gets ignored in this case
|
||||
return N.array((1, float(NumChannels)/MaxValue), N.float)
|
||||
|
||||
@@ -34,7 +34,7 @@ def ScaleWorldToPixel(self, Lengths):
|
||||
This is a new version of a function that will get passed to the
|
||||
drawing functions of the objects, to Change a length from world to
|
||||
pixel coordinates.
|
||||
|
||||
|
||||
This version uses the "ceil" function, so that fractional pixel get
|
||||
rounded up, rather than down.
|
||||
|
||||
@@ -63,14 +63,14 @@ class DrawFrame(wx.Frame):
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
ProjectionFun = YScaleFun,
|
||||
)
|
||||
|
||||
|
||||
self.Canvas = Canvas = NC.Canvas
|
||||
#self.Canvas.ScaleWorldToPixel = ScaleWorldToPixel
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
self.Values = random.randint(0, MaxValue, (NumChannels,))
|
||||
|
||||
|
||||
self.Bars = []
|
||||
self.BarWidth = 0.75
|
||||
# add an X axis
|
||||
@@ -88,7 +88,7 @@ class DrawFrame(wx.Frame):
|
||||
FillStyle = "Solid",
|
||||
)
|
||||
self.Bars.append(bar)
|
||||
|
||||
|
||||
# Add a couple a button the Toolbar
|
||||
|
||||
tb = NC.ToolBar
|
||||
@@ -106,7 +106,7 @@ class DrawFrame(wx.Frame):
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
Canvas.Draw(True)
|
||||
|
||||
|
||||
|
||||
def OnMove(self, event):
|
||||
"""
|
||||
@@ -118,7 +118,7 @@ class DrawFrame(wx.Frame):
|
||||
channel = "%i,"%(channel+1)
|
||||
else:
|
||||
channel = ""
|
||||
|
||||
|
||||
if value >=0:
|
||||
value = "%3g"%value
|
||||
else:
|
||||
@@ -128,16 +128,16 @@ class DrawFrame(wx.Frame):
|
||||
def ResetData(self, event):
|
||||
self.Values = random.randint(0, MaxValue, (NumChannels,))
|
||||
for i, bar in enumerate(self.Bars):
|
||||
bar.SetShape(bar.XY, (self.BarWidth, self.Values[i]))
|
||||
bar.SetShape(bar.XY, (self.BarWidth, self.Values[i]))
|
||||
self.Canvas.Draw(Force=True)
|
||||
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ FC = FloatCanvas
|
||||
class MovingObjectMixin: # Borrowed from MovingElements.py
|
||||
"""
|
||||
Methods required for a Moving object
|
||||
|
||||
|
||||
"""
|
||||
|
||||
def GetOutlinePoints(self):
|
||||
@@ -57,22 +57,22 @@ class Ball(MovingObjectMixin, FloatCanvas.Circle):
|
||||
class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
## Set up the MenuBar
|
||||
|
||||
|
||||
MenuBar = wx.MenuBar()
|
||||
|
||||
|
||||
file_menu = wx.Menu()
|
||||
item = file_menu.Append(wx.ID_EXIT, "","Terminate the program")
|
||||
self.Bind(wx.EVT_MENU, self.OnQuit, item)
|
||||
MenuBar.Append(file_menu, "&File")
|
||||
|
||||
|
||||
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("")
|
||||
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
# Add the buttons
|
||||
@@ -81,7 +81,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
StartButton = wx.Button(self, label="Start")
|
||||
StartButton.Bind(wx.EVT_BUTTON, self.OnStart)
|
||||
|
||||
|
||||
StopButton = wx.Button(self, label="Stop")
|
||||
StopButton.Bind(wx.EVT_BUTTON, self.OnStop)
|
||||
|
||||
@@ -93,7 +93,7 @@ class DrawFrame(wx.Frame):
|
||||
NC = NavCanvas.NavCanvas(self, -1, (500,500),
|
||||
Debug = False,
|
||||
BackgroundColor = "BLUE")
|
||||
|
||||
|
||||
self.Canvas = NC.Canvas
|
||||
self.Initialize(None)
|
||||
|
||||
@@ -107,30 +107,30 @@ class DrawFrame(wx.Frame):
|
||||
self.Bind(wx.EVT_TIMER, self.MoveBall, self.timer)
|
||||
|
||||
self.Show(True)
|
||||
|
||||
|
||||
def OnQuit(self,event):
|
||||
self.timer.Stop()
|
||||
self.Close(True)
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def Initialize(self, event=None):
|
||||
Canvas = self.Canvas
|
||||
|
||||
Canvas = self.Canvas
|
||||
|
||||
#Add the floor
|
||||
Canvas.AddLine(( (0, 0), (100, 0) ), LineWidth=4, LineColor="Black")
|
||||
# add the wall:
|
||||
Canvas.AddRectangle( (0,0), (10,50), FillColor='green')
|
||||
|
||||
# add the ball:
|
||||
self.Ball = Ball( (5, 52), (2, 0), InForeground=True )
|
||||
self.Ball = Ball( (5, 52), (2, 0), InForeground=True )
|
||||
Canvas.AddObject( self.Ball )
|
||||
# to capture the mouse to move the ball
|
||||
self.Ball.Bind(FC.EVT_FC_LEFT_DOWN, self.BallHit)
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
wx.CallAfter(Canvas.ZoomToBB)
|
||||
|
||||
def BallHit(self, object):
|
||||
@@ -150,12 +150,12 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
def OnLeftUp(self, event):
|
||||
self.Ball.Moving = False
|
||||
|
||||
|
||||
def OnReset(self, event=None):
|
||||
self.Ball.SetPoint( (5, 52) )
|
||||
self.Ball.Velocity = np.array((1.5, 0.0))
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
|
||||
def OnStart(self, event=None):
|
||||
self.timer.Start(20)
|
||||
|
||||
@@ -171,7 +171,7 @@ class DrawFrame(wx.Frame):
|
||||
A = np.pi*(ball.Radius/100)**2 # radius in cm
|
||||
Cd = 0.47
|
||||
rho = 1.3
|
||||
|
||||
|
||||
if not ball.Moving: # don't do this if the user is moving it
|
||||
vel = ball.Velocity
|
||||
pos = ball.XY
|
||||
@@ -179,9 +179,9 @@ class DrawFrame(wx.Frame):
|
||||
# apply drag
|
||||
vel -= np.sign(vel) * ((0.5 * Cd * rho * A * vel**2) / m * dt)
|
||||
# apply gravity
|
||||
vel[1] -= g * dt
|
||||
vel[1] -= g * dt
|
||||
# move the ball
|
||||
pos += dt * vel
|
||||
pos += dt * vel
|
||||
# check if it's on the wall
|
||||
if pos[1] <= 52. and pos[0] <= 10.:
|
||||
#reverse velocity
|
||||
@@ -193,10 +193,10 @@ class DrawFrame(wx.Frame):
|
||||
vel[1] *= -1.0
|
||||
pos[1] = ball.Radius
|
||||
|
||||
self.Ball.SetPoint( pos )
|
||||
self.Ball.SetPoint( pos )
|
||||
self.Canvas.Draw(True)
|
||||
wx.GetApp().Yield(onlyIfNeeded=True)
|
||||
|
||||
|
||||
class DemoApp(wx.App):
|
||||
def OnInit(self):
|
||||
frame = DrawFrame(None, -1, "Simple Drawing Window",wx.DefaultPosition, (700,700) )
|
||||
@@ -204,10 +204,10 @@ class DemoApp(wx.App):
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app = DemoApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ class DrawFrame(wx.Frame):
|
||||
# Debug = 0,
|
||||
# BackgroundColor = "White",
|
||||
# )
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeft)
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class DrawFrame(wx.Frame):
|
||||
self.SpaceWidth = 1
|
||||
self.Labels = ["SW Tasks", "Set RX Rf"] + ["A Row Label"]*16
|
||||
self.NumRows = len(self.Labels)
|
||||
|
||||
|
||||
self.BuildChartBackground()
|
||||
self.AddLabels()
|
||||
self.Show()
|
||||
@@ -69,20 +69,20 @@ class DrawFrame(wx.Frame):
|
||||
LineColor = None,
|
||||
FillColor = "LightGrey",
|
||||
FillStyle = "Solid",)
|
||||
|
||||
|
||||
# put a dashed line in every 1 unit:
|
||||
for i in range(16):
|
||||
Canvas.AddLine(((i*self.SpaceWidth,bottom),(i*self.SpaceWidth,top)),
|
||||
LineColor = "Black",
|
||||
LineStyle = "Dot",
|
||||
# or "Dot", "ShortDash", "LongDash","ShortDash", "DotDash"
|
||||
# or "Dot", "ShortDash", "LongDash","ShortDash", "DotDash"
|
||||
LineWidth = 1,)
|
||||
def AddLabels(self):
|
||||
Canvas = self.Canvas
|
||||
|
||||
for i, label in enumerate(self.Labels):
|
||||
Canvas.AddScaledText(label,
|
||||
( -self.TextWidth, -(i+0.2)*self.LineHeight ),
|
||||
( -self.TextWidth, -(i+0.2)*self.LineHeight ),
|
||||
Size = 0.6 * self.LineHeight,
|
||||
Color = "Black",
|
||||
BackgroundColor = None,
|
||||
@@ -111,10 +111,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
||||
#from floatcanvas import FloatCanvas as FC
|
||||
|
||||
|
||||
colors = [ (255, 0 , 0 ),
|
||||
(0 , 255, 0 ),
|
||||
(0 , 0, 255),
|
||||
colors = [ (255, 0 , 0 ),
|
||||
(0 , 255, 0 ),
|
||||
(0 , 0, 255),
|
||||
(255, 255, 0 ),
|
||||
(255, 0, 255),
|
||||
(0 , 255, 255),
|
||||
@@ -49,11 +49,11 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "Black",
|
||||
)
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
|
||||
# build the squares:
|
||||
w = 10
|
||||
dx = 14
|
||||
@@ -104,10 +104,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "White",
|
||||
).Canvas
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
self.MakePic()
|
||||
|
||||
|
||||
return None
|
||||
|
||||
def MakePic(self):
|
||||
@@ -69,4 +69,4 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App()
|
||||
DrawFrame(None, -1, "FloatCanvas Demo App", wx.DefaultPosition, (700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
NC = NavCanvas.NavCanvas(self,
|
||||
size= (500,500),
|
||||
@@ -40,10 +40,10 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
)
|
||||
|
||||
|
||||
self.Canvas = NC.Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
# Add some buttons to the Toolbar
|
||||
tb = NC.ToolBar
|
||||
@@ -65,7 +65,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.RBBoxMode = GUI.RubberBandBox(self.NewRect)
|
||||
self.Canvas.SetMode(self.RBBoxMode)
|
||||
|
||||
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
self.Show(True)
|
||||
@@ -102,10 +102,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App()
|
||||
DrawFrame(None, -1, "FloatCanvas Rectangle Drawer", wx.DefaultPosition, (700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
|
||||
|
||||
Point = (45,40)
|
||||
Box = Canvas.AddCircle(Point,
|
||||
Diameter = 10,
|
||||
@@ -52,7 +52,7 @@ class DrawFrame(wx.Frame):
|
||||
Canvas.GridUnder = Grid
|
||||
#Canvas.GridOver = Grid
|
||||
|
||||
Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
@@ -69,10 +69,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False) # true to get its own output window.
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class DrawFrame(wx.Frame):
|
||||
Canvas = NC.Canvas
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
Point = (45,40)
|
||||
|
||||
@@ -52,7 +52,7 @@ class DrawFrame(wx.Frame):
|
||||
self.GroupA.AddObjects((C2,T))
|
||||
Canvas.AddObject(self.GroupA)
|
||||
|
||||
|
||||
|
||||
## create another Groups of objects
|
||||
|
||||
R = FloatCanvas.Rectangle((15, 15),(10, 18), FillColor="orange")
|
||||
@@ -63,7 +63,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.GroupB = FloatCanvas.Group((R,E,C,C2,T))
|
||||
Canvas.AddObject(self.GroupB)
|
||||
|
||||
|
||||
self.Groups = {"A":self.GroupA, "B":self.GroupB}
|
||||
|
||||
# Add a couple of tools to the Canvas Toolbar
|
||||
@@ -106,10 +106,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class DrawFrame(wx.Frame):
|
||||
Canvas = NC.Canvas
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
Point = (45,40)
|
||||
|
||||
@@ -52,7 +52,7 @@ class DrawFrame(wx.Frame):
|
||||
self.GroupA.AddObjects((C2,T))
|
||||
Canvas.AddObject(self.GroupA)
|
||||
|
||||
|
||||
|
||||
## create another Groups of objects
|
||||
|
||||
R = FloatCanvas.Rectangle((15, 15),(10, 18), FillColor="orange")
|
||||
@@ -63,7 +63,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.GroupB = FloatCanvas.Group((R,E,C,C2,T))
|
||||
Canvas.AddObject(self.GroupB)
|
||||
|
||||
|
||||
self.Groups = {"A":self.GroupA, "B":self.GroupB}
|
||||
|
||||
# Add a couple of tools to the Canvas Toolbar
|
||||
@@ -96,10 +96,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class DrawFrame(wx.Frame):
|
||||
def MakeHexagons(self):
|
||||
print("Building %i Hexagons"%NumHexagons)
|
||||
# get a list of colors for random colors
|
||||
|
||||
|
||||
wx.lib.colourdb.updateColourDB()
|
||||
self.colors = wx.lib.colourdb.getColourList()
|
||||
print("Max colors:", len(self.colors))
|
||||
@@ -63,7 +63,7 @@ class DrawFrame(wx.Frame):
|
||||
(-D , 0),
|
||||
(-D/2, h),
|
||||
(D/2 , h),
|
||||
))
|
||||
))
|
||||
Centers = uniform(-100, 100, (NumHexagons, 2))
|
||||
for center in Centers:
|
||||
# scale the hexagon
|
||||
@@ -87,10 +87,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
DrawFrame(None, -1, "FloatCanvas Demo App", wx.DefaultPosition, (700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
|
||||
# Add the Canvas
|
||||
NC = NavCanvas.NavCanvas(self,-1,
|
||||
@@ -33,10 +33,10 @@ class DrawFrame(wx.Frame):
|
||||
BackgroundColor = "White",
|
||||
)
|
||||
self.Canvas = NC.Canvas
|
||||
|
||||
|
||||
self.LoadMap(TestFileName)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
self.Show()
|
||||
self.Canvas.ZoomToBB()
|
||||
@@ -73,5 +73,5 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
Point = (45,40)
|
||||
Text = Canvas.AddScaledText("A String",
|
||||
@@ -68,10 +68,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DrawFrame(wx.Frame):
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
|
||||
|
||||
@@ -286,25 +286,25 @@ class DrawFrame(wx.Frame):
|
||||
elif Dir == "down": Y -= 10
|
||||
Object.SetPoint((X,Y))
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
|
||||
def UnBindAllMouseEvents(self):
|
||||
## Here is how you catch FloatCanvas mouse events
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DCLICK, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DCLICK, self.dummyHandler)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_DCLICK, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MIDDLE_DCLICK, self.dummyHandler)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_DCLICK, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_DOWN, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_UP, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_RIGHT_DCLICK, self.dummyHandler)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOUSEWHEEL, self.dummyHandler)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOUSEWHEEL, self.dummyHandler)
|
||||
|
||||
self.EventsAreBound = False
|
||||
|
||||
|
||||
def dummyHandler(self, evt):
|
||||
evt.Skip()
|
||||
|
||||
@@ -318,7 +318,7 @@ class DemoApp(wx.App):
|
||||
objects, of each kind supported.
|
||||
|
||||
*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
|
||||
with a lot of data, and will take a while to load and draw (about 10 sec
|
||||
on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
|
||||
performance is not very good for large drawings.
|
||||
|
||||
@@ -326,7 +326,7 @@ class DemoApp(wx.App):
|
||||
|
||||
Once you have a picture drawn, you can zoom in and out and move about
|
||||
the picture. There is a tool bar with three tools that can be
|
||||
selected.
|
||||
selected.
|
||||
|
||||
The magnifying glass with the plus is the zoom in tool. Once selected,
|
||||
if you click the image, it will zoom in, centered on where you
|
||||
@@ -369,10 +369,10 @@ class DemoApp(wx.App):
|
||||
|
||||
app = DemoApp(False)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,25 +19,25 @@ except ImportError:
|
||||
from wx.lib.floatcanvas import NavCanvas, FloatCanvas, GUIMode
|
||||
|
||||
class TestFrame(wx.Frame):
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK SLATE BLUE")
|
||||
|
||||
|
||||
# Layout
|
||||
MainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
MainSizer.Add(self.canvas, 4, wx.EXPAND)
|
||||
self.SetSizer(MainSizer)
|
||||
|
||||
|
||||
self.canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
|
||||
self.canvas.AddRectangle((10,10), (100, 20), FillColor="red")
|
||||
|
||||
|
||||
self.canvas.SetMode(GUIMode.GUIMouse(self.canvas))
|
||||
|
||||
|
||||
wx.CallAfter(self.canvas.ZoomToBB)
|
||||
|
||||
|
||||
def OnLeftDown(self, event):
|
||||
print('Left Button clicked at: %s' % event.Coords)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import numpy as N
|
||||
class MovingObjectMixin:
|
||||
"""
|
||||
Methods required for a Moving object
|
||||
|
||||
|
||||
"""
|
||||
|
||||
def GetOutlinePoints(self):
|
||||
@@ -46,20 +46,20 @@ class MovingObjectMixin:
|
||||
)
|
||||
|
||||
return OutlinePoints
|
||||
|
||||
|
||||
|
||||
class ConnectorObjectMixin:
|
||||
"""
|
||||
Mixin class for DrawObjects that can be connected with lines
|
||||
|
||||
|
||||
NOte that this versionony works for Objects that have an "XY" attribute:
|
||||
that is, one that is derived from XHObjectMixin.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.XY
|
||||
|
||||
|
||||
class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -67,7 +67,7 @@ class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -75,7 +75,7 @@ class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class MovingArc(FC.Arc, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -83,7 +83,7 @@ class MovingArc(FC.Arc, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
"""
|
||||
|
||||
@@ -100,8 +100,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
InForeground = False):
|
||||
FC.DrawObject.__init__(self, InForeground)
|
||||
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.LineColor = LineColor
|
||||
self.LineStyle = LineStyle
|
||||
self.LineWidth = LineWidth
|
||||
@@ -127,8 +127,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
if HTdc and self.HitAble:
|
||||
HTdc.SetPen(self.HitPen)
|
||||
HTdc.DrawLines(Points)
|
||||
|
||||
|
||||
|
||||
|
||||
class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
|
||||
def __init__(self, XY, L):
|
||||
@@ -153,9 +153,9 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
## Override the default OutlinePoints
|
||||
def GetOutlinePoints(self):
|
||||
return self.Points
|
||||
|
||||
|
||||
def CompPoints(self, XY, L):
|
||||
c = L/ N.sqrt(3)
|
||||
c = L/ N.sqrt(3)
|
||||
|
||||
Points = N.array(((0, c),
|
||||
( L/2.0, -c/2.0),
|
||||
@@ -176,24 +176,24 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
Points = N.array(((0,0),
|
||||
(1,0),
|
||||
(0.5, 1)),
|
||||
N.float)
|
||||
|
||||
|
||||
data = (( (0,0), 1),
|
||||
( (3,3), 2),
|
||||
( (-2,3), 2.5 ),
|
||||
@@ -218,16 +218,16 @@ class DrawFrame(wx.Frame):
|
||||
)
|
||||
Line = ConnectorLine(Bitmaps[0], Bitmaps[1], LineWidth=3, LineColor="Red")
|
||||
Canvas.AddObject(Line)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## then add them to the Canvas, so they are on top of the line
|
||||
for bmp in Bitmaps:
|
||||
Canvas.AddObject(bmp)
|
||||
bmp.Bind(FC.EVT_FC_LEFT_DOWN, self.ObjectHit)
|
||||
|
||||
A = MovingArc((-5, 0),(-2, 2),(-5, 2), LineColor="Red", LineWidth=2)
|
||||
self.Canvas.AddObject(A)
|
||||
self.Canvas.AddObject(A)
|
||||
A.Bind(FC.EVT_FC_LEFT_DOWN, self.ObjectHit)
|
||||
|
||||
self.Show(True)
|
||||
@@ -272,7 +272,7 @@ class DrawFrame(wx.Frame):
|
||||
if self.MoveObject is not None:
|
||||
dxy = event.GetPosition() - self.StartPoint
|
||||
dxy = self.Canvas.ScalePixelToWorld(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.MoveTri = None
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class DrawFrame(wx.Frame):
|
||||
self.timer = None
|
||||
|
||||
self.DrawAxis()
|
||||
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ class TriangleShape1(FC.Polygon, ShapeMixin):
|
||||
FillColor = "Red",
|
||||
FillStyle = "Solid")
|
||||
ShapeMixin.__init__(self)
|
||||
|
||||
|
||||
def CompPoints(self, XY, L):
|
||||
c = L/ N.sqrt(3)
|
||||
c = L/ N.sqrt(3)
|
||||
|
||||
Points = N.array(((0, c),
|
||||
( L/2.0, -c/2.0),
|
||||
@@ -80,18 +80,18 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
Canvas.AddRectangle((-5,-5),
|
||||
(10,10),
|
||||
@@ -105,7 +105,7 @@ class DrawFrame(wx.Frame):
|
||||
(1,0),
|
||||
(0.5, 1)),
|
||||
N.float_)
|
||||
|
||||
|
||||
data = (( (0,0), 1),
|
||||
( (3,3), 2),
|
||||
( (-2,3), 2.5 ),
|
||||
@@ -174,10 +174,10 @@ if __name__ == "__main__":
|
||||
x = DrawFrame(None, -1, "FloatCanvas TextBox Test App", wx.DefaultPosition, (700,700) )
|
||||
x.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ class DrawFrame(wx.Frame):
|
||||
size = (500,500),
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
)
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
Point = (45,40)
|
||||
Box = Canvas.AddScaledTextBox("A Two Line\nString",
|
||||
@@ -78,10 +78,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ A simple demo to show how to "Overlays": i.e. drawing something
|
||||
on top of eveything else on the Canvas, relative to window coords,
|
||||
rather than screen coords.
|
||||
|
||||
This method uses the "GridOver" object in the FloatCanvas
|
||||
This method uses the "GridOver" object in the FloatCanvas
|
||||
- it was orginally dsigend for girds, graticule,s etc. that
|
||||
are always drawn regardless of zoom, pan, etc, but it works
|
||||
for overlays too.
|
||||
for overlays too.
|
||||
|
||||
"""
|
||||
|
||||
@@ -28,7 +28,7 @@ class TextOverlay(FloatCanvas.Text):
|
||||
An example of an Overlay object:
|
||||
|
||||
all it needs is a new _Draw method.
|
||||
|
||||
|
||||
NOTE: you may want to get fancier with this,
|
||||
deriving from ScaledTextBox
|
||||
|
||||
@@ -94,8 +94,8 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
|
||||
|
||||
Point = (45,40)
|
||||
Box = Canvas.AddCircle(Point,
|
||||
Diameter = 10,
|
||||
@@ -110,7 +110,7 @@ class DrawFrame(wx.Frame):
|
||||
BackgroundColor = 'Pink',
|
||||
)
|
||||
|
||||
Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
@@ -127,10 +127,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False) # true to get its own output window.
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,29 +34,29 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
Values = (10,10,10)
|
||||
Colors = ('Red', 'Blue', 'Green')
|
||||
Pie1 = PieChart(N.array((0, 0)), 10, Values, Colors, Scaled=False)
|
||||
Canvas.AddObject(Pie1)
|
||||
|
||||
|
||||
Values = (10, 5, 5)
|
||||
Pie2 = PieChart(N.array((40, 0)), 10, Values, Colors)
|
||||
Canvas.AddObject(Pie2)
|
||||
|
||||
|
||||
# test default colors
|
||||
Values = (10, 15, 12, 24, 6, 10, 13, 11, 9, 13, 15, 12)
|
||||
Pie3 = PieChart(N.array((20, 20)), 10, Values, LineColor="Black")
|
||||
Canvas.AddObject(Pie3)
|
||||
|
||||
|
||||
# missng slice!
|
||||
Values = (10, 15, 12, 24)
|
||||
Colors = ('Red', 'Blue', 'Green', None)
|
||||
Pie4 = PieChart(N.array((0, -15)), 10, Values, Colors, LineColor="Black")
|
||||
Canvas.AddObject(Pie4)
|
||||
|
||||
|
||||
|
||||
# Test the styles
|
||||
Values = (10, 12, 14)
|
||||
@@ -68,7 +68,7 @@ class DrawFrame(wx.Frame):
|
||||
Pie1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Pie1Hit)
|
||||
Pie2.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Pie2Hit)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
|
||||
@@ -20,27 +20,27 @@ FC = FloatCanvas
|
||||
class PixelBitmap:
|
||||
"""
|
||||
An unscaled bitmap that can be put on top of the canvas using:
|
||||
|
||||
|
||||
Canvas.GridOver = MyPixelBitmap
|
||||
|
||||
|
||||
It will always be drawn on top of everything else, and be positioned
|
||||
according to pixel coordinates on teh screen, regardless of zoom and
|
||||
pan position.
|
||||
|
||||
|
||||
"""
|
||||
def __init__(self, Bitmap, XY, Position = 'tl'):
|
||||
"""
|
||||
PixelBitmap (Bitmap, XY, Position='tl')
|
||||
|
||||
Bitmap is a wx.Bitmap or wx.Image
|
||||
|
||||
|
||||
XY is the (x,y) location to place the bitmap, in pixel coordinates
|
||||
|
||||
|
||||
Position indicates from where in the window the position is relative to:
|
||||
'tl' indicated the position from the top left the the window (the detault)
|
||||
'br' the bottom right
|
||||
'cr the center right, etc.
|
||||
|
||||
|
||||
"""
|
||||
if type(Bitmap) == wx.Bitmap:
|
||||
self.Bitmap = Bitmap
|
||||
@@ -51,7 +51,7 @@ class PixelBitmap:
|
||||
|
||||
self.XY = np.asarray(XY, dtype=np.int).reshape((2,))
|
||||
self.Position = Position
|
||||
|
||||
|
||||
(self.Width, self.Height) = self.Bitmap.GetWidth(), self.Bitmap.GetHeight()
|
||||
self.ShiftFun = FC.TextObjectMixin.ShiftFunDict[Position]
|
||||
|
||||
@@ -62,7 +62,7 @@ class PixelBitmap:
|
||||
XY = (XY[0], h - XY[1] - self.Height)
|
||||
elif self.Position[0] == 'c':
|
||||
XY = (XY[0], XY[1] + (h - self.Height)/2)
|
||||
|
||||
|
||||
if self.Position[1] == 'r':
|
||||
XY = (w - XY[0] - self.Width, XY[1])
|
||||
elif self.Position[1] == 'c':
|
||||
@@ -77,7 +77,7 @@ class GridGroup:
|
||||
def _Draw(self, *args):
|
||||
for grid in self.Grids:
|
||||
grid._Draw(*args)
|
||||
|
||||
|
||||
class DrawFrame(wx.Frame):
|
||||
|
||||
"""
|
||||
@@ -97,8 +97,8 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
|
||||
|
||||
Point = (45,40)
|
||||
Box = Canvas.AddCircle(Point,
|
||||
Diameter = 10,
|
||||
@@ -118,7 +118,7 @@ class DrawFrame(wx.Frame):
|
||||
])
|
||||
Canvas.GridOver = grids
|
||||
|
||||
FloatCanvas.EVT_MOTION(Canvas, self.OnMove )
|
||||
FloatCanvas.EVT_MOTION(Canvas, self.OnMove )
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
@@ -135,10 +135,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False) # true to get its own output window.
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,16 +30,16 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
Pts = ((45,40), (20, 15), (10, 40), (30,30))
|
||||
|
||||
|
||||
Points = Canvas.AddPointSet(Pts, Diameter=3, Color="Red")
|
||||
Points.HitLineWidth = 10
|
||||
|
||||
|
||||
Points.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.OnOverPoints)
|
||||
Points.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.OnLeavePoints)
|
||||
Points.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnLeftDown)
|
||||
@@ -66,10 +66,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
self.Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
Debug = 0,
|
||||
@@ -59,9 +59,9 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnLeftUp)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftClick)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnLeftUp)
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftClick)
|
||||
|
||||
self.ResetSelections()
|
||||
|
||||
@@ -226,12 +226,12 @@ class PolyEditor(wx.App):
|
||||
|
||||
PolyEditor(0).MainLoop()# put in True if you want output to go to it's own window.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,16 +33,16 @@ import numpy as N
|
||||
class MovingObjectMixin:
|
||||
"""
|
||||
Methods required for a Moving object
|
||||
|
||||
|
||||
"""
|
||||
def GetOutlinePoints(self):
|
||||
"""
|
||||
Returns a set of points with which to draw the outline when moving the
|
||||
Returns a set of points with which to draw the outline when moving the
|
||||
object.
|
||||
|
||||
|
||||
Points are a NX2 array of (x,y) points in World coordinates.
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
BB = self.BoundingBox
|
||||
OutlinePoints = N.array( ( (BB[0,0], BB[0,1]),
|
||||
@@ -57,15 +57,15 @@ class MovingObjectMixin:
|
||||
class ConnectorObjectMixin:
|
||||
"""
|
||||
Mixin class for DrawObjects that can be connected with lines
|
||||
|
||||
|
||||
Note that this version only works for Objects that have an "XY" attribute:
|
||||
that is, one that is derived from XHObjectMixin.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.XY
|
||||
|
||||
|
||||
class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -73,7 +73,7 @@ class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -84,10 +84,10 @@ class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
|
||||
class MovingGroup(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.BoundingBox.Center
|
||||
|
||||
|
||||
class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
A version of the moving group for nodes -- an ellipse with text on it.
|
||||
@@ -117,7 +117,7 @@ class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.BoundingBox.Center
|
||||
|
||||
|
||||
|
||||
class MovingText(FC.ScaledText, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
@@ -134,7 +134,7 @@ class MovingTextBox(FC.ScaledTextBox, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
"""
|
||||
|
||||
@@ -152,8 +152,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
InForeground = False):
|
||||
FC.DrawObject.__init__(self, InForeground)
|
||||
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.LineColor = LineColor
|
||||
self.LineStyle = LineStyle
|
||||
self.LineWidth = LineWidth
|
||||
@@ -179,8 +179,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
if HTdc and self.HitAble:
|
||||
HTdc.SetPen(self.HitPen)
|
||||
HTdc.DrawLines(Points)
|
||||
|
||||
|
||||
|
||||
|
||||
class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
|
||||
def __init__(self, XY, L):
|
||||
@@ -205,9 +205,9 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
## Override the default OutlinePoints
|
||||
def GetOutlinePoints(self):
|
||||
return self.Points
|
||||
|
||||
|
||||
def CompPoints(self, XY, L):
|
||||
c = L/ N.sqrt(3)
|
||||
c = L/ N.sqrt(3)
|
||||
|
||||
Points = N.array(((0, c),
|
||||
( L/2.0, -c/2.0),
|
||||
@@ -232,7 +232,7 @@ class TreeNode:
|
||||
def __str__(self):
|
||||
return "TreeNode: %s"%self.Name
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
|
||||
## Build Tree:
|
||||
leaves = [TreeNode(name) for name in ["Assistant VP 1","Assistant VP 2","Assistant VP 3"] ]
|
||||
@@ -246,12 +246,12 @@ elements = TreeNode("Root", [CEO, Father])
|
||||
def LayoutTree(root, x, y, level):
|
||||
NumNodes = len(root.Children)
|
||||
root.Point = (x,y)
|
||||
x += root.dx
|
||||
x += root.dx
|
||||
y += (root.dy * level * (NumNodes-1) / 2.0)
|
||||
for node in root.Children:
|
||||
LayoutTree(node, x, y, level-1)
|
||||
y -= root.dy * level
|
||||
|
||||
|
||||
def TraverseTree(root, func):
|
||||
func(root)
|
||||
for child in (root.Children):
|
||||
@@ -267,25 +267,25 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "White",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
self.elements = elements
|
||||
LayoutTree(self.elements, 0, 0, 3)
|
||||
self.AddTree(self.elements)
|
||||
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
@@ -319,7 +319,7 @@ class DrawFrame(wx.Frame):
|
||||
node.DrawObject = object
|
||||
Nodes.append(object)
|
||||
def AddConnectors(node):
|
||||
for child in node.Children:
|
||||
for child in node.Children:
|
||||
Connector = ConnectorLine(node.DrawObject, child.DrawObject, LineWidth=3, LineColor="Red")
|
||||
Connectors.append(Connector)
|
||||
## create the Objects
|
||||
@@ -327,14 +327,14 @@ class DrawFrame(wx.Frame):
|
||||
## create the Connectors
|
||||
TraverseTree(root, AddConnectors)
|
||||
## Add the conenctos to the Canvas first, so they are undernieth the nodes
|
||||
self.Canvas.AddObjects(Connectors)
|
||||
self.Canvas.AddObjects(Connectors)
|
||||
## now add the nodes
|
||||
self.Canvas.AddObjects(Nodes)
|
||||
self.Canvas.AddObjects(Nodes)
|
||||
# Now bind the Nodes -- DrawObjects must be Added to a Canvas before they can be bound.
|
||||
for node in Nodes:
|
||||
#pass
|
||||
node.Bind(FC.EVT_FC_LEFT_DOWN, self.ObjectHit)
|
||||
|
||||
|
||||
|
||||
|
||||
def ObjectHit(self, object):
|
||||
@@ -371,7 +371,7 @@ class DrawFrame(wx.Frame):
|
||||
if self.MoveObject is not None:
|
||||
dxy = event.GetPosition() - self.StartPoint
|
||||
dxy = self.Canvas.ScalePixelToWorld(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
app = wx.App(0)
|
||||
|
||||
@@ -51,9 +51,9 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
|
||||
Point = N.array((50e-6, 0))
|
||||
Size = N.array(( (2000e-6 - 5e-6), 50000))
|
||||
Box = Canvas.AddRectangle(Point,
|
||||
@@ -64,14 +64,14 @@ class DrawFrame(wx.Frame):
|
||||
Canvas.AddText("%s"%(Point,), Point, Position="cr")
|
||||
Canvas.AddPoint(Point, Diameter=3, Color = "red")
|
||||
|
||||
|
||||
|
||||
Point = Point + Size
|
||||
Canvas.AddText("%s"%(Point,), Point, Position="cl")
|
||||
Canvas.AddPoint(Point, Diameter=3, Color = "red")
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
|
||||
@@ -85,10 +85,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ but uses memory more efficiently for large images and high zoom levels.)
|
||||
"""
|
||||
|
||||
## Set a path to an Image file here:
|
||||
ImageFile = "white_tank.jpg"
|
||||
ImageFile = "white_tank.jpg"
|
||||
|
||||
|
||||
import wx
|
||||
@@ -41,9 +41,9 @@ class DrawFrame(wx.Frame):
|
||||
Canvas.MaxScale=20 # sets the maximum zoom level
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
|
||||
|
||||
# create the image:
|
||||
image = wx.Image(ImageFile)
|
||||
self.width, self.height = image.GetSize()
|
||||
@@ -53,10 +53,10 @@ class DrawFrame(wx.Frame):
|
||||
Position = 'tl',
|
||||
)
|
||||
Canvas.AddObject(img)
|
||||
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
|
||||
|
||||
def OnMove(self, event):
|
||||
"""
|
||||
Updates the status bar with the world coordinates
|
||||
@@ -68,10 +68,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class MyFrame(wx.Frame):
|
||||
Position = 'br',
|
||||
Alignment = "left",
|
||||
InForeground = False)
|
||||
|
||||
|
||||
wx.CallAfter(Canvas.ZoomToBB)
|
||||
|
||||
# set up the Splitter
|
||||
@@ -56,7 +56,7 @@ class MyFrame(wx.Frame):
|
||||
splitter.SplitVertically(panel1, panel2, sash_Position)
|
||||
min_Pan_size = 40
|
||||
splitter.SetMinimumPaneSize(min_Pan_size)
|
||||
|
||||
|
||||
self.Fit()
|
||||
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
self.CreateStatusBar()
|
||||
|
||||
|
||||
panel = NavPanel(self)
|
||||
|
||||
|
||||
self.Show()
|
||||
|
||||
class NavPanel(NavCanvas.NavCanvas):
|
||||
@@ -40,10 +40,10 @@ class NavPanel(NavCanvas.NavCanvas):
|
||||
ProjectionFun = None,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
)
|
||||
|
||||
|
||||
self.parent_frame = parent
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
|
||||
|
||||
# create the image:
|
||||
self.Canvas.AddPolygon( ( (2,3),
|
||||
(5,6),
|
||||
@@ -51,9 +51,9 @@ class NavPanel(NavCanvas.NavCanvas):
|
||||
FillColor = "red",
|
||||
)
|
||||
|
||||
|
||||
|
||||
wx.CallAfter(self.Canvas.ZoomToBB) # so it will get called after everything is created and sized
|
||||
|
||||
|
||||
def OnMove(self, event):
|
||||
"""
|
||||
Updates the status bar with the world coordinates
|
||||
|
||||
@@ -23,7 +23,7 @@ from wx.lib.floatcanvas import NavCanvas
|
||||
class Spline(FC.Line):
|
||||
def __init__(self, *args, **kwargs):
|
||||
FC.Line.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||
Points = WorldToPixel(self.Points)
|
||||
dc.SetPen(self.Pen)
|
||||
@@ -56,21 +56,21 @@ class DrawFrame(wx.Frame):
|
||||
MenuBar.Append(help_menu, "&Help")
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
|
||||
# Add the Canvas
|
||||
self.Canvas = NavCanvas.NavCanvas(self,
|
||||
BackgroundColor = "White",
|
||||
).Canvas
|
||||
|
||||
self.Canvas.Bind(FC.EVT_MOTION, self.OnMove)
|
||||
self.Canvas.Bind(FC.EVT_MOTION, self.OnMove)
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
self.DrawTest()
|
||||
self.Show()
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
|
||||
def OnAbout(self, event):
|
||||
print("OnAbout called")
|
||||
|
||||
@@ -94,7 +94,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
def DrawTest(self,event=None):
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
Canvas = self.Canvas
|
||||
|
||||
Points = [(0, 0),
|
||||
@@ -135,7 +135,7 @@ class DrawFrame(wx.Frame):
|
||||
MyLine = FC.Spline(Points,
|
||||
LineWidth = 3,
|
||||
LineColor = "Blue")
|
||||
|
||||
|
||||
Canvas.AddObject(MyLine)
|
||||
Canvas.AddPointSet(Points,
|
||||
Color = "Red",
|
||||
@@ -148,7 +148,7 @@ class DrawFrame(wx.Frame):
|
||||
(70, 185),
|
||||
(160,60),
|
||||
]
|
||||
|
||||
|
||||
Canvas.AddSpline(Points,
|
||||
LineWidth = 5,
|
||||
LineColor = "Purple")
|
||||
@@ -163,7 +163,7 @@ class DemoApp(wx.App):
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
return True
|
||||
|
||||
|
||||
app = DemoApp(False)# put in True if you want output to go to it's own window.
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
||||
#from floatcanvas import NavCanvas, FloatCanvas
|
||||
|
||||
import numpy as N
|
||||
|
||||
|
||||
class DrawFrame(wx.Frame):
|
||||
|
||||
"""
|
||||
@@ -28,16 +28,16 @@ class DrawFrame(wx.Frame):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
# Add the Canvas
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
Point = (45,40)
|
||||
Box = Canvas.AddScaledTextBox("A Two Line\nString",
|
||||
Point,
|
||||
@@ -265,7 +265,7 @@ class DrawFrame(wx.Frame):
|
||||
LineSpacing = 0.8,
|
||||
Alignment = 'center',
|
||||
)
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
self.Canvas.ZoomToBB()
|
||||
@@ -287,10 +287,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App()
|
||||
DrawFrame(None, -1, "FloatCanvas Demo App", wx.DefaultPosition, (700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ This is another paragraph. I am trying to make it long enough to wrap a reasonab
|
||||
##LongString = (
|
||||
##""" This is a not so long string
|
||||
##Another line""")
|
||||
|
||||
|
||||
class DrawFrame(wx.Frame):
|
||||
|
||||
"""
|
||||
@@ -48,23 +48,23 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnLeftUp )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnLeftUp )
|
||||
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
|
||||
Point = N.array((0,0), N.float)
|
||||
|
||||
|
||||
|
||||
|
||||
Canvas.AddCircle(Point,
|
||||
|
||||
@@ -76,7 +76,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
Width = 300
|
||||
self.Box = Canvas.AddScaledTextBox(LongString,
|
||||
Point,
|
||||
@@ -93,19 +93,19 @@ class DrawFrame(wx.Frame):
|
||||
Weight = wx.NORMAL,
|
||||
Underlined = False,
|
||||
Position = 'tl',
|
||||
LineSpacing = 0.8,
|
||||
LineSpacing = 0.8,
|
||||
Alignment = "left",
|
||||
#Alignment = "center",
|
||||
#Alignment = "right",
|
||||
InForeground = False)
|
||||
|
||||
|
||||
|
||||
self.Handle1 = Canvas.AddBitmap(Resources.getMoveCursorBitmap(), Point, Position='cc')
|
||||
self.Handle2a = Canvas.AddBitmap(Resources.getMoveRLCursorBitmap(), Point, Position='cc')
|
||||
self.Handle2b = Canvas.AddBitmap(Resources.getMoveRLCursorBitmap(), Point, Position='cc')
|
||||
|
||||
self.SetHandles()
|
||||
|
||||
|
||||
self.Handle1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle1Hit)
|
||||
self.Handle2a.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle2Hit)
|
||||
self.Handle2b.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle2Hit)
|
||||
@@ -177,7 +177,7 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
def OnLeftDown(self, event):
|
||||
pass
|
||||
|
||||
|
||||
def OnLeftUp(self, event):
|
||||
if self.Resizing:
|
||||
self.Resizing = False
|
||||
@@ -196,7 +196,7 @@ class DrawFrame(wx.Frame):
|
||||
self.ResizeRect = None
|
||||
# self.Box.SetPoint(Point1)
|
||||
self.SetHandles()
|
||||
|
||||
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
def SetHandles(self):
|
||||
@@ -208,15 +208,15 @@ class DrawFrame(wx.Frame):
|
||||
y -= h/3
|
||||
self.Handle2b.SetPoint((x,y))
|
||||
self.Handle1.SetPoint(self.Box.XY)
|
||||
|
||||
|
||||
|
||||
app = wx.App()
|
||||
DrawFrame(None, -1, "FloatCanvas TextBox Test App", wx.DefaultPosition, (700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"Another Name","Another Type", 19
|
||||
"Another Name","Another Type", 19
|
||||
-81.531753540039,31.134635925293
|
||||
-81.531150817871,31.134529113769
|
||||
-81.530662536621,31.134353637695
|
||||
@@ -18,7 +18,7 @@
|
||||
-81.532928466797,31.135110855102
|
||||
-81.532447814941,31.134794235229
|
||||
-81.532341003418,31.134586334229
|
||||
"A third 'name'","6", 7
|
||||
"A third 'name'","6", 7
|
||||
-81.522369384766,31.122062683106
|
||||
-81.522109985352,31.121908187866
|
||||
-81.522010803223,31.121685028076
|
||||
@@ -26,7 +26,7 @@
|
||||
-81.522483825684,31.121797561646
|
||||
-81.522514343262,31.122062683106
|
||||
-81.522369384766,31.122062683106
|
||||
"8223","1", 9
|
||||
"8223","1", 9
|
||||
-81.523277282715,31.122261047363
|
||||
-81.522987365723,31.121982574463
|
||||
-81.523200988770,31.121547698975
|
||||
|
||||
@@ -33,16 +33,16 @@ import numpy as N
|
||||
class MovingObjectMixin:
|
||||
"""
|
||||
Methods required for a Moving object
|
||||
|
||||
|
||||
"""
|
||||
def GetOutlinePoints(self):
|
||||
"""
|
||||
Returns a set of points with which to draw the outline when moving the
|
||||
Returns a set of points with which to draw the outline when moving the
|
||||
object.
|
||||
|
||||
|
||||
Points are a NX2 array of (x,y) points in World coordinates.
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
BB = self.BoundingBox
|
||||
OutlinePoints = N.array( ( (BB[0,0], BB[0,1]),
|
||||
@@ -57,15 +57,15 @@ class MovingObjectMixin:
|
||||
class ConnectorObjectMixin:
|
||||
"""
|
||||
Mixin class for DrawObjects that can be connected with lines
|
||||
|
||||
|
||||
Note that this version only works for Objects that have an "XY" attribute:
|
||||
that is, one that is derived from XHObjectMixin.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.XY
|
||||
|
||||
|
||||
class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -73,7 +73,7 @@ class MovingBitmap(FC.ScaledBitmap, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
ScaledBitmap Object that can be moved
|
||||
@@ -84,10 +84,10 @@ class MovingCircle(FC.Circle, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
|
||||
class MovingGroup(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.BoundingBox.Center
|
||||
|
||||
|
||||
class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
A version of the moving group for nodes -- an ellipse with text on it.
|
||||
@@ -117,7 +117,7 @@ class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
|
||||
|
||||
def GetConnectPoint(self):
|
||||
return self.BoundingBox.Center
|
||||
|
||||
|
||||
|
||||
class MovingText(FC.ScaledText, MovingObjectMixin, ConnectorObjectMixin):
|
||||
"""
|
||||
@@ -126,7 +126,7 @@ class MovingText(FC.ScaledText, MovingObjectMixin, ConnectorObjectMixin):
|
||||
## All we need to do is is inherit from:
|
||||
## ScaledBitmap, MovingObjectMixin and ConnectorObjectMixin
|
||||
pass
|
||||
|
||||
|
||||
class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
"""
|
||||
|
||||
@@ -144,8 +144,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
InForeground = False):
|
||||
FC.DrawObject.__init__(self, InForeground)
|
||||
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.Object1 = Object1
|
||||
self.Object2 = Object2
|
||||
self.LineColor = LineColor
|
||||
self.LineStyle = LineStyle
|
||||
self.LineWidth = LineWidth
|
||||
@@ -171,8 +171,8 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
|
||||
if HTdc and self.HitAble:
|
||||
HTdc.SetPen(self.HitPen)
|
||||
HTdc.DrawLines(Points)
|
||||
|
||||
|
||||
|
||||
|
||||
class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
|
||||
def __init__(self, XY, L):
|
||||
@@ -197,9 +197,9 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
|
||||
## Override the default OutlinePoints
|
||||
def GetOutlinePoints(self):
|
||||
return self.Points
|
||||
|
||||
|
||||
def CompPoints(self, XY, L):
|
||||
c = L/ N.sqrt(3)
|
||||
c = L/ N.sqrt(3)
|
||||
|
||||
Points = N.array(((0, c),
|
||||
( L/2.0, -c/2.0),
|
||||
@@ -224,7 +224,7 @@ class TreeNode:
|
||||
def __str__(self):
|
||||
return "TreeNode: %s"%self.Name
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
|
||||
## Build Tree:
|
||||
leaves = [TreeNode(name) for name in ["Assistant VP 1","Assistant VP 2","Assistant VP 3"] ]
|
||||
@@ -238,12 +238,12 @@ elements = TreeNode("Root", [CEO, Father])
|
||||
def LayoutTree(root, x, y, level):
|
||||
NumNodes = len(root.Children)
|
||||
root.Point = (x,y)
|
||||
x += root.dx
|
||||
x += root.dx
|
||||
y += (root.dy * level * (NumNodes-1) / 2.0)
|
||||
for node in root.Children:
|
||||
LayoutTree(node, x, y, level-1)
|
||||
y -= root.dy * level
|
||||
|
||||
|
||||
def TraverseTree(root, func):
|
||||
func(root)
|
||||
for child in (root.Children):
|
||||
@@ -259,25 +259,25 @@ class DrawFrame(wx.Frame):
|
||||
def __init__(self, *args, **kwargs):
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.CreateStatusBar()
|
||||
# Add the Canvas
|
||||
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
|
||||
ProjectionFun = None,
|
||||
Debug = 0,
|
||||
BackgroundColor = "White",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
|
||||
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )
|
||||
|
||||
self.elements = elements
|
||||
LayoutTree(self.elements, 0, 0, 3)
|
||||
self.AddTree(self.elements)
|
||||
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
@@ -310,7 +310,7 @@ class DrawFrame(wx.Frame):
|
||||
node.DrawObject = object
|
||||
Nodes.append(object)
|
||||
def AddConnectors(node):
|
||||
for child in node.Children:
|
||||
for child in node.Children:
|
||||
Connector = ConnectorLine(node.DrawObject, child.DrawObject, LineWidth=3, LineColor="Red")
|
||||
Connectors.append(Connector)
|
||||
## create the Objects
|
||||
@@ -318,14 +318,14 @@ class DrawFrame(wx.Frame):
|
||||
## create the Connectors
|
||||
TraverseTree(root, AddConnectors)
|
||||
## Add the conenctos to the Canvas first, so they are undernieth the nodes
|
||||
self.Canvas.AddObjects(Connectors)
|
||||
self.Canvas.AddObjects(Connectors)
|
||||
## now add the nodes
|
||||
self.Canvas.AddObjects(Nodes)
|
||||
self.Canvas.AddObjects(Nodes)
|
||||
# Now bind the Nodes -- DrawObjects must be Added to a Canvas before they can be bound.
|
||||
for node in Nodes:
|
||||
#pass
|
||||
node.Bind(FC.EVT_FC_LEFT_DOWN, self.ObjectHit)
|
||||
|
||||
|
||||
|
||||
|
||||
def ObjectHit(self, object):
|
||||
@@ -362,7 +362,7 @@ class DrawFrame(wx.Frame):
|
||||
if self.MoveObject is not None:
|
||||
dxy = event.GetPosition() - self.StartPoint
|
||||
dxy = self.Canvas.ScalePixelToWorld(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.MovingObject.Move(dxy)
|
||||
self.MoveTri = None
|
||||
self.Canvas.Draw(True)
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
||||
class DrawFrame(wx.Frame):
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wx.Frame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
|
||||
## Set up the MenuBar
|
||||
|
||||
|
||||
MenuBar = wx.MenuBar()
|
||||
|
||||
|
||||
file_menu = wx.Menu()
|
||||
item = file_menu.Append(wx.ID_ANY, "E&xit","Terminate the program")
|
||||
self.Bind(wx.EVT_MENU, self.OnQuit, item)
|
||||
@@ -35,22 +35,22 @@ class DrawFrame(wx.Frame):
|
||||
item = draw_menu.Append(wx.ID_ANY, "&Plot","Re-do Plot")
|
||||
self.Bind(wx.EVT_MENU, self.Plot, item)
|
||||
MenuBar.Append(draw_menu, "&Plot")
|
||||
|
||||
|
||||
|
||||
|
||||
help_menu = wx.Menu()
|
||||
item = help_menu.Append(wx.ID_ANY, "&About",
|
||||
"More information About this program")
|
||||
self.Bind(wx.EVT_MENU, self.OnAbout, item)
|
||||
MenuBar.Append(help_menu, "&Help")
|
||||
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
|
||||
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("")
|
||||
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||
|
||||
|
||||
# Add the Canvas
|
||||
self.Canvas = NavCanvas.NavCanvas(self ,wx.ID_ANY ,(500,300),
|
||||
ProjectionFun = None,
|
||||
@@ -60,13 +60,13 @@ class DrawFrame(wx.Frame):
|
||||
|
||||
self.Canvas.NumBetweenBlits = 1000
|
||||
|
||||
|
||||
|
||||
self.Show(True)
|
||||
|
||||
|
||||
self.Plot()
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
|
||||
"the use of the FloatCanvas\n"
|
||||
@@ -74,20 +74,20 @@ class DrawFrame(wx.Frame):
|
||||
"About Me", wx.OK | wx.ICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def ZoomToFit(self,event):
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
|
||||
def OnQuit(self,event):
|
||||
self.Close(True)
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
|
||||
def DrawAxis(self):
|
||||
Canvas = self.Canvas
|
||||
|
||||
|
||||
# Draw the Axis
|
||||
|
||||
# Note: the AddRectangle Parameters all have sensible
|
||||
@@ -145,59 +145,59 @@ class DrawFrame(wx.Frame):
|
||||
self.Canvas.Draw()
|
||||
self.Canvas.SaveAsImage("junk.png")
|
||||
|
||||
|
||||
|
||||
class DemoApp(wx.App):
|
||||
"""
|
||||
How the demo works:
|
||||
|
||||
|
||||
Either under the Draw menu, or on the toolbar, you can push Run and Stop
|
||||
|
||||
"Run" start an oscilloscope like display of a moving sine curve
|
||||
"Stop" stops it.
|
||||
|
||||
|
||||
While the plot os running (or not) you can zoom in and out and move
|
||||
about the picture. There is a tool bar with three tools that can be
|
||||
selected.
|
||||
|
||||
|
||||
The magnifying glass with the plus is the zoom in tool. Once selected,
|
||||
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
|
||||
box, and the image will zoom to fit that box when you release it.
|
||||
|
||||
|
||||
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
|
||||
clicked.
|
||||
|
||||
|
||||
The hand is the move tool. Once selected, if you click and drag on
|
||||
the image, it will move so that the part you clicked on ends up
|
||||
where you release the mouse. Nothing is changed while you are
|
||||
dragging, but you can see the outline of the former picture.
|
||||
|
||||
|
||||
I'd like the cursor to change as you change tools, but the stock
|
||||
wx.Cursors didn't include anything I liked, so I stuck with the
|
||||
pointer. Please let me know if you have any nice cursor images for me to
|
||||
use.
|
||||
|
||||
|
||||
|
||||
|
||||
Any bugs, comments, feedback, questions, and especially code are welcome:
|
||||
|
||||
|
||||
-Chris Barker
|
||||
|
||||
|
||||
Chris.Barker@noaa.gov
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def OnInit(self):
|
||||
frame = DrawFrame(None, wx.ID_ANY, "Plotting Test",wx.DefaultPosition,wx.Size(700,400))
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app = DemoApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ class DrawFrame(wx.Frame):
|
||||
Debug = 0,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
).Canvas
|
||||
|
||||
|
||||
self.Canvas = Canvas
|
||||
|
||||
|
||||
Point = (0,0)
|
||||
Box = Canvas.AddRectangle(Point,
|
||||
(80,100),
|
||||
@@ -59,14 +59,14 @@ class DrawFrame(wx.Frame):
|
||||
Canvas.AddText("%s"%(Point,), Point, Position="cr")
|
||||
Canvas.AddPoint(Point, Diameter=3, Color = "red")
|
||||
|
||||
|
||||
|
||||
Point = (0,100)
|
||||
Canvas.AddText("%s"%(Point,), Point, Position="cr")
|
||||
Canvas.AddPoint(Point, Diameter=3, Color = "red")
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
|
||||
self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
|
||||
|
||||
|
||||
self.Show()
|
||||
Canvas.ZoomToBB()
|
||||
|
||||
@@ -80,10 +80,10 @@ class DrawFrame(wx.Frame):
|
||||
app = wx.App(False)
|
||||
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user