Ensure that runTest is not modal, even when a required module is not

installed.

Create the code page small and hide it to reduce flicker, it will
later be shown and sized correctly when put into the notebook.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28918 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-08-25 23:56:43 +00:00
parent 3801d366cb
commit 2e839e966d
4 changed files with 339 additions and 331 deletions

View File

@@ -21,69 +21,65 @@ NOTE: The Numeric module is substantially faster than numarray for this
purpose, if you have lot's of objects purpose, if you have lot's of objects
""" """
import wx StartUpDemo = "all"
def runTest(frame, nb, log): if __name__ == "__main__": # parse options if run stand-alone
dlg = wx.MessageDialog(frame, errorText, 'Sorry', wx.OK | # check options:
wx.ICON_INFORMATION) import sys, getopt
dlg.ShowModal() optlist, args = getopt.getopt(sys.argv[1:],'l',["local","all","text","map","stext","hit","hitf","animate","speed","temp","props"])
dlg.Destroy()
overview = "" for opt in optlist:
if opt[0] == "--all":
else: StartUpDemo = "all"
StartUpDemo = "all" elif opt[0] == "--text":
if __name__ == "__main__": # parse options if run stand-alone StartUpDemo = "text"
# check options: elif opt[0] == "--map":
import sys, getopt StartUpDemo = "map"
optlist, args = getopt.getopt(sys.argv[1:],'l',["local","all","text","map","stext","hit","hitf","animate","speed","temp","props"]) elif opt[0] == "--stext":
StartUpDemo = "stext"
for opt in optlist: elif opt[0] == "--hit":
if opt[0] == "--all": StartUpDemo = "hit"
StartUpDemo = "all" elif opt[0] == "--hitf":
elif opt[0] == "--text": StartUpDemo = "hitf"
StartUpDemo = "text" elif opt[0] == "--animate":
elif opt[0] == "--map": StartUpDemo = "animate"
StartUpDemo = "map" elif opt[0] == "--speed":
elif opt[0] == "--stext": StartUpDemo = "speed"
StartUpDemo = "stext" elif opt[0] == "--temp":
elif opt[0] == "--hit": StartUpDemo = "temp"
StartUpDemo = "hit" elif opt[0] == "--props":
elif opt[0] == "--hitf": StartUpDemo = "props"
StartUpDemo = "hitf" import wx
elif opt[0] == "--animate": import time, random
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): class TestPanel(wx.Panel):
def __init__(self, parent, log): def __init__(self, parent, log):
self.log = log self.log = log
wx.Panel.__init__(self, parent, -1) wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Show the FloatBar sample", (50,50)) b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b) self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt): 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 = DrawFrame(None, -1, "FloatCanvas Drawing Window",wx.DefaultPosition,(500,500))
win.Show(True) win.Show(True)
win.DrawTest() win.DrawTest()
def runTest(frame, nb, log):
win = TestPanel(nb, log) #---------------------------------------------------------------------------
return win
if haveNumeric:
try: try:
from floatcanvas import NavCanvas, FloatCanvas from floatcanvas import NavCanvas, FloatCanvas
@@ -91,26 +87,26 @@ else:
from wx.lib.floatcanvas import NavCanvas, FloatCanvas from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb import wxPython.lib.colourdb
class DrawFrame(wx.Frame): class DrawFrame(wx.Frame):
""" """
A frame used for the FloatCanvas Demo A frame used for the FloatCanvas Demo
""" """
def __init__(self,parent, id,title,position,size): def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size) wx.Frame.__init__(self,parent, id,title,position, size)
## Set up the MenuBar ## Set up the MenuBar
MenuBar = wx.MenuBar() MenuBar = wx.MenuBar()
file_menu = wx.Menu() file_menu = wx.Menu()
item = file_menu.Append(-1, "&Close","Close this frame") item = file_menu.Append(-1, "&Close","Close this frame")
self.Bind(wx.EVT_MENU, self.OnQuit, item) self.Bind(wx.EVT_MENU, self.OnQuit, item)
MenuBar.Append(file_menu, "&File") MenuBar.Append(file_menu, "&File")
draw_menu = wx.Menu() draw_menu = wx.Menu()
item = draw_menu.Append(-1, "&Draw Test","Run a test of drawing random components") item = draw_menu.Append(-1, "&Draw Test","Run a test of drawing random components")
@@ -118,7 +114,7 @@ else:
item = draw_menu.Append(-1, "&Line Test","Run a test of drawing random lines") item = draw_menu.Append(-1, "&Line Test","Run a test of drawing random lines")
self.Bind(wx.EVT_MENU, self.LineTest, item) self.Bind(wx.EVT_MENU, self.LineTest, item)
item = draw_menu.Append(-1, "Draw &Map","Run a test of drawing a map") item = draw_menu.Append(-1, "Draw &Map","Run a test of drawing a map")
self.Bind(wx.EVT_MENU, self.DrawMap, item) self.Bind(wx.EVT_MENU, self.DrawMap, item)
item = draw_menu.Append(-1, "&Text Test","Run a test of text drawing") item = draw_menu.Append(-1, "&Text Test","Run a test of text drawing")
@@ -138,20 +134,20 @@ else:
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)
MenuBar.Append(draw_menu, "&Tests") MenuBar.Append(draw_menu, "&Tests")
view_menu = wx.Menu() view_menu = wx.Menu()
item = view_menu.Append(-1, "Zoom to &Fit","Zoom to fit the window") item = view_menu.Append(-1, "Zoom to &Fit","Zoom to fit the window")
self.Bind(wx.EVT_MENU, self.ZoomToFit, item) self.Bind(wx.EVT_MENU, self.ZoomToFit, item)
MenuBar.Append(view_menu, "&View") MenuBar.Append(view_menu, "&View")
help_menu = wx.Menu() help_menu = wx.Menu()
item = help_menu.Append(-1, "&About", item = help_menu.Append(-1, "&About",
"More information About this program") "More information About this program")
self.Bind(wx.EVT_MENU, self.OnAbout, item) self.Bind(wx.EVT_MENU, self.OnAbout, item)
MenuBar.Append(help_menu, "&Help") MenuBar.Append(help_menu, "&Help")
self.SetMenuBar(MenuBar) self.SetMenuBar(MenuBar)
self.CreateStatusBar() self.CreateStatusBar()
# Add the Canvas # Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self, self.Canvas = NavCanvas.NavCanvas(self,
@@ -263,28 +259,28 @@ else:
def OnAbout(self, event): def OnAbout(self, event):
print "OnAbout called" print "OnAbout called"
dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n" dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
"the use of the FloatCanvas\n", "the use of the FloatCanvas\n",
"About Me", wx.OK | wx.ICON_INFORMATION) "About Me", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal() dlg.ShowModal()
dlg.Destroy() dlg.Destroy()
def ZoomToFit(self,event): def ZoomToFit(self,event):
self.Canvas.ZoomToBB() self.Canvas.ZoomToBB()
def Clear(self,event = None): def Clear(self,event = None):
self.UnBindAllMouseEvents() self.UnBindAllMouseEvents()
self.Canvas.ClearAll() self.Canvas.ClearAll()
self.Canvas.SetProjectionFun(None) self.Canvas.SetProjectionFun(None)
self.Canvas.Draw() self.Canvas.Draw()
def OnQuit(self,event): def OnQuit(self,event):
self.Close(True) self.Close(True)
def OnCloseWindow(self, event): def OnCloseWindow(self, event):
self.Destroy() self.Destroy()
def DrawTest(self,event=None): def DrawTest(self,event=None):
wx.GetApp().Yield() wx.GetApp().Yield()
# import random # import random
@@ -299,7 +295,7 @@ else:
Canvas.SetProjectionFun(None) Canvas.SetProjectionFun(None)
## Random tests of everything: ## Random tests of everything:
# Rectangles # Rectangles
for i in range(3): for i in range(3):
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]))
@@ -308,7 +304,7 @@ else:
h = random.randint(1,5) h = random.randint(1,5)
w = random.randint(1,5) w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor = colors[cf]) Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor = colors[cf])
# Ellipses # Ellipses
for i in range(3): for i in range(3):
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]))
@@ -317,14 +313,14 @@ else:
h = random.randint(1,5) h = random.randint(1,5)
w = random.randint(1,5) w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf]) Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
# Points # Points
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]))
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]))
@@ -334,7 +330,7 @@ else:
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 = []
@@ -345,7 +341,7 @@ else:
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 = []
@@ -360,7 +356,7 @@ else:
LineColor = colors[cl], LineColor = colors[cl],
FillColor = colors[cf], FillColor = colors[cf],
FillStyle = 'Solid') FillStyle = 'Solid')
## Pointset ## Pointset
for i in range(4): for i in range(4):
points = [] points = []
@@ -368,7 +364,7 @@ else:
cf = random.randint(0,len(colors)-1) cf = random.randint(0,len(colors)-1)
D = random.randint(1,4) D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter = D) Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
# Text # Text
String = "Unscaled text" String = "Unscaled text"
for i in range(3): for i in range(3):
@@ -417,7 +413,7 @@ else:
h = random.randint(1,5) h = random.randint(1,5)
w = random.randint(1,5) w = random.randint(1,5)
Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf]) Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
# Ellipses # Ellipses
for i in range(3): for i in range(3):
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]))
@@ -426,7 +422,7 @@ else:
h = random.randint(1,5) h = random.randint(1,5)
w = random.randint(1,5) w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf]) Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
# 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]))
@@ -436,7 +432,7 @@ else:
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 = []
@@ -447,7 +443,7 @@ else:
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 = []
@@ -462,7 +458,7 @@ else:
LineColor = colors[cl], LineColor = colors[cl],
FillColor = colors[cf], FillColor = colors[cf],
FillStyle = 'Solid') FillStyle = 'Solid')
# Scaled Text # Scaled Text
String = "Scaled text" String = "Scaled text"
for i in range(3): for i in range(3):
@@ -480,7 +476,7 @@ else:
self.Timer = wx.PyTimer(self.ShowFrame) self.Timer = wx.PyTimer(self.ShowFrame)
self.FrameDelay = 50 # milliseconds self.FrameDelay = 50 # milliseconds
Canvas.ZoomToBB() Canvas.ZoomToBB()
def ShowFrame(self): def ShowFrame(self):
@@ -499,7 +495,7 @@ else:
wx.GetApp().Yield(True) wx.GetApp().Yield(True)
else: else:
self.Timer.Stop() self.Timer.Stop()
def MoveMe(self, Object): def MoveMe(self, Object):
self.MovingObject = Object self.MovingObject = Object
@@ -512,7 +508,7 @@ else:
self.TimeStep = 1 self.TimeStep = 1
self.Timer.Start(self.FrameDelay) self.Timer.Start(self.FrameDelay)
#print "Did %i frames in %f seconds"%(N, (time.time() - start) ) #print "Did %i frames in %f seconds"%(N, (time.time() - start) )
def TestHitTest(self,event=None): def TestHitTest(self,event=None):
wx.GetApp().Yield() wx.GetApp().Yield()
@@ -529,11 +525,11 @@ else:
dy = 40 dy = 40
x,y = 20, 20 x,y = 20, 20
FontSize = 8 FontSize = 8
#Add one that is not HitAble #Add one that is not HitAble
Canvas.AddRectangle(x, y, w, h, LineWidth = 2) Canvas.AddRectangle(x, y, w, h, LineWidth = 2)
Canvas.AddText("Not Hit-able", x, y, Size = FontSize, Position = "bl") Canvas.AddText("Not Hit-able", x, y, Size = FontSize, Position = "bl")
x += dx x += dx
R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2) R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2)
@@ -739,7 +735,7 @@ else:
dx = 80 dx = 80
dy = 40 dy = 40
x,y = 20, 20 x,y = 20, 20
color = "Red" color = "Red"
R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color, InForeground = False) R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color, InForeground = False)
R.Name = color + "Rectangle" R.Name = color + "Rectangle"
@@ -749,10 +745,10 @@ else:
Canvas.AddText(R.Name, x, y+h, Position = "tl") Canvas.AddText(R.Name, x, y+h, Position = "tl")
## A set of Rectangles that move together ## A set of Rectangles that move together
## NOTE: In a real app, it might be better to create a new ## NOTE: In a real app, it might be better to create a new
## custom FloatCanvas DrawObject ## custom FloatCanvas DrawObject
self.MovingRects = [] self.MovingRects = []
x += dx x += dx
color = "LightBlue" color = "LightBlue"
@@ -789,16 +785,16 @@ else:
def RectMoveLeft(self,Object): def RectMoveLeft(self,Object):
self.MoveRects("left") self.MoveRects("left")
def RectMoveRight(self,Object): def RectMoveRight(self,Object):
self.MoveRects("right") self.MoveRects("right")
def RectMoveUp(self,Object): def RectMoveUp(self,Object):
self.MoveRects("up") self.MoveRects("up")
def RectMoveDown(self,Object): def RectMoveDown(self,Object):
self.MoveRects("down") self.MoveRects("down")
def MoveRects(self, Dir): def MoveRects(self, Dir):
for Object in self.MovingRects: for Object in self.MovingRects:
X,Y = Object.XY X,Y = Object.XY
@@ -808,8 +804,8 @@ else:
elif Dir == "down": Y -= 10 elif Dir == "down": Y -= 10
Object.SetXY(X,Y) Object.SetXY(X,Y)
self.Canvas.Draw() self.Canvas.Draw()
def PointSetGotHit(self, Object): def PointSetGotHit(self, Object):
print Object.Name, "Got Hit\n" print Object.Name, "Got Hit\n"
@@ -852,19 +848,19 @@ else:
Canvas.AddPointSet((x,y), Color = "White", Diameter = 2) Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
x,y = (0, 2) x,y = (0, 2)
Canvas.AddPointSet((x,y), Color = "White", Diameter = 2) Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
self.Canvas.AddText("Top Center",x,y,Size = 14,Color = "Black",Position = "tc") self.Canvas.AddText("Top Center",x,y,Size = 14,Color = "Black",Position = "tc")
self.Canvas.AddText("Bottom Center",x,y,Size = 14,Color = "White",Position = "bc") self.Canvas.AddText("Bottom Center",x,y,Size = 14,Color = "White",Position = "bc")
x,y = (0, 4) x,y = (0, 4)
Canvas.AddPointSet((x,y), Color = "White", Diameter = 2) Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
self.Canvas.AddText("Center Right",x,y,Size = 14,Color = "Black",Position = "cr") self.Canvas.AddText("Center Right",x,y,Size = 14,Color = "Black",Position = "cr")
self.Canvas.AddText("Center Left",x,y,Size = 14,Color = "Black",Position = "cl") self.Canvas.AddText("Center Left",x,y,Size = 14,Color = "Black",Position = "cl")
x,y = (0, -2) x,y = (0, -2)
Canvas.AddPointSet((x,y), Color = "White", Diameter = 2) Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
self.Canvas.AddText("Center Center",x,y,Size = 14,Color = "Black",Position = "cc") self.Canvas.AddText("Center Center",x,y,Size = 14,Color = "Black",Position = "cc")
@@ -903,13 +899,13 @@ else:
x,y = (0, 20) x,y = (0, 20)
Canvas.AddScaledText("Top Center",x,y,Size = 7,Color = "Black",Position = "tc") Canvas.AddScaledText("Top Center",x,y,Size = 7,Color = "Black",Position = "tc")
Canvas.AddScaledText("Bottom Center",x,y,Size = 7,Color = "White",Position = "bc") Canvas.AddScaledText("Bottom Center",x,y,Size = 7,Color = "White",Position = "bc")
Canvas.AddPointSet((x,y), Color = "White", Diameter = 4) Canvas.AddPointSet((x,y), Color = "White", Diameter = 4)
x,y = (0, -20) x,y = (0, -20)
Canvas.AddScaledText("Center Right",x,y,Size = 9,Color = "Black",Position = "cr") Canvas.AddScaledText("Center Right",x,y,Size = 9,Color = "Black",Position = "cr")
Canvas.AddScaledText("Center Left",x,y,Size = 9,Color = "Black",Position = "cl") Canvas.AddScaledText("Center Left",x,y,Size = 9,Color = "Black",Position = "cl")
Canvas.AddPointSet((x,y), Color = "White", Diameter = 4) Canvas.AddPointSet((x,y), Color = "White", Diameter = 4)
@@ -935,12 +931,12 @@ else:
T = self.Canvas.AddScaledText("Bookman Font", x, y, Size = 8, Font = Font) T = self.Canvas.AddScaledText("Bookman Font", x, y, Size = 8, Font = Font)
self.Canvas.ZoomToBB() self.Canvas.ZoomToBB()
def DrawMap(self,event = None): def DrawMap(self,event = None):
wx.GetApp().Yield() wx.GetApp().Yield()
import os, time import os, time
self.BindAllMouseEvents() self.BindAllMouseEvents()
## Test of Actual Map Data ## Test of Actual Map Data
self.Canvas.ClearAll() self.Canvas.ClearAll()
self.Canvas.SetProjectionFun("FlatEarth") self.Canvas.SetProjectionFun("FlatEarth")
@@ -954,8 +950,8 @@ else:
#start = time.clock() #start = time.clock()
self.Canvas.ZoomToBB() self.Canvas.ZoomToBB()
#print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) ) #print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
def LineTest(self,event = None): def LineTest(self,event = None):
wx.GetApp().Yield() wx.GetApp().Yield()
import os, time import os, time
@@ -1033,7 +1029,7 @@ else:
w = random.randint(1,5) w = random.randint(1,5)
self.Rectangle = Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor = colors[cf]) self.Rectangle = Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor = colors[cf])
self.ColorObjectsAll.append(self.Rectangle) self.ColorObjectsAll.append(self.Rectangle)
# Ellipse # Ellipse
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]))
lw = random.randint(1,5) lw = random.randint(1,5)
@@ -1042,7 +1038,7 @@ else:
w = random.randint(1,5) w = random.randint(1,5)
self.Ellipse = Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf]) self.Ellipse = Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
self.ColorObjectsAll.append(self.Ellipse) self.ColorObjectsAll.append(self.Ellipse)
# Point # Point
xy = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) xy = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50) D = random.randint(1,50)
@@ -1050,7 +1046,7 @@ else:
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)
self.ColorObjectsColor.append(Canvas.AddPoint(xy, colors[cf], D)) self.ColorObjectsColor.append(Canvas.AddPoint(xy, colors[cf], D))
# Circle # Circle
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]))
D = random.randint(1,5) D = random.randint(1,5)
@@ -1069,7 +1065,7 @@ else:
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)
self.ColorObjectsLine.append(Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl])) self.ColorObjectsLine.append(Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl]))
# Polygon # Polygon
## points = [] ## points = []
## for j in range(random.randint(2,6)): ## for j in range(random.randint(2,6)):
@@ -1084,21 +1080,21 @@ else:
LineColor = colors[cl], LineColor = colors[cl],
FillColor = colors[cf], FillColor = colors[cf],
FillStyle = 'Solid')) FillStyle = 'Solid'))
## Pointset ## Pointset
points = RandomArray.uniform(Range[0],Range[1],(100,2)) points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1) cf = random.randint(0,len(colors)-1)
D = random.randint(1,4) D = random.randint(1,4)
self.PointSet = Canvas.AddPointSet(points, Color = colors[cf], Diameter = D) self.PointSet = Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
self.ColorObjectsColor.append(self.PointSet) self.ColorObjectsColor.append(self.PointSet)
## Point ## Point
point = RandomArray.uniform(Range[0],Range[1],(2,)) point = RandomArray.uniform(Range[0],Range[1],(2,))
cf = random.randint(0,len(colors)-1) cf = random.randint(0,len(colors)-1)
D = random.randint(1,4) D = random.randint(1,4)
self.Point = Canvas.AddPoint(point, Color = colors[cf], Diameter = D) self.Point = Canvas.AddPoint(point, Color = colors[cf], Diameter = D)
self.ColorObjectsColor.append(self.Point) self.ColorObjectsColor.append(self.Point)
# Text # Text
String = "Unscaled text" String = "Unscaled text"
ts = random.randint(10,40) ts = random.randint(10,40)
@@ -1151,7 +1147,7 @@ else:
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) self.Canvas.Draw(Force = True)
def TempTest(self, event= None): def TempTest(self, event= None):
@@ -1180,7 +1176,7 @@ else:
self.SelectedPoly = None self.SelectedPoly = None
self.SelectPoints = [] self.SelectPoints = []
self.SelectedPoint = None self.SelectedPoint = None
Canvas.ZoomToBB() Canvas.ZoomToBB()
def SelectPoly(self, Object): def SelectPoly(self, Object):
@@ -1206,65 +1202,65 @@ else:
print "Point Num: %i Hit"%Point.VerticeNum print "Point Num: %i Hit"%Point.VerticeNum
self.SelectedPoint = Point self.SelectedPoint = Point
class DemoApp(wx.App): class DemoApp(wx.App):
""" """
How the demo works: How the demo works:
Under the Draw menu, there are three options: Under the Draw menu, there are three options:
*Draw Test: will put up a picture of a bunch of randomly generated *Draw Test: will put up a picture of a bunch of randomly generated
objects, of each kind supported. objects, of each kind supported.
*Draw Map: will draw a map of the world. Be patient, it is a big map, *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 on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
performance is not very good for large drawings. performance is not very good for large drawings.
*Clear: Clears the Canvas. *Clear: Clears the Canvas.
Once you have a picture drawn, you can zoom in and out and move about 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 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, 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 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 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. 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, 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 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, 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 as it has a LOT of lines to be drawn. The image is double buffered, so
you don't see the drawing in progress) you don't see the drawing in progress)
The hand is the move tool. Once selected, if you click and drag on the 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 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 release the mouse. Nothing is changed while you are dragging. The
drawing is too slow for that. drawing is too slow for that.
I'd like the cursor to change as you change tools, but the stock I'd like the cursor to change as you change tools, but the stock
wxCursors didn't include anything I liked, so I stuck with the wxCursors 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 pointer. Please let me know if you have any nice cursor images for me to
use. use.
Any bugs, comments, feedback, questions, and especially code are welcome: Any bugs, comments, feedback, questions, and especially code are welcome:
-Chris Barker -Chris Barker
Chris.Barker@noaa.gov Chris.Barker@noaa.gov
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
wx.App.__init__(self, *args, **kwargs) wx.App.__init__(self, *args, **kwargs)
def OnInit(self): def OnInit(self):
wx.InitAllImageHandlers() wx.InitAllImageHandlers()
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)
frame.Show() frame.Show()
@@ -1294,25 +1290,25 @@ else:
elif StartUpDemo == "props": elif StartUpDemo == "props":
"starting PropertiesChange Test" "starting PropertiesChange Test"
frame.PropertiesChangeTest() frame.PropertiesChangeTest()
return True return True
def Read_MapGen(filename,stats = 0,AllLines=0): def Read_MapGen(filename,stats = 0,AllLines=0):
""" """
This function reads a MapGen Format file, and This function reads a MapGen Format file, and
returns a list of NumPy arrays with the line segments in them. returns a list of NumPy arrays with the line segments in them.
Each NumPy array in the list is an NX2 array of Python Floats. 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 The demo should have come with a file, "world.dat" that is the
shorelines of the whole world, in MapGen format. shorelines of the whole world, in MapGen format.
""" """
import string import string
file = open(filename,'rt') file = open(filename,'rt')
data = file.readlines() data = file.readlines()
data = map(string.strip,data) data = map(string.strip,data)
Shorelines = [] Shorelines = []
segment = [] segment = []
for line in data: for line in data:
@@ -1323,7 +1319,7 @@ else:
else: else:
segment.append(map(float,string.split(line))) segment.append(map(float,string.split(line)))
if segment: Shorelines.append(Numeric.array(segment)) if segment: Shorelines.append(Numeric.array(segment))
if stats: if stats:
NumSegments = len(Shorelines) NumSegments = len(Shorelines)
NumPoints = 0 NumPoints = 0
@@ -1343,14 +1339,28 @@ else:
return Lines return Lines
else: else:
return Shorelines return Shorelines
## for the wxPython demo: #---------------------------------------------------------------------------
## for the wxPython demo:
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
if haveNumeric:
try: try:
import floatcanvas import 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 import floatcanvas from wx.lib import floatcanvas
overview = floatcanvas.__doc__ overview = floatcanvas.__doc__
else:
overview = ""
if __name__ == "__main__": if __name__ == "__main__":
if not haveNumeric: if not haveNumeric:

