clipping region versus plot of region

All,

I don't understand why dc.DrawPolygon(points) and region = wx.RegionFromPoints(points) seem to occupy two different regions in the plane.

Help!

D.

import wx
from math import hypot, sin, cos, pi

class Star(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 300))
        
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
        self.Center()
        self.Show()
        
    def OnPaint(self, event):
        
        dc = wx.PaintDC(self)
        dc.SetPen(wx.Pen('#424242'))
        
        size_x, size_y = self.GetClientSizeTuple()
        dc.SetDeviceOrigin(size_x / 2, size_y / 2)
        
        points = (((0, 85), (75, 75), (100, 10), (125, 75), (200, 85),
            (150, 125), (160, 190), (100, 150), (40, 190), (50, 125)))
        
        dc.DrawPolygon(points)
        region = wx.RegionFromPoints(points)
        dc.SetClippingRegionAsRegion(region)
        
        radius = hypot(size_x / 2, size_y / 2)
        angle = 0
        
        while (angle < 2 * pi):
            x = radius * cos(angle)
            y = radius * sin(angle)
            dc.DrawLinePoint((0, 0), (x, y))
            angle += pi / 180
            
        dc.DestroyClippingRegion()
        
app = wx.App(False)
Star(None, -1, 'Star')
app.MainLoop()

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

This might be a bug, although I'm not 100% sure that a wx.Region is supposed to honor the device origin or not... Please create a ticket about it.

···

On 5/4/10 9:23 PM, David Arnold wrote:

All,

I don't understand why dc.DrawPolygon(points) and region = wx.RegionFromPoints(points) seem to occupy two different regions in the plane.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Where do I go to report this?

D.

···

On May 4, 2010, at 9:42 PM, Robin Dunn wrote:

On 5/4/10 9:23 PM, David Arnold wrote:

All,

I don't understand why dc.DrawPolygon(points) and region = wx.RegionFromPoints(points) seem to occupy two different regions in the plane.

This might be a bug, although I'm not 100% sure that a wx.Region is supposed to honor the device origin or not... Please create a ticket about it.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

1) Go to http://wxpython.org/
2) On the right, bottom third, there's a "Report a Bug" link
3) Click that and you'll go here: http://trac.wxwidgets.org/
4) Submit your bug (Note: You may need to Register)

I think you need to mark it as wxPython specific, but I'm not sure.

···

On May 5, 1:53 am, David Arnold <dwarnol...@suddenlink.net> wrote:

Where do I go to report this?

D.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

See wxTrac has been migrated to GitHub Issues - wxWidgets. That is from the C++ guys but mostly applies to wxPython tickets too.

···

On 5/4/10 11:53 PM, David Arnold wrote:

Where do I go to report this?

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Not in this case. I don't think it is a wxPython bug, it should probably use the GUI-all component.

···

On 5/5/10 7:24 AM, Mike Driscoll wrote:

On May 5, 1:53 am, David Arnold<dwarnol...@suddenlink.net> wrote:

Where do I go to report this?

D.

1) Go to http://wxpython.org/
2) On the right, bottom third, there's a "Report a Bug" link
3) Click that and you'll go here: http://trac.wxwidgets.org/
4) Submit your bug (Note: You may need to Register)

I think you need to mark it as wxPython specific, but I'm not sure.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

All,

I stumbled across one of Robin Dunn's examples by accident:

http://chandlerproject.org/Projects/WxPythonGraphicsContext

Are there more such examples, or better yet, a tutorial on using wx.GraphicsContext?

Finally, Suppose that I create a drawing area that is 300 by 300, but I want to map user coordinates [-1,1] on the horizontal, and [-1,1] on the vertical, with the origin centered in the middle of the drawing area. What is the best way to proceed with this idea? Has anyone some example code for a similar construct?

Thanks.

David

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

All,

I stumbled across one of Robin Dunn's examples by accident:

Chandler Wiki : Wx Python Graphics Context

Are there more such examples,

There is a similar example in the demo which has been tweaked a little since that screenshot was taken, but it's basically the same thing.

or better yet, a tutorial on using wx.GraphicsContext?

I don't recall seeing any GC tutorials anywhere either, it is a relatively new feature and not many people are using it yet. It mostly follows the same high level design principles as the advanced drawing APIs on each platform (GDI+, CoreGraphics, Cairo) based on paths and matrix transforms, so if you understand how things work in one of those APIs it shouldn't be too much of a leap to understand wxGC.

Finally, Suppose that I create a drawing area that is 300 by 300, but I want to map user coordinates [-1,1] on the horizontal, and [-1,1] on the vertical, with the origin centered in the middle of the drawing area. What is the best way to proceed with this idea? Has anyone some example code for a similar construct?

It can be done with wxGC without too much hassle. You can use Translate() to move the origin to the center, and Scale() to change the coordinate space. I've attached a simple example of this.

Unfortunately, there isn't yet a way to specify a pen with a fractional width, so when you scale the GC like this you end up with very fat stroked lines. If you have PyCairo installed then you can use wx.lib.graphics instead, which is a wxGC-like API that uses Cairo on all the platforms, and which can use a pen with a fractional width.

test_gcScale.py (1.44 KB)

···

On 5/5/10 11:54 AM, David Arnold wrote:

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en