1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
import unittest
from unittests import wtc
import wx
import wx.lib.ogl as ogl
class lib_ogl_Tests(wtc.WidgetTestCase):
def test_lib_oglCtor(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.RectangleShape(w=50, h=50)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
def test_lib_oglRectangle(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.RectangleShape(w=50, h=50)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
def test_lib_oglPolygonShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.PolygonShape()
w, h = 60, 60
points = [(0.0, -h/2.0),
(w/2.0, 0.0),
(0.0, h/2.0),
(-w/2.0, 0.0),
]
aShape.Create(points)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
def test_lib_oglCircle(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.CircleShape(50)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
def test_lib_oglEllipseShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.EllipseShape(50, 50)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
def test_lib_oglTextShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.TextShape(50, 50)
aShape.SetCanvas(osc)
aShape.AddText("Some nice text here")
self.diagram.AddShape(aShape)
def test_lib_oglLineShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
fromShape = ogl.RectangleShape(w=50, h=50)
fromShape.SetCanvas(osc)
self.diagram.AddShape(fromShape)
toShape = ogl.RectangleShape(w=50, h=50)
toShape.SetCanvas(osc)
self.diagram.AddShape(toShape)
lShape = ogl.LineShape()
lShape.SetCanvas(osc)
lShape.MakeLineControlPoints(2)
fromShape.AddLine(lShape, toShape)
self.diagram.AddShape(lShape)
lShape.Show(True)
def test_lib_oglShapeRegion(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.RectangleShape(w=50, h=50)
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
region1 = ogl.ShapeRegion()
region1.SetText('DividedShape')
region1.SetProportions(0.0, 0.2)
region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
aShape.AddRegion(region1)
def test_lib_oglDivisonShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.CompositeShape()
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
# create a division in the composite
aShape.MakeContainer()
# add a shape to the original division
shape2 = ogl.RectangleShape(40, 60)
aShape.GetDivisions()[0].AddChild(shape2)
def test_lib_oglCompositeShape(self):
ogl.OGLInitialize()
osc = ogl.ShapeCanvas(self.frame)
self.diagram = ogl.Diagram()
osc.SetDiagram(self.diagram)
self.diagram.SetCanvas(osc)
aShape = ogl.CompositeShape()
aShape.SetCanvas(osc)
self.diagram.AddShape(aShape)
constraining_shape = ogl.RectangleShape(120, 100)
constrained_shape1 = ogl.CircleShape(50)
constrained_shape2 = ogl.RectangleShape(80, 20)
aShape.AddChild(constraining_shape)
aShape.AddChild(constrained_shape1)
aShape.AddChild(constrained_shape2)
constraint = ogl.Constraint(ogl.CONSTRAINT_MIDALIGNED_BOTTOM,
constraining_shape,
[constrained_shape1, constrained_shape2])
aShape.AddConstraint(constraint)
aShape.Recompute()
def test_lib_ogl_Constants(self):
ogl.CONSTRAINT_CENTRED_VERTICALLY
ogl.CONSTRAINT_CENTRED_HORIZONTALLY
ogl.CONSTRAINT_CENTRED_BOTH
ogl.CONSTRAINT_LEFT_OF
ogl.CONSTRAINT_RIGHT_OF
ogl.CONSTRAINT_ABOVE
ogl.CONSTRAINT_BELOW
ogl.CONSTRAINT_ALIGNED_TOP
ogl.CONSTRAINT_ALIGNED_BOTTOM
ogl.CONSTRAINT_ALIGNED_LEFT
ogl.CONSTRAINT_ALIGNED_RIGHT
# Like aligned, but with the objects centred on the respective edge
# of the reference object.
ogl.CONSTRAINT_MIDALIGNED_TOP
ogl.CONSTRAINT_MIDALIGNED_BOTTOM
ogl.CONSTRAINT_MIDALIGNED_LEFT
ogl.CONSTRAINT_MIDALIGNED_RIGHT
# from _drawn
ogl.METAFLAGS_OUTLINE
ogl.METAFLAGS_ATTACHMENTS
ogl.DRAWN_ANGLE_0
ogl.DRAWN_ANGLE_90
ogl.DRAWN_ANGLE_180
ogl.DRAWN_ANGLE_270
# Drawing operations
ogl.DRAWOP_SET_PEN
ogl.DRAWOP_SET_BRUSH
ogl.DRAWOP_SET_FONT
ogl.DRAWOP_SET_TEXT_COLOUR
ogl.DRAWOP_SET_BK_COLOUR
ogl.DRAWOP_SET_BK_MODE
ogl.DRAWOP_SET_CLIPPING_RECT
ogl.DRAWOP_DESTROY_CLIPPING_RECT
ogl.DRAWOP_DRAW_LINE
ogl.DRAWOP_DRAW_POLYLINE
ogl.DRAWOP_DRAW_POLYGON
ogl.DRAWOP_DRAW_RECT
ogl.DRAWOP_DRAW_ROUNDED_RECT
ogl.DRAWOP_DRAW_ELLIPSE
ogl.DRAWOP_DRAW_POINT
ogl.DRAWOP_DRAW_ARC
ogl.DRAWOP_DRAW_TEXT
ogl.DRAWOP_DRAW_SPLINE
ogl.DRAWOP_DRAW_ELLIPTIC_ARC
# Line alignment flags
# Vertical by default
ogl.LINE_ALIGNMENT_HORIZ
ogl.LINE_ALIGNMENT_VERT
ogl.LINE_ALIGNMENT_TO_NEXT_HANDLE
ogl.LINE_ALIGNMENT_NONE
# keys
ogl.KEY_SHIFT
ogl.KEY_CTRL
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
|