View File

@@ -18,57 +18,54 @@ except ImportError:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
if not haveGLCanvas:
def runTest(frame, nb, log):
dlg = wx.MessageDialog(frame, 'The GLCanvas class has not been included with this build of wxPython!',
'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
elif not haveOpenGL: buttonDefs = {
def runTest(frame, nb, log): wx.NewId() : ('CubeCanvas', 'Cube'),
dlg = wx.MessageDialog(frame, wx.NewId() : ('ConeCanvas', 'Cone'),
'The OpenGL package was not found. You can get it at\n' }
'http://PyOpenGL.sourceforge.net/',
'Sorry', wx.OK | wx.ICON_INFORMATION) class ButtonPanel(wx.Panel):
dlg.ShowModal() def __init__(self, parent, log):
dlg.Destroy() wx.Panel.__init__(self, parent, -1)
self.log = log
box = wx.BoxSizer(wx.VERTICAL)
box.Add((20, 30))
keys = buttonDefs.keys()
keys.sort()
for k in keys:
text = buttonDefs[k][1]
btn = wx.Button(self, k, text)
box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.Bind(wx.EVT_BUTTON, self.OnButton, btn)
#** Enable this to show putting a GLCanvas on the wx.Panel
if 0:
c = CubeCanvas(self)
c.SetSize((200, 200))
box.Add(c, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.SetAutoLayout(True)
self.SetSizer(box)
def OnButton(self, evt):
if not haveGLCanvas:
dlg = wx.MessageDialog(self,
'The GLCanvas class has not been included with this build of wxPython!',
'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
elif not haveOpenGL:
dlg = wx.MessageDialog(self,
'The OpenGL package was not found. You can get it at\n'
'http://PyOpenGL.sourceforge.net/',
'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
else: else:
buttonDefs = {
wx.NewId() : ('CubeCanvas', 'Cube'),
wx.NewId() : ('ConeCanvas', 'Cone'),
}
class ButtonPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
self.log = log
box = wx.BoxSizer(wx.VERTICAL)
box.Add((20, 30))
keys = buttonDefs.keys()
keys.sort()
for k in keys:
text = buttonDefs[k][1]
btn = wx.Button(self, k, text)
box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.Bind(wx.EVT_BUTTON, self.OnButton, btn)
#** Enable this to show putting a GLCanvas on the wx.Panel
if 0:
c = CubeCanvas(self)
c.SetSize((200, 200))
box.Add(c, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.SetAutoLayout(True)
self.SetSizer(box)
def OnButton(self, evt):
canvasClassName = buttonDefs[evt.GetId()][0] canvasClassName = buttonDefs[evt.GetId()][0]
canvasClass = eval(canvasClassName) canvasClass = eval(canvasClassName)
frame = wx.Frame(None, -1, canvasClassName, size=(400,400)) frame = wx.Frame(None, -1, canvasClassName, size=(400,400))
@@ -76,179 +73,171 @@ else:
frame.Show(True) frame.Show(True)
class MyCanvasBase(glcanvas.GLCanvas):
def runTest(frame, nb, log): def __init__(self, parent):
win = ButtonPanel(nb, log) glcanvas.GLCanvas.__init__(self, parent, -1)
return win self.init = False
# initial mouse position
self.lastx = self.x = 30
self.lasty = self.y = 30
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
def OnEraseBackground(self, event):
pass # Do nothing, to avoid flashing on MSW.
class MyCanvasBase(glcanvas.GLCanvas): def OnSize(self, event):
def __init__(self, parent): size = self.GetClientSize()
glcanvas.GLCanvas.__init__(self, parent, -1) if self.GetContext():
self.init = False
# initial mouse position
self.lastx = self.x = 30
self.lasty = self.y = 30
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
def OnEraseBackground(self, event):
pass # Do nothing, to avoid flashing on MSW.
def OnSize(self, event):
size = self.GetClientSize()
if self.GetContext():
self.SetCurrent()
glViewport(0, 0, size.width, size.height)
event.Skip()
def OnPaint(self, event):
dc = wx.PaintDC(self)
self.SetCurrent() self.SetCurrent()
if not self.init: glViewport(0, 0, size.width, size.height)
self.InitGL() event.Skip()
self.init = True
self.OnDraw()
def OnMouseDown(self, evt): def OnPaint(self, event):
self.CaptureMouse() dc = wx.PaintDC(self)
self.SetCurrent()
if not self.init:
self.InitGL()
self.init = True
self.OnDraw()
def OnMouseUp(self, evt): def OnMouseDown(self, evt):
self.ReleaseMouse() self.CaptureMouse()
def OnMouseMotion(self, evt): def OnMouseUp(self, evt):
if evt.Dragging() and evt.LeftIsDown(): self.ReleaseMouse()
self.x, self.y = self.lastx, self.lasty
self.x, self.y = evt.GetPosition()
self.Refresh(False) def OnMouseMotion(self, evt):
if evt.Dragging() and evt.LeftIsDown():
self.x, self.y = self.lastx, self.lasty
self.x, self.y = evt.GetPosition()
self.Refresh(False)
class CubeCanvas(MyCanvasBase): class CubeCanvas(MyCanvasBase):
def InitGL(self): def InitGL(self):
# set viewing projection # set viewing projection
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0); glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
# position viewer # position viewer
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0, 0.0, -2.0); glTranslatef(0.0, 0.0, -2.0);
# position object # position object
glRotatef(self.y, 1.0, 0.0, 0.0); glRotatef(self.y, 1.0, 0.0, 0.0);
glRotatef(self.x, 0.0, 1.0, 0.0); glRotatef(self.x, 0.0, 1.0, 0.0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT0);
def OnDraw(self): def OnDraw(self):
# clear color and depth buffers # clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
# draw six faces of a cube # draw six faces of a cube
glBegin(GL_QUADS) glBegin(GL_QUADS)
glNormal3f( 0.0, 0.0, 1.0) glNormal3f( 0.0, 0.0, 1.0)
glVertex3f( 0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5) glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5,-0.5, 0.5) glVertex3f(-0.5,-0.5, 0.5)
glVertex3f( 0.5,-0.5, 0.5) glVertex3f( 0.5,-0.5, 0.5)
glNormal3f( 0.0, 0.0,-1.0) glNormal3f( 0.0, 0.0,-1.0)
glVertex3f(-0.5,-0.5,-0.5) glVertex3f(-0.5,-0.5,-0.5)
glVertex3f(-0.5, 0.5,-0.5) glVertex3f(-0.5, 0.5,-0.5)
glVertex3f( 0.5, 0.5,-0.5) glVertex3f( 0.5, 0.5,-0.5)
glVertex3f( 0.5,-0.5,-0.5) glVertex3f( 0.5,-0.5,-0.5)
glNormal3f( 0.0, 1.0, 0.0) glNormal3f( 0.0, 1.0, 0.0)
glVertex3f( 0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5)
glVertex3f( 0.5, 0.5,-0.5) glVertex3f( 0.5, 0.5,-0.5)
glVertex3f(-0.5, 0.5,-0.5) glVertex3f(-0.5, 0.5,-0.5)
glVertex3f(-0.5, 0.5, 0.5) glVertex3f(-0.5, 0.5, 0.5)
glNormal3f( 0.0,-1.0, 0.0) glNormal3f( 0.0,-1.0, 0.0)
glVertex3f(-0.5,-0.5,-0.5) glVertex3f(-0.5,-0.5,-0.5)
glVertex3f( 0.5,-0.5,-0.5) glVertex3f( 0.5,-0.5,-0.5)
glVertex3f( 0.5,-0.5, 0.5) glVertex3f( 0.5,-0.5, 0.5)
glVertex3f(-0.5,-0.5, 0.5) glVertex3f(-0.5,-0.5, 0.5)
glNormal3f( 1.0, 0.0, 0.0) glNormal3f( 1.0, 0.0, 0.0)
glVertex3f( 0.5, 0.5, 0.5) glVertex3f( 0.5, 0.5, 0.5)
glVertex3f( 0.5,-0.5, 0.5) glVertex3f( 0.5,-0.5, 0.5)
glVertex3f( 0.5,-0.5,-0.5) glVertex3f( 0.5,-0.5,-0.5)
glVertex3f( 0.5, 0.5,-0.5) glVertex3f( 0.5, 0.5,-0.5)
glNormal3f(-1.0, 0.0, 0.0) glNormal3f(-1.0, 0.0, 0.0)
glVertex3f(-0.5,-0.5,-0.5) glVertex3f(-0.5,-0.5,-0.5)
glVertex3f(-0.5,-0.5, 0.5) glVertex3f(-0.5,-0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5) glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5,-0.5) glVertex3f(-0.5, 0.5,-0.5)
glEnd() glEnd()
glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0); glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0);
glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0); glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0);
self.SwapBuffers() self.SwapBuffers()
class ConeCanvas(MyCanvasBase): class ConeCanvas(MyCanvasBase):
def InitGL( self ): def InitGL( self ):
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
# camera frustrum setup # camera frustrum setup
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0); glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0]) glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0]) glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
glMaterial(GL_FRONT, GL_SHININESS, 50.0) glMaterial(GL_FRONT, GL_SHININESS, 50.0)
glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0]) glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]); glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
glEnable(GL_LIGHTING) glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0) glEnable(GL_LIGHT0)
glDepthFunc(GL_LESS) glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST) glEnable(GL_DEPTH_TEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
# position viewer # position viewer
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
def OnDraw(self): def OnDraw(self):
# clear color and depth buffers # clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
# use a fresh transformation matrix # use a fresh transformation matrix
glPushMatrix() glPushMatrix()
# position object # position object
glTranslate(0.0, 0.0, -2.0); glTranslate(0.0, 0.0, -2.0);
glRotate(30.0, 1.0, 0.0, 0.0); glRotate(30.0, 1.0, 0.0, 0.0);
glRotate(30.0, 0.0, 1.0, 0.0); glRotate(30.0, 0.0, 1.0, 0.0);
glTranslate(0, -1, 0) glTranslate(0, -1, 0)
glRotate(250, 1, 0, 0) glRotate(250, 1, 0, 0)
glutSolidCone(0.5, 1, 30, 5) glutSolidCone(0.5, 1, 30, 5)
glPopMatrix() glPopMatrix()
glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0); glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0);
glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0); glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0);
# push into visible buffer # push into visible buffer
self.SwapBuffers() self.SwapBuffers()
@@ -256,6 +245,13 @@ else:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def runTest(frame, nb, log):
win = ButtonPanel(nb, log)
return win
overview = """\ overview = """\

