2004-05-25 22:13:04 -04:00
|
|
|
|
# -*- coding: iso-8859-1 -*-
|
2003-12-08 20:23:28 -05:00
|
|
|
|
# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
|
#
|
|
|
|
|
# o Updated for wx namespace
|
|
|
|
|
#
|
2004-05-25 22:13:04 -04:00
|
|
|
|
# 20040508 - Pierre Hj<48>lm
|
|
|
|
|
#
|
|
|
|
|
# o Changed to use the python version of OGL
|
|
|
|
|
# o Added TextShape, CompositeShape and CompositeShape with divisions
|
|
|
|
|
#
|
2004-08-31 10:54:13 -04:00
|
|
|
|
# 20040830 - Pierre Hj<48>lm
|
|
|
|
|
#
|
|
|
|
|
# o Added DrawnShape
|
|
|
|
|
#
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
import wx
|
|
|
|
|
import wx.lib.ogl as ogl
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
import images
|
2001-04-09 15:36:36 -04:00
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2004-08-31 10:54:13 -04:00
|
|
|
|
class DrawnShape(ogl.DrawnShape):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
ogl.DrawnShape.__init__(self)
|
|
|
|
|
|
|
|
|
|
self.SetDrawnBrush(wx.WHITE_BRUSH)
|
|
|
|
|
self.SetDrawnPen(wx.BLACK_PEN)
|
|
|
|
|
self.DrawArc((0, -10), (30, 0), (-30, 0))
|
|
|
|
|
|
|
|
|
|
self.SetDrawnPen(wx.Pen("#ff8030"))
|
|
|
|
|
self.DrawLine((-30, 5), (30, 5))
|
|
|
|
|
|
|
|
|
|
self.SetDrawnPen(wx.Pen("#00ee10"))
|
|
|
|
|
self.DrawRoundedRectangle((-20, 10, 40, 10), 5)
|
|
|
|
|
|
|
|
|
|
self.SetDrawnPen(wx.Pen("#9090f0"))
|
|
|
|
|
self.DrawEllipse((-30, 25, 60, 20))
|
|
|
|
|
|
|
|
|
|
self.SetDrawnTextColour(wx.BLACK)
|
|
|
|
|
self.SetDrawnFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL))
|
|
|
|
|
self.DrawText("DrawText", (-26, 28))
|
|
|
|
|
|
|
|
|
|
self.SetDrawnBrush(wx.GREEN_BRUSH)
|
|
|
|
|
self.DrawPolygon([(-100, 5), (-45, 30), (-35, 20), (-30, 5)])
|
|
|
|
|
|
|
|
|
|
self.SetDrawnPen(wx.BLACK_PEN)
|
|
|
|
|
self.DrawLines([(30, -45), (40, -45), (40 ,45), (30, 45)])
|
|
|
|
|
|
|
|
|
|
# Make sure to call CalculateSize when all drawing is done
|
|
|
|
|
self.CalculateSize()
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
class DiamondShape(ogl.PolygonShape):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
def __init__(self, w=0.0, h=0.0):
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ogl.PolygonShape.__init__(self)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
if w == 0.0:
|
|
|
|
|
w = 60.0
|
|
|
|
|
if h == 0.0:
|
|
|
|
|
h = 60.0
|
|
|
|
|
|
|
|
|
|
points = [ (0.0, -h/2.0),
|
|
|
|
|
(w/2.0, 0.0),
|
|
|
|
|
(0.0, h/2.0),
|
|
|
|
|
(-w/2.0, 0.0),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.Create(points)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
class RoundedRectangleShape(ogl.RectangleShape):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
def __init__(self, w=0.0, h=0.0):
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ogl.RectangleShape.__init__(self, w, h)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.SetCornerRadius(-0.3)
|
|
|
|
|
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class CompositeDivisionShape(ogl.CompositeShape):
|
|
|
|
|
def __init__(self, canvas):
|
|
|
|
|
ogl.CompositeShape.__init__(self)
|
|
|
|
|
|
|
|
|
|
self.SetCanvas(canvas)
|
|
|
|
|
|
|
|
|
|
# create a division in the composite
|
|
|
|
|
self.MakeContainer()
|
|
|
|
|
|
|
|
|
|
# add a shape to the original division
|
|
|
|
|
shape2 = ogl.RectangleShape(40, 60)
|
|
|
|
|
self.GetDivisions()[0].AddChild(shape2)
|
|
|
|
|
|
|
|
|
|
# now divide the division so we get 2
|
|
|
|
|
self.GetDivisions()[0].Divide(wx.HORIZONTAL)
|
|
|
|
|
|
|
|
|
|
# and add a shape to the second division (and move it to the
|
|
|
|
|
# centre of the division)
|
|
|
|
|
shape3 = ogl.CircleShape(40)
|
|
|
|
|
shape3.SetBrush(wx.CYAN_BRUSH)
|
|
|
|
|
self.GetDivisions()[1].AddChild(shape3)
|
|
|
|
|
shape3.SetX(self.GetDivisions()[1].GetX())
|
|
|
|
|
|
|
|
|
|
for division in self.GetDivisions():
|
|
|
|
|
division.SetSensitivityFilter(0)
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class CompositeShape(ogl.CompositeShape):
|
|
|
|
|
def __init__(self, canvas):
|
|
|
|
|
ogl.CompositeShape.__init__(self)
|
|
|
|
|
|
|
|
|
|
self.SetCanvas(canvas)
|
|
|
|
|
|
|
|
|
|
constraining_shape = ogl.RectangleShape(120, 100)
|
|
|
|
|
constrained_shape1 = ogl.CircleShape(50)
|
|
|
|
|
constrained_shape2 = ogl.RectangleShape(80, 20)
|
|
|
|
|
|
|
|
|
|
constraining_shape.SetBrush(wx.BLUE_BRUSH)
|
|
|
|
|
constrained_shape2.SetBrush(wx.RED_BRUSH)
|
|
|
|
|
|
|
|
|
|
self.AddChild(constraining_shape)
|
|
|
|
|
self.AddChild(constrained_shape1)
|
|
|
|
|
self.AddChild(constrained_shape2)
|
|
|
|
|
|
|
|
|
|
constraint = ogl.Constraint(ogl.CONSTRAINT_MIDALIGNED_BOTTOM, constraining_shape, [constrained_shape1, constrained_shape2])
|
|
|
|
|
self.AddConstraint(constraint)
|
|
|
|
|
self.Recompute()
|
|
|
|
|
|
|
|
|
|
# If we don't do this, the shapes will be able to move on their
|
|
|
|
|
# own, instead of moving the composite
|
|
|
|
|
constraining_shape.SetDraggable(False)
|
|
|
|
|
constrained_shape1.SetDraggable(False)
|
|
|
|
|
constrained_shape2.SetDraggable(False)
|
|
|
|
|
|
|
|
|
|
# If we don't do this the shape will take all left-clicks for itself
|
|
|
|
|
constraining_shape.SetSensitivityFilter(0)
|
|
|
|
|
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
class DividedShape(ogl.DividedShape):
|
2003-03-25 01:35:27 -05:00
|
|
|
|
def __init__(self, width, height, canvas):
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ogl.DividedShape.__init__(self, width, height)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region1 = ogl.ShapeRegion()
|
|
|
|
|
region1.SetText('DividedShape')
|
2003-03-25 01:35:27 -05:00
|
|
|
|
region1.SetProportions(0.0, 0.2)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
self.AddRegion(region1)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region2 = ogl.ShapeRegion()
|
2003-03-25 01:35:27 -05:00
|
|
|
|
region2.SetText('This is Region number two.')
|
|
|
|
|
region2.SetProportions(0.0, 0.3)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region2.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ|ogl.FORMAT_CENTRE_VERT)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
self.AddRegion(region2)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region3 = ogl.ShapeRegion()
|
2003-03-25 01:35:27 -05:00
|
|
|
|
region3.SetText('Region 3\nwith embedded\nline breaks')
|
|
|
|
|
region3.SetProportions(0.0, 0.5)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
region3.SetFormatMode(ogl.FORMAT_NONE)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
self.AddRegion(region3)
|
|
|
|
|
|
|
|
|
|
self.SetRegionSizes()
|
|
|
|
|
self.ReformatRegions(canvas)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ReformatRegions(self, canvas=None):
|
|
|
|
|
rnum = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
if canvas is None:
|
|
|
|
|
canvas = self.GetCanvas()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
|
|
dc = wx.ClientDC(canvas) # used for measuring
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
for region in self.GetRegions():
|
|
|
|
|
text = region.GetText()
|
|
|
|
|
self.FormatText(dc, text, rnum)
|
|
|
|
|
rnum += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
|
2003-11-12 16:34:20 -05:00
|
|
|
|
print "***", self
|
2004-05-25 22:13:04 -04:00
|
|
|
|
ogl.DividedShape.OnSizingEndDragLeft(self, pt, x, y, keys, attch)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
self.SetRegionSizes()
|
|
|
|
|
self.ReformatRegions()
|
|
|
|
|
self.GetCanvas().Refresh()
|
|
|
|
|
|
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
class MyEvtHandler(ogl.ShapeEvtHandler):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
def __init__(self, log, frame):
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ogl.ShapeEvtHandler.__init__(self)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.log = log
|
|
|
|
|
self.statbarFrame = frame
|
|
|
|
|
|
|
|
|
|
def UpdateStatusBar(self, shape):
|
2004-05-25 22:13:04 -04:00
|
|
|
|
x, y = shape.GetX(), shape.GetY()
|
1999-09-10 02:25:47 -04:00
|
|
|
|
width, height = shape.GetBoundingBoxMax()
|
2004-05-25 22:13:04 -04:00
|
|
|
|
self.statbarFrame.SetStatusText("Pos: (%d, %d) Size: (%d, %d)" %
|
1999-09-10 02:25:47 -04:00
|
|
|
|
(x, y, width, height))
|
|
|
|
|
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
def OnLeftClick(self, x, y, keys=0, attachment=0):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
shape = self.GetShape()
|
|
|
|
|
canvas = shape.GetCanvas()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
dc = wx.ClientDC(canvas)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
canvas.PrepareDC(dc)
|
|
|
|
|
|
|
|
|
|
if shape.Selected():
|
2003-03-25 01:35:27 -05:00
|
|
|
|
shape.Select(False, dc)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
canvas.Redraw(dc)
|
|
|
|
|
else:
|
2003-03-25 01:35:27 -05:00
|
|
|
|
redraw = False
|
1999-09-10 02:25:47 -04:00
|
|
|
|
shapeList = canvas.GetDiagram().GetShapeList()
|
|
|
|
|
toUnselect = []
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
for s in shapeList:
|
|
|
|
|
if s.Selected():
|
|
|
|
|
# If we unselect it now then some of the objects in
|
|
|
|
|
# shapeList will become invalid (the control points are
|
|
|
|
|
# shapes too!) and bad things will happen...
|
|
|
|
|
toUnselect.append(s)
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
shape.Select(True, dc)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
|
|
|
|
if toUnselect:
|
|
|
|
|
for s in toUnselect:
|
2003-03-25 01:35:27 -05:00
|
|
|
|
s.Select(False, dc)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
canvas.Redraw(dc)
|
|
|
|
|
|
|
|
|
|
self.UpdateStatusBar(shape)
|
|
|
|
|
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
def OnEndDragLeft(self, x, y, keys=0, attachment=0):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
shape = self.GetShape()
|
2004-05-25 22:13:04 -04:00
|
|
|
|
ogl.ShapeEvtHandler.OnEndDragLeft(self, x, y, keys, attachment)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
if not shape.Selected():
|
|
|
|
|
self.OnLeftClick(x, y, keys, attachment)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.UpdateStatusBar(shape)
|
|
|
|
|
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
|
2004-05-25 22:13:04 -04:00
|
|
|
|
ogl.ShapeEvtHandler.OnSizingEndDragLeft(self, pt, x, y, keys, attch)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.UpdateStatusBar(self.GetShape())
|
|
|
|
|
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
def OnMovePost(self, dc, x, y, oldX, oldY, display):
|
2004-05-25 22:13:04 -04:00
|
|
|
|
ogl.ShapeEvtHandler.OnMovePost(self, dc, x, y, oldX, oldY, display)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
self.UpdateStatusBar(self.GetShape())
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def OnRightClick(self, *dontcare):
|
|
|
|
|
self.log.WriteText("%s\n" % self.GetShape())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
class TestWindow(ogl.ShapeCanvas):
|
1999-09-10 02:25:47 -04:00
|
|
|
|
def __init__(self, parent, log, frame):
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ogl.ShapeCanvas.__init__(self, parent)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
|
maxWidth = 1000
|
|
|
|
|
maxHeight = 1000
|
|
|
|
|
self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20)
|
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.log = log
|
|
|
|
|
self.frame = frame
|
2003-12-08 20:23:28 -05:00
|
|
|
|
self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
|
|
|
|
|
self.diagram = ogl.Diagram()
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.SetDiagram(self.diagram)
|
|
|
|
|
self.diagram.SetCanvas(self)
|
|
|
|
|
self.shapes = []
|
2001-04-01 23:49:52 -04:00
|
|
|
|
self.save_gdi = []
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
rRectBrush = wx.Brush("MEDIUM TURQUOISE", wx.SOLID)
|
|
|
|
|
dsBrush = wx.Brush("WHEAT", wx.SOLID)
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
self.MyAddShape(
|
|
|
|
|
CompositeDivisionShape(self),
|
2004-08-31 10:54:13 -04:00
|
|
|
|
270, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division"
|
2004-05-25 22:13:04 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.MyAddShape(
|
|
|
|
|
CompositeShape(self),
|
|
|
|
|
100, 260, wx.BLACK_PEN, wx.RED_BRUSH, "Composite"
|
|
|
|
|
)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
self.MyAddShape(
|
|
|
|
|
ogl.CircleShape(80),
|
2004-06-01 17:51:04 -04:00
|
|
|
|
75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle"
|
2003-12-08 20:23:28 -05:00
|
|
|
|
)
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
self.MyAddShape(
|
2004-06-01 17:51:04 -04:00
|
|
|
|
ogl.TextShape(120, 45),
|
|
|
|
|
160, 35, wx.GREEN_PEN, wx.LIGHT_GREY_BRUSH, "OGL is now a\npure Python lib!"
|
2004-05-25 22:13:04 -04:00
|
|
|
|
)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
self.MyAddShape(
|
|
|
|
|
ogl.RectangleShape(85, 50),
|
|
|
|
|
305, 60, wx.BLACK_PEN, wx.LIGHT_GREY_BRUSH, "Rectangle"
|
|
|
|
|
)
|
|
|
|
|
|
2004-08-31 10:54:13 -04:00
|
|
|
|
self.MyAddShape(
|
|
|
|
|
DrawnShape(),
|
|
|
|
|
500, 80, wx.BLACK_PEN, wx.BLACK_BRUSH, "DrawnShape"
|
|
|
|
|
)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
ds = self.MyAddShape(
|
2004-05-25 22:13:04 -04:00
|
|
|
|
DividedShape(140, 150, self),
|
2004-08-31 10:54:13 -04:00
|
|
|
|
520, 265, wx.BLACK_PEN, dsBrush, ''
|
2004-05-25 22:13:04 -04:00
|
|
|
|
)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
|
|
self.MyAddShape(
|
|
|
|
|
DiamondShape(90, 90),
|
2004-08-31 10:54:13 -04:00
|
|
|
|
355, 260, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon"
|
2003-12-08 20:23:28 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.MyAddShape(
|
2004-05-25 22:13:04 -04:00
|
|
|
|
RoundedRectangleShape(95, 70),
|
|
|
|
|
345, 145, wx.Pen(wx.RED, 2), rRectBrush, "Rounded Rect"
|
2003-12-08 20:23:28 -05:00
|
|
|
|
)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2001-04-09 15:36:36 -04:00
|
|
|
|
bmp = images.getTest2Bitmap()
|
2004-05-01 22:41:33 -04:00
|
|
|
|
mask = wx.Mask(bmp, wx.BLUE)
|
2001-04-01 23:49:52 -04:00
|
|
|
|
bmp.SetMask(mask)
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
s = ogl.BitmapShape()
|
2001-04-01 23:49:52 -04:00
|
|
|
|
s.SetBitmap(bmp)
|
2004-05-25 22:13:04 -04:00
|
|
|
|
self.MyAddShape(s, 225, 130, None, None, "Bitmap")
|
2001-04-01 23:49:52 -04:00
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
dc = wx.ClientDC(self)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.PrepareDC(dc)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
for x in range(len(self.shapes)):
|
|
|
|
|
fromShape = self.shapes[x]
|
|
|
|
|
if x+1 == len(self.shapes):
|
|
|
|
|
toShape = self.shapes[0]
|
|
|
|
|
else:
|
|
|
|
|
toShape = self.shapes[x+1]
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
|
|
line = ogl.LineShape()
|
1999-09-10 02:25:47 -04:00
|
|
|
|
line.SetCanvas(self)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
line.SetPen(wx.BLACK_PEN)
|
|
|
|
|
line.SetBrush(wx.BLACK_BRUSH)
|
|
|
|
|
line.AddArrow(ogl.ARROW_ARROW)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
line.MakeLineControlPoints(2)
|
|
|
|
|
fromShape.AddLine(line, toShape)
|
|
|
|
|
self.diagram.AddShape(line)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
line.Show(True)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
|
|
|
|
|
1999-09-30 03:11:20 -04:00
|
|
|
|
def MyAddShape(self, shape, x, y, pen, brush, text):
|
2004-05-25 22:13:04 -04:00
|
|
|
|
# Composites have to be moved for all children to get in place
|
|
|
|
|
if isinstance(shape, ogl.CompositeShape):
|
|
|
|
|
dc = wx.ClientDC(self)
|
|
|
|
|
self.PrepareDC(dc)
|
|
|
|
|
shape.Move(dc, x, y)
|
|
|
|
|
else:
|
|
|
|
|
shape.SetDraggable(True, True)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
shape.SetCanvas(self)
|
|
|
|
|
shape.SetX(x)
|
|
|
|
|
shape.SetY(y)
|
2001-04-01 23:49:52 -04:00
|
|
|
|
if pen: shape.SetPen(pen)
|
|
|
|
|
if brush: shape.SetBrush(brush)
|
2004-06-07 21:13:33 -04:00
|
|
|
|
if text:
|
|
|
|
|
for line in text.split('\n'):
|
|
|
|
|
shape.AddText(line)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
#shape.SetShadowMode(ogl.SHADOW_RIGHT)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
self.diagram.AddShape(shape)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
shape.Show(True)
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
|
|
|
|
evthandler = MyEvtHandler(self.log, self.frame)
|
|
|
|
|
evthandler.SetShape(shape)
|
|
|
|
|
evthandler.SetPreviousHandler(shape.GetEventHandler())
|
|
|
|
|
shape.SetEventHandler(evthandler)
|
|
|
|
|
|
|
|
|
|
self.shapes.append(shape)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
return shape
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
2001-04-01 23:49:52 -04:00
|
|
|
|
|
2001-09-26 22:11:47 -04:00
|
|
|
|
def OnBeginDragLeft(self, x, y, keys):
|
|
|
|
|
self.log.write("OnBeginDragLeft: %s, %s, %s\n" % (x, y, keys))
|
|
|
|
|
|
|
|
|
|
def OnEndDragLeft(self, x, y, keys):
|
|
|
|
|
self.log.write("OnEndDragLeft: %s, %s, %s\n" % (x, y, keys))
|
|
|
|
|
|
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2003-11-12 16:34:20 -05:00
|
|
|
|
# This creates some pens and brushes that the OGL library uses.
|
|
|
|
|
# It should be called after the app object has been created, but
|
|
|
|
|
# before OGL is used.
|
2003-12-11 14:55:48 -05:00
|
|
|
|
ogl.OGLInitialize()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
win = TestWindow(nb, log, frame)
|
|
|
|
|
return win
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
overview = """<html><body>
|
|
|
|
|
<h2>Object Graphics Library</h2>
|
1999-09-10 02:25:47 -04:00
|
|
|
|
|
|
|
|
|
The Object Graphics Library is a library supporting the creation and
|
|
|
|
|
manipulation of simple and complex graphic images on a canvas.
|
|
|
|
|
|
2004-05-25 22:13:04 -04:00
|
|
|
|
<p>The OGL library was originally written in C++ and provided to
|
|
|
|
|
wxPython via an extension module wrapper as is most of the rest of
|
|
|
|
|
wxPython. The code has now been ported to Python (with many thanks to
|
|
|
|
|
Pierre Hj<EFBFBD>lm!) in order to make it be more easily maintainable and
|
|
|
|
|
less likely to get rusty because nobody cares about the C++ lib any
|
|
|
|
|
more.
|
|
|
|
|
|
1999-09-10 02:25:47 -04:00
|
|
|
|
"""
|
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
|
if __name__ == '__main__':
|
2004-05-25 22:13:04 -04:00
|
|
|
|
import sys, os
|
2003-03-25 01:35:27 -05:00
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|