vilcans / screenplain

Write your screenplay in plain text and run it through this program to make it look good
MIT License
163 stars 29 forks source link

TypeError when output-file omitted #53

Closed rnkn closed 4 years ago

rnkn commented 4 years ago

From the usage message, it would appear to indicate that the output file is optional when generating PDF/HTML output, however, when omitting and output file I receive the following error:

$ screenplain -f pdf INPUT.fountain
Traceback (most recent call last):
  File "/usr/local/bin/screenplain", line 6, in <module>
    main(sys.argv[1:])
  File "/usr/local/lib/python3.7/site-packages/screenplain/main.py", line 131, in main
    to_pdf(screenplay, output, is_strong=options.strong)
  File "/usr/local/lib/python3.7/site-packages/screenplain/export/pdf.py", line 277, in to_pdf
    doc.build(story)
  File "/usr/local/lib/python3.7/site-packages/reportlab/platypus/doctemplate.py", line 1082, in build
    self._endBuild()
  File "/usr/local/lib/python3.7/site-packages/reportlab/platypus/doctemplate.py", line 1017, in _endBuild
    if getattr(self,'_doSave',1): self.canv.save()
  File "/usr/local/lib/python3.7/site-packages/reportlab/pdfgen/canvas.py", line 1244, in save
    self._doc.SaveToFile(self._filename, self)
  File "/usr/local/lib/python3.7/site-packages/reportlab/pdfbase/pdfdoc.py", line 222, in SaveToFile
    f.write(data)
TypeError: write() argument must be str, not bytes

The same occurs with -f html.

I’ve installed screenplain via:

$ pip install ’screenplain[pdf]'
vilcans commented 4 years ago

This is because Screenplain is written for Python 2.

Now that the Python Foundation finally no longer supports Python 2.x, it is about time making the master branch of Screenplain be Python 3 compatible. I opened a separate issue for that: #54

rnkn commented 4 years ago

Ah I probably should have figured that one out on my own, thanks!

tin2tin commented 3 years ago

I'm still getting this error when using Python 3.7 and installed with pip. Has this change been included in the pip version?

vilcans commented 3 years ago

I can't reproduce it. I tried with:

vilcans@nice:~/proj $ virtualenv tempenv
created virtual environment CPython3.6.9.final.0-64 in 97ms
  creator CPython3Posix(dest=/home/vilcans/proj/tempenv, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/vilcans/.local/share/virtualenv/seed-app-data/v1.0.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
vilcans@nice:~/proj $ . tempenv/bin/activate
(tempenv) vilcans@nice:~/proj $ python --version
Python 3.6.9
(tempenv) vilcans@nice:~/proj $ pip install 'screenplain[pdf]'
Collecting screenplain[pdf]
  Using cached screenplain-0.9.0-py3-none-any.whl (17 kB)
Collecting reportlab; extra == "pdf"
  Using cached reportlab-3.5.57-cp36-cp36m-manylinux2010_x86_64.whl (2.6 MB)
Collecting pillow>=4.0.0
  Using cached Pillow-8.0.1-cp36-cp36m-manylinux1_x86_64.whl (2.2 MB)
Installing collected packages: pillow, reportlab, screenplain
Successfully installed pillow-8.0.1 reportlab-3.5.57 screenplain-0.9.0
WARNING: You are using pip version 20.0.2; however, version 20.3.3 is available.
You should consider upgrading via the '/home/vilcans/proj/tempenv/bin/python -m pip install --upgrade pip' command.
(tempenv) vilcans@nice:~/proj $ screenplain Big-Fish.fountain out.pdf
(tempenv) vilcans@nice:~/proj $ file out.pdf
out.pdf: PDF document, version 1.4

But that is Python 3.6.9 though. I also tried screenplain -f pdf Big-Fish.fountain which outputs the PDF to stdout, and that worked on the Linux machine I tested on. Maybe OS/X doesn't work the same. What happens if you write the pdf to a file instead? And are you sure you're getting the exact same error? I should try with Python 3.7 too.

tin2tin commented 3 years ago

I'm using the Blender included python on Windows. I think it is 3.77. I'm calling the pdf the exact same way as html and fdx export: https://github.com/tin2tin/Blender_Screenwriter/blob/master/operators/fountain_export.py#L75 And only pdf fails. ReportLab is also installed.

image

Should I make a separate bug-report for this?

tin2tin commented 3 years ago

Unfortunately, I'm stuck with the python version included with Blender. Is there anything else I could try?

vilcans commented 3 years ago

Unfortunately, I'm stuck with the python version included with Blender. Is there anything else I could try?

I have tried to reproduce the error in Blender 2.91, but for me the "Export screenplain" menu option is disabled.

I also encountered a problem when installing the add-on, so I created an issue for that.

vilcans commented 3 years ago

@tin2tin But I tested this in Blender's Python console, and it generated a PDF without problems:

>>> from screenplain.parsers.fountain import parse_lines
>>> s = parse_lines(["X"])
>>> from screenplain.export.pdf import to_pdf
>>> to_pdf(s, 'c:\\proj\\test.pdf')
tin2tin commented 3 years ago

Thank you for spending your time on this.

You'll need to have a filename in the text editor with the .fountain extension to enable export.

Checking again. Are you on Windows?

tin2tin commented 3 years ago

I'm using this to ensure proper installation of screenplain: https://blenderartists.org/t/pip-for-blender/1259938 Fixed the missing subprocess problem. Html and fdx exports okay, but pdf doesn't.

tin2tin commented 3 years ago

This is what I get: image

tin2tin commented 3 years ago

I had some success with running Blender in Admin mode and used strings like you did, but using parse_line I get this layout in the produced pdf file: image image Do you have any clue why the string isn't parsed correctly?

tin2tin commented 3 years ago

Okay, if I input the screenplay as bytes and the output as string it works.

vilcans commented 3 years ago

This is what I get: image

That's because the c:\proj folder doesn't exist on your computer. That's just a folder where I keep my projects, so for me it exists. 😄

vilcans commented 3 years ago

I had some success with running Blender in Admin mode and used strings like you did, but using parse_line I get this layout in the produced pdf file: image Do you have any clue why the string isn't parsed correctly?

parse_lines takes a sequence of strings as arguments, e.g. a list as in parse_lines(['Line 1', 'Line 2']). If you supply a string to it, e.g. parse_lines('Line 1\nLine 2'), it will treat each character as a line. Instead call parse in that case.

tin2tin commented 3 years ago

I've updated the Blender Screenwriter project to reflect these changes.