pyx-project / pyx

Repository of PyX, a Python package for the creation of PostScript, PDF, and SVG files.
https://pyx-project.org/
GNU General Public License v2.0
109 stars 18 forks source link

AttributeError: 'arc' object has no attribute 'bbox' #15

Closed s1291 closed 4 years ago

s1291 commented 4 years ago

Hello, I am trying to run the following basic example:

from pyx import canvas, path, deco

rect = path.rect(0, 0, 5, 2)
arc = path.arc(0, 0, 1, 30, 45)
canvas = canvas.canvas()

canvas.stroke(rect, [deco.earrow.small])
canvas.stroke(arc)

canvas.writePDFfile()

When I run it:

python3 example2.py

I get the following error:

C:\Users\PC\AppData\Local\Temp\pyx>python example2.py
Traceback (most recent call last):
  File "example2.py", line 10, in <module>
    canvas.writePDFfile()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\canvas.py", line 50, in wrappedindocument
    return method(d, file, **write_kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\document.py", line 193, in writePDFfile  
    pdfwriter.PDFwriter(self, f, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\pdfwriter.py", line 329, in __init__
    catalog = PDFcatalog(document, self, registry)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\pdfwriter.py", line 143, in __init__
    self.PDFpages = PDFpages(document, writer, registry)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\pdfwriter.py", line 202, in __init__
    page = PDFpage(page, pageno, self, writer, registry)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\pdfwriter.py", line 236, in __init__
    self.PDFcontent = PDFcontent(page, writer, self.pageregistry)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\pdfwriter.py", line 268, in __init__
    page.processPDF(contentfile, awriter, acontext, registry, self.bbox)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\document.py", line 135, in processPDF
    self._process("processPDF", *args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\document.py", line 78, in _process
    bbox.set(self.canvas.bbox()) # this bbox is not accurate
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\canvas.py", line 179, in bbox
    obbox += cmd.bbox()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyx\deco.py", line 101, in bbox
    pathbbox = self.path.bbox()
AttributeError: 'arc' object has no attribute 'bbox'
gertingold commented 4 years ago

path.arc is a path element. Give it as a parameter to path.path to create a path. The third line should read

arc = path.path(path.arc(0, 0, 1, 30, 45))