EXE.pythonEval: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
m Admin moved page EXE.execPython to EXE.pythonEval without leaving a redirect: Error in docs
No edit summary
Line 1: Line 1:
EXE.execPython(''code''[, ''callback''])
EXE.pythonEval(''code''[, ''callback''])


== Description ==
== Description ==


EXE.execPython executes code in the EXE runtime wrapper. It only works in EXE apps. AppStudio's EXE apps work by wrapping your app in a executable wrapper which is written in Python. This function requires you to know Python ti use it.
EXE.pythonEval executes code in the EXE runtime wrapper. It only works in EXE apps. AppStudio's EXE apps work by wrapping your app in a executable wrapper which is written in Python. This function requires you to know Python to use it.


Code has to be properly formatted Python code, following all Python syntax rules. In addition to the base Python language, the following libraries can be used:
Code has to be properly formatted Python code, following all Python syntax rules. In addition to the base Python language, the following libraries can be used:
Line 13: Line 13:
Other may be included in a future release.
Other may be included in a future release.


Calls to EXE.execPython are processed asynchronously. To return values, put {callback}(value) in your code, and supply the name of the function you want called as ''callback''.
Calls to EXE.pythonEval are processed asynchronously. To return values, put {callback}(value) in your code, and supply the name of the function you want called as ''callback''.


== Example (BASIC) ==
== Example (BASIC) ==

Revision as of 20:27, 10 August 2015

EXE.pythonEval(code[, callback])

Description

EXE.pythonEval executes code in the EXE runtime wrapper. It only works in EXE apps. AppStudio's EXE apps work by wrapping your app in a executable wrapper which is written in Python. This function requires you to know Python to use it.

Code has to be properly formatted Python code, following all Python syntax rules. In addition to the base Python language, the following libraries can be used:

  • os
  • wx
  • jason
  • yaml

Other may be included in a future release.

Calls to EXE.pythonEval are processed asynchronously. To return values, put {callback}(value) in your code, and supply the name of the function you want called as callback.

Example (BASIC)

Do a simple calculation and return the result

EXE.pythonEval("{callback}(4*4)", "showResult")

Function showResult(res)
  MsgBox res
End Function

Example (JavaScript)

EXE.pythonEval("{callback}(4*4)", "showResult");

function showResult(res) {
    NSB.MsgBox(res);
}

Other examples

Exit the app

EXE.pythonEval("sys.exit(0)")

Put up a wx Message Box:

EXE.pythonEval("wx.MessageBox('It works!', 'Info', wx.OK | wx.ICON_INFORMATION)", "MessageBox")

Run a code snippet

Put the following code into a TextArea:

# Code must be in Python.
# note how to return results.
a=64
{callback}(a*a)

And execute it as follows:

EXE.pythonEval(TextArea1.value, "showResult")

Output

Related Items