PDA

View Full Version : html/javascript page call python function



murali_mepath
2014-05-18, 21:59
hi,

I have a webview section into which is loaded a HTML page. I have a page where I have written some python functions. How do I call the python function that is in a particular page from the html/javascript page that is loaded into the webview? I have done this and it works:


Lianja.showDocument("python:resetidleflag()");

But it crashes Lianja if I repeat it a few times. Lianja.execute works without crashing but I can use that to only call VFP functions and not python functions. And do I need to prefix the function name with the page name or something? But strange it does execute, except that after I call it a few times it crashes Lianja.

In short is there another way of executing a python function which is in one of the pages from javascript, by using something other than showDocument?

The best way to replicate this would be to call(from Lianja/VFP or javascript) a python function repeatedly from the console, using Lianja.showDocument("python:mypyfunc"). The first time it will execute, subsequently it will freeze/hang.

Cheers,
M&M

barrymavin
2014-05-19, 06:41
Hi Murali,

Python (as well as PHP and JavaScript) functions are global in the App. They are not page specific.

You can also call execPython(), execPHP() and execJavaScript() to load and execute external script files.

if you want to report a bug then please submit a ticket on Lianja.com rather than notify us on the forums so that we can schedule to look into it. It also depends on what your Python function is doing. If it's messing about with threads or similar you may be interfering with the main GUI thread.

murali_mepath
2014-05-22, 18:24
Hi Barry,

Thanks for the information. I figured out what causes the crash. Later I will post on what actually was the culprit. I need to get some sleep first :-D

Cheers,
Murali

hmischel@diligentsystems.com
2016-09-09, 16:20
Hi Barry,

I have a file in my application called convert.py.

I would like to call it from a Custom VFP section.

I have tried execPython("convert.py"), but that is not calling it.

Is there something else I need to do call the py file?

Thanks.

Herb

barrymavin
2016-09-09, 17:15
Hi Herb,

Lianja.evaluate("execPython('file.py')")

HankFay
2016-09-09, 21:11
Hi Barry,

So if Herb was in a prg, execPython() by itself would work, but not from a Custom Section? Trying to get my head around this (although I have no urge to build a custom section <s>).

Hank

barrymavin
2016-09-09, 22:34
Oh sorry herb, I misread the question. From a custom VFP section execPython() should just work. Does it work from the console?

hmischel@diligentsystems.com
2016-09-11, 15:08
Hi Barry,

Yes - once I loaded the file using loadlibrary(), all of my python functions are working using execPython("functionName()").

Thanks.

Herb