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
|
import unittest
from unittests import wtc
import wx
import os
#---------------------------------------------------------------------------
class graphics_Tests(wtc.WidgetTestCase):
def test_gcCreate1(self):
gc = wx.GraphicsContext.Create(wx.ClientDC(self.frame))
self.assertTrue(gc.IsOk())
def test_gcCreate2(self):
bmp = wx.Bitmap(100,100)
mdc = wx.MemoryDC(bmp)
gc = wx.GraphicsContext.Create(mdc)
self.assertTrue(gc.IsOk())
def test_gcCreate3(self):
img = wx.Image(100,100)
gc = wx.GraphicsContext.Create(img)
self.assertTrue(gc.IsOk())
def test_gcCreate4(self):
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.painted = False
self.gcIsOk = False
def OnPaint(self, evt):
dc = wx.AutoBufferedPaintDC(self)
gc = wx.GraphicsContext.Create(dc)
self.gcIsOk = gc.IsOk()
self.painted = True
panel = MyPanel(self.frame)
self.myUpdate(panel)
self.waitFor(100)
self.assertTrue(panel.painted)
self.assertTrue(panel.gcIsOk)
def test_gcCreateBitmap(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
self.assertTrue(gc.IsOk())
bmp = wx.Bitmap(100,100)
gb = gc.CreateBitmap(bmp)
self.assertTrue(gb.IsOk())
self.assertTrue(isinstance(gb, wx.GraphicsBitmap))
img = wx.Image(100,100)
gb = gc.CreateBitmapFromImage(img)
self.assertTrue(gb.IsOk())
# CreateSubBitmap is not implemented for wxCairoRenderer
if 'wxGTK' not in wx.PlatformInfo:
gb = gc.CreateSubBitmap(gb, 5, 5, 25, 25)
self.assertTrue(gb.IsOk())
img = gb.ConvertToImage()
self.assertTrue(img.IsOk())
def test_gcCreateBrush(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gb = gc.CreateBrush(wx.Brush('blue'))
self.assertTrue(gb.IsOk())
self.assertTrue(isinstance(gb, wx.GraphicsBrush))
def test_gcCreateFont(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gf = gc.CreateFont(wx.NORMAL_FONT)
self.assertTrue(gf.IsOk())
self.assertTrue(isinstance(gf, wx.GraphicsFont))
gf = gc.CreateFont(15, 'Courier')
self.assertTrue(gf.IsOk())
def test_gcCreatePen(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gp = gc.CreatePen(wx.RED_PEN)
self.assertTrue(gp.IsOk())
self.assertTrue(isinstance(gp, wx.GraphicsPen))
def test_gcCreatePath(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
p = gc.CreatePath()
self.assertTrue(p.IsOk())
self.assertTrue(isinstance(p, wx.GraphicsPath))
def test_gcCreateMatrix(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
m = gc.CreateMatrix()
self.assertTrue(m.IsOk())
self.assertTrue(isinstance(m, wx.GraphicsMatrix))
values = m.Get()
self.assertTrue(len(values) == 6)
dx, dy = m.TransformDistance(5,6)
x,y = m.TransformPoint(7,8)
def test_gcTextExtents(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gf = gc.CreateFont(wx.NORMAL_FONT)
gc.SetFont(gf)
ext = gc.GetPartialTextExtents("Hello")
self.assertEqual(len(ext), 5)
w, h, d, e = gc.GetFullTextExtent("Hello")
w, h = gc.GetTextExtent("Hello")
def test_gcStrokeLines1(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gc.SetPen(wx.Pen('blue', 2))
points = [ wx.Point2D(5,5),
wx.Point2D(50,5),
wx.Point2D(50,50),
wx.Point2D(5,5),
]
gc.StrokeLines(points)
def test_gcStrokeLines2(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gc.SetPen(wx.Pen('blue', 2))
points = [ (5,5), (50,5), wx.Point2D(50,50), (5,5) ]
gc.StrokeLines(points)
def test_gcStrokeLines3(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gc.SetPen(wx.Pen('blue', 2))
with self.assertRaises(TypeError):
points = [ (5,5), (50,5), 'not a point', (5,5) ]
gc.StrokeLines(points)
def test_gcDrawLines(self):
self.waitFor(50)
gc = wx.GraphicsContext.Create(self.frame)
gc.SetPen(wx.Pen('blue', 2))
points = [ (5,5), (50,5), wx.Point2D(50,50), (5,5) ]
gc.DrawLines(points)
def test_gcGradientStops(self):
self.waitFor(50)
gs1 = wx.GraphicsGradientStop('red', 0.25)
gs2 = wx.GraphicsGradientStop('green', 0.50)
gs3 = wx.GraphicsGradientStop('blue', 0.90)
gs1.Colour
gs1.Position
stops = wx.GraphicsGradientStops()
stops.Add(gs1)
stops.Add(gs2)
stops.Add('white', 0.75)
stops.Add(gs3)
self.assertEqual(len(stops), 6) # 2 existing, plus 4 added
gs = stops[2]
self.assertTrue(gs.Position == 0.5)
gc = wx.GraphicsContext.Create(self.frame)
b = gc.CreateLinearGradientBrush(0,0, 500, 100, stops)
def test_gcNullObjects(self):
wx.NullGraphicsPen
wx.NullGraphicsBrush
wx.NullGraphicsFont
wx.NullGraphicsBitmap
wx.NullGraphicsMatrix
wx.NullGraphicsPath
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
|