sciter-sdk / pysciter

Python bindings for Sciter
https://sciter.com
MIT License
396 stars 40 forks source link

How to load files from pyinstaller's temp directory? #52

Open GirkovArpa opened 2 years ago

GirkovArpa commented 2 years ago
Graphics.Image.load('image.png')

This tries to load the file image.png from the same folder as the executable. But, image.png is actually in a temp folder, because I've packaged everything into a single executable with pyinstaller, and when running it extracts everything to a temp folder.

So, how to tell Sciter to load image.png from the temp folder, and not the current executable's folder?

In other words, the same folder as index.html.

GirkovArpa commented 2 years ago

Also take note about Host.on_load_data, where you can intercept resources load requests and override with your own path:

Originally posted by @pravic in https://github.com/sciter-sdk/pysciter/issues/11#issuecomment-250925289

How would one go about this? I tried this:

def on_load_data(self, nm):
    nm.uri = sys._MEIPASS + '/' + nm.uri
    pass

But got this error:

Exception ignored on calling ctypes callback function: <bound method Host.handle_notification of <main.Frame object at 0x000002D5325D4430>>

TypeError: unicode string or integer address expected instead of bytes instance

GirkovArpa commented 2 years ago

I got around this issue by editing main.html on every run via python in order to insert the necessary path information. But others may still need a less hackish solution.

pravic commented 2 years ago

unicode string or integer address expected instead of bytes instance

What's the type of sys._MEIPASS + '/' + nm.uri?