View File

@@ -273,7 +273,7 @@ try:
class DemoCodeEditor(PythonSTC): class DemoCodeEditor(PythonSTC):
def __init__(self, parent): def __init__(self, parent):
PythonSTC.__init__(self, parent, -1, wx.BORDER_NONE) PythonSTC.__init__(self, parent, -1, style=wx.BORDER_NONE)
self.SetUpEditor() self.SetUpEditor()
# Some methods to make it compatible with how the wxTextCtrl is used # Some methods to make it compatible with how the wxTextCtrl is used
@@ -443,8 +443,8 @@ try:
except ImportError: except ImportError:
class DemoCodeEditor(wx.TextCtrl): class DemoCodeEditor(wx.TextCtrl):
def __init__(self, parent): def __init__(self, parent):
wx.TextCtrl.__init__(self, parent, -1, style = wx.TE_MULTILINE | wx.TextCtrl.__init__(self, parent, -1, style =
wx.HSCROLL | wx.TE_RICH2 | wx.TE_NOHIDESEL) wx.TE_MULTILINE | wx.HSCROLL | wx.TE_RICH2 | wx.TE_NOHIDESEL)
def RegisterModifiedEvent(self, eventHandler): def RegisterModifiedEvent(self, eventHandler):
self.Bind(wx.EVT_TEXT, eventHandler) self.Bind(wx.EVT_TEXT, eventHandler)
@@ -482,7 +482,8 @@ modDefault = modOriginal
class DemoCodePanel(wx.Panel): class DemoCodePanel(wx.Panel):
"""Panel for the 'Demo Code' tab""" """Panel for the 'Demo Code' tab"""
def __init__(self, parent, mainFrame): def __init__(self, parent, mainFrame):
wx.Panel.__init__(self, parent) wx.Panel.__init__(self, parent, size=(1,1))
self.Hide()
self.mainFrame = mainFrame self.mainFrame = mainFrame
self.editor = DemoCodeEditor(self) self.editor = DemoCodeEditor(self)
self.editor.RegisterModifiedEvent(self.OnCodeModified) self.editor.RegisterModifiedEvent(self.OnCodeModified)

View File

@@ -42,9 +42,10 @@ class PythonSTC(stc.StyledTextCtrl):
fold_symbols = 2 fold_symbols = 2
def __init__(self, parent, ID, style=0): def __init__(self, parent, ID,
stc.StyledTextCtrl.__init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize,
style = style|wx.NO_FULL_REPAINT_ON_RESIZE) style=0):
stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)