Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use clip with canvas #20

Closed
djnugent opened this issue Jul 15, 2020 · 3 comments
Closed

Can't use clip with canvas #20

djnugent opened this issue Jul 15, 2020 · 3 comments

Comments

@djnugent
Copy link

When I run

from pyx import canvas
can = canvas.canvas([canvas.clip])

I get this error

Traceback (most recent call last):
    can = canvas.canvas([canvas.clip])
  File "/usr/local/lib/python3.6/dist-packages/pyx/canvas.py", line 135, in __init__
    attr.checkattrs(attrs, [trafo.trafo_pt, clip, style.style])
  File "/usr/local/lib/python3.6/dist-packages/pyx/attr.py", line 56, in checkattrs
    raise TypeError("instance %r not allowed" % attrs[len(getattrs(attrs, allowedclasses))])
TypeError: instance <class 'pyx.canvas.clip'> not allowed

Pyx version 0.15
Python 3.6

@djnugent
Copy link
Author

Ah. This is likely because it is an uninitialized clip object. I misunderstood the purpose of clip. Not a lot of documentation on what clip actually does other than "it clips". Will need to do more digging

@djnugent
Copy link
Author

Yep that was it. Pasting solution for anyone who gets stuck on this.

clip = canvas.clip(path.rect(0, 0,10,10)) # clip takes in a path
can = canvas.canvas([clip])

@gertingold
Copy link
Contributor

In such a case, it may be useful to take a look at the example section: https://pyx-project.org/examples/drawing2/clipping.html . I admit that each time I use clipping, which is not very often, I have to look up its usage and that is the place I usually turn to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants