Can I use python in html to call functions in other libs? #544

Closed
tempbeta opened this Issue Mar 15, 2013 · 8 comments

Projects

None yet

6 participants

@tempbeta

I want to use python as a glue language to call DLLs, shared libraries,etc.
I tried this:

<head>
<script type="text/python" src="py/app.py"></script>
</head>
<body>
<button onClick="foo()">test</button>
</body>

app.py:

def foo():
    windll.user32.MessageBoxA(0, 'test','show',  0)

It didn't work for me,but it works in TideSDK.
Any where wrong?Or there are some security limits?

@Subash

node-webkit allows you to call nodejs modules and javascript not python.
In other words, node-webkit doesn't support python.

@tempbeta

thank you sbspk
I tried IronPython to do it:

http://localhost:8000/

<script src="js/dlr-latest.js" type="text/javascript"></script>
<script type="application/x-python">
window.Alert('Hello')
import sys
sys.path.append ("py/Lib")
import ctypes
</script>

it works but can't import modules like ctypes:
ImportError: No module named ctypes
What should I do?

Maybe I should try node-ffi

@sonicsnes

I can't find any bindings allowing direct communication between node-flavored javascript and python.

Firstly, I'm going to throw in the customary "why would you even do that?"

However, if you really do need this to work, consider writing a wrapper for your python script which creates an API on a localhost-bound port or socket. Then, launch the python script from your node-webkit application and communicate with it via that socket.

@tempbeta

@sonicsnes sounds like a good idea.I will try it.

@dubcanada

May I ask what you need python for? Nothing against Python, but what can't you do in JS that you can do in Python? Or is something already built.

If it's something already done, you could try... http://www.skulpt.org/ or something like that.

Even then the point of node-webkit is multiplatform webkit based gui. Adding python would remove support for Windows/maybe Mac depending on what you need. You'd need to hack together some sort of solution for those.

Moral of the story is, it sounds like way too much work.

@owenc4a4

I think nodejs is as powerful as python. nodejs is enough.
I also can run python as a child process. I think it is easy to implement.

@tempbeta

@dubcanada I need python to call Win32API (with ctypes),I found JS can do it only with node-ffi(AFAIK) ,It's going to take a little bit more work for me.

@rogerwang
nwjs member

hello, we don't support python directly in the DOM.

@rogerwang rogerwang closed this May 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment