B4J Question <solved> [PyBridge] Only in UI apps?

Daestrum

Expert
Licensed User
Longtime User
Does PyBridge only work in UI apps, can't seem to get it to work in a non-UI app. ( I probably missed Erel stating it somewhere )
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
No. You probably haven't called StartMessageLoop.

Template for console apps:
B4X:
Sub Process_Globals
    Private py As PyBridge
End Sub

Sub AppStart (Args() As String)
    Start
    StartMessageLoop
End Sub

Private Sub Start
    py.Initialize(Me, "py")
    Dim opt As PyOptions = py.CreateOptions("Python/python/python.exe")
    py.Start(opt)
    Wait For Py_Connected (Success As Boolean)
    If Success = False Then
        LogError("Failed to start Python process.")
        ExitApplication
    End If
    Dim np As PyWrapper = py.ImportModule("numpy")
    Dim arr As PyWrapper = np.GetField("random").Run("rand").Arg(3).Arg(4)
    arr.Print
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
working now - thank you.
 
Upvote 0
Top