[wxPython-users] Graphics context Docs
Christopher Barker
Chris.Barker at noaa.gov
Wed Sep 5 20:54:36 PDT 2007
Christopher Barker wrote:
> Dj Gilcrease wrote:
>> Actually it shouldnt be any harder then drawing your line since you
>> have to create a path for your line anyways, you just use FillPath
>> instead of DrawPath
> =
> Is it really that easy? I guess I expected that a path that was just a =
> poly-line had no area, and thus no fill -- but I guess it's time to =
> experiment.
I've experimented, and alas, I was right -- you need some area to your =
path in order to fill it. I did get it to work by drawing a =
parallelogram, but it's sure more work than if you could jsut make a =
path and stroke it with a GradientPen.
Oh Well,
-Chris
Test Code enclosed for anyone curious.
-- =
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
-------------- next part --------------
#/usr/bin/env python
"""
A simmple test for GraphicsContext
"""
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
=
self.Bind(wx.EVT_PAINT, self.OnPaint)
=
def OnPaint(self, evt):
print "In OnPaint"
=
DC =3D wx.PaintDC(self)
self.Draw(DC)
=
def Draw(self, DC):
print "In Draw"
DC.SetBackground(wx.Brush("White"))
DC.Clear()
=
GC =3D wx.GraphicsContext.Create(DC)
=
Pen =3D GC.CreatePen(wx.Pen("Black", 4))
=
GC.SetPen(Pen)
GC.DrawLines([(0,0),(100,100),(300,100)])
GC.SetPen(wx.TRANSPARENT_PEN)
c1 =3D wx.Color(255, 0, 0, 255)
c2 =3D wx.Color(255, 0, 0, 0)
Brush =3D GC.CreateLinearGradientBrush(20, 150, 300, 150, c1, c2)
GC.SetBrush(Brush)
GC.DrawRectangle(20, 150, 200, 1)
=
Path =3D GC.CreatePath()
Path.MoveToPoint(0,0)
Path.AddLineToPoint(500,300)
Path.AddLineToPoint(500,298)
Path.AddLineToPoint(0,-2)
=
GC.SetPen(wx.Pen("Blue", 3))
#GC.SetBrush(wx.Brush("Red"))
#GC.DrawPath(Path)
Brush =3D GC.CreateLinearGradientBrush(-2, -2, 500, 300, c1, c2)
GC.SetBrush(Brush)
GC.FillPath(Path)
=
A =3D wx.App(0)
F =3D MyFrame(None)
F.Show()
A.MainLoop()
=
=20
More information about the wxpython-users
mailing list