GChristensen / enso-portable

Portable Enso Launcher community edition
Other
164 stars 46 forks source link

Need help with error for new Enso Command. #28

Closed tnmeesters closed 1 year ago

tnmeesters commented 1 year ago

Hello,

I'm trying to create a new script within the 'Enso Command Editor' but I'm getting an error that I do not understand.

Below is what I have in the command editor. I have installed the docx2pdf package.

from docx2pdf import convert from pathlib import Path

def cmd_convert_docx_to_pdf(ensoapi): """ Convert docx to pdf """ seldict = ensoapi.get_selection()

if seldict.get('files'):
    file = seldict['files'][0]
elif seldict.get('text'):
    file = seldict['text'].strip()
else:
    file = None

if not (file and (os.path.isfile(file) or os.path.isdir(file))):
    ensoapi.display_message("No file or folder is selected...")
    return

path = Path(file)
convert(path)

This is the error that I get with the traceback command.

Scriptotron exception: Traceback (most recent call last): File "C:\Data\Programs\Enso\enso\contrib\scriptotron\tracebacks.py", line 63, in wrapper return func( *args, *kwargs ) File "C:\Data\Programs\Enso\enso\contrib\scriptotron\adapters.py", line 35, in run result = self.func(self.ensoapi) File "C:\Data\Programs\Enso.enso\commands\user.py", line 60, in cmd_convert_docx_to_pdf docx2pdf.convert(r"C:\Users\SpecificUser\Desktop\test.docx", r"C:\Users\SpecificUser\Desktop\test.pdf") File "C:\Data\Programs\Enso\python\lib\site-packages\docx2pdf__init.py", line 106, in convert return windows(paths, keep_active) File "C:\Data\Programs\Enso\python\lib\site-packages\docx2pdf__init.py", line 29, in windows pbar = tqdm(total=1) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\asyncio.py", line 24, in init__ super(tqdm_asyncio, self).init__(iterable, args, *kwargs) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\std.py", line 1109, in init self.refresh(lock_args=self.lock_args) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\std.py", line 1361, in refresh self.display() File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\std.py", line 1509, in display self.sp(self.str() if msg is None else msg) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\std.py", line 350, in print_status fp_write('\r' + s + (' ' max(last_len[0] - len_s, 0))) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\std.py", line 343, in fp_write fp.write(_unicode(s)) File "C:\Data\Programs\Enso\python\lib\site-packages\tqdm\utils.py", line 89, in getattr return getattr(self._wrapped, name) AttributeError: 'NoneType' object has no attribute 'write'


I think I have installed docx2pdf correctly. I use it on windows 10. Thanks for keeping Enso up and running. Still use it every day.

Thomas

GChristensen commented 1 year ago

Hi,

tqdm is a progress bar that is displayed in the console window. Because Enso is launched using pythonw, there is no console window, so it might not work as expected. So, this error is not directly related to Enso.

A possible solutions might be:

  1. To redirect stdout or stderr to a file, in a such way:

sys.stderr = open("/path/to/a/writable/directory/stderr.log", "w")

before calling convert,

  1. If docx2pdf has no option to disable the console output, it may be necessary to edit its sources to manually disable it.

  2. Use another docx to pdf conversion library.