FAQ
Experimenting with graphics in an app: it's AUI based with a few panes,
one of which has a panel containing a few sizers holding UI elements.
One sizer contains a panel that needs some basic line-drawing graphics
in it.

I use the wxPython demo app heavily to figure this stuff out, and my
experiments seem to work, but I'm flying blind somewhat.

Can someone englighten me about the wx.GraphicsContext versus wx.PaintDC
(BTW what does PaintDC stand for? Drawing Context perhaps?)

The scrolledWindow and GraphicsContext examples are helpful, but it
appears I can draw a rectangles, lines and text in either just a
straight wxPaintDC, or can do:

dc = wx.PaintDC(self)
gc = wx.GraphicsContext.Create(dc)

...and do the same drawing with gc.DrawText etc...

Can someone clarify the differences or added value of the gc over the
dc, and is using the dc alone a valid approach? Where will it end up
biting me - I don't mean which body part :) Perhaps I should say in
which situation will it bite...

Thx,
Ross.

Search Discussions

  • Chris Mellon at Aug 19, 2008 at 6:27 pm

    On Tue, Aug 19, 2008 at 1:16 PM, RgeeK wrote:
    Experimenting with graphics in an app: it's AUI based with a few panes, one
    of which has a panel containing a few sizers holding UI elements. One sizer
    contains a panel that needs some basic line-drawing graphics in it.

    I use the wxPython demo app heavily to figure this stuff out, and my
    experiments seem to work, but I'm flying blind somewhat.

    Can someone englighten me about the wx.GraphicsContext versus wx.PaintDC
    (BTW what does PaintDC stand for? Drawing Context perhaps?)

    The scrolledWindow and GraphicsContext examples are helpful, but it appears
    I can draw a rectangles, lines and text in either just a straight wxPaintDC,
    or can do:

    dc = wx.PaintDC(self)
    gc = wx.GraphicsContext.Create(dc)

    ...and do the same drawing with gc.DrawText etc...

    Can someone clarify the differences or added value of the gc over the dc,
    and is using the dc alone a valid approach? Where will it end up biting me
    - I don't mean which body part :) Perhaps I should say in which situation
    will it bite...
    This is probably better suited to the wxPython ML instead of c.l.p,
    because it's so specific.

    In short: wxDC (and friends) are traditional raster based drawing
    contexts. wxGraphicsContext is a vector/path based API. If you're
    doing drawing that's suited for a vector format (like line drawing
    probably is), using wxGraphicsContext will give you better image
    quality as well as the general vector features like free scaling,
    rotation, transforms, etc,
  • RgeeK at Aug 21, 2008 at 7:55 pm

    Chris Mellon wrote:
    This is probably better suited to the wxPython ML instead of c.l.p,
    because it's so specific.

    In short: wxDC (and friends) are traditional raster based drawing
    contexts. wxGraphicsContext is a vector/path based API. If you're
    doing drawing that's suited for a vector format (like line drawing
    probably is), using wxGraphicsContext will give you better image
    quality as well as the general vector features like free scaling,
    rotation, transforms, etc,
    Thx Chris - I wasn't aware of the wxPython ML. I'll hunt around for it
    for further q's in that vein.

    Your explanation is helpful tho' - thx.
  • Tim Roberts at Aug 22, 2008 at 6:28 am

    RgeeK wrote:
    ...
    I use the wxPython demo app heavily to figure this stuff out, and my
    experiments seem to work, but I'm flying blind somewhat.

    Can someone englighten me about the wx.GraphicsContext versus wx.PaintDC
    (BTW what does PaintDC stand for? Drawing Context perhaps?)
    Yes. The DC is a concept straight from the Windows GDI API. It holds your
    current surface, your current foreground and background colors, your
    current pattern, your current raster op, etc. In X, the same concept is
    called a "gc" -- graphics context.

    Windows requires special handling to create a DC within a WM_PAINT handler
    (which is what calls OnPaint). That's why wx.PaintDC is separate. Outside
    of OnPaint, you'd usually use wx.ClientDC.
    --
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 19, '08 at 6:16p
activeAug 22, '08 at 6:28a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase