I made a wxPython gui to interact with a camera, however the lab is very matlab centric and the professor wants everything to be controllable from matlab.
I think this is more of a matlab problem, but it's python related and I thought it might be a little odd to go to a matlab forum to ask questions about what I can do to use matlab as little as possible. Actually it might be an issue with c, although I'm heavily embedding python in c...anyway, I'm sorry if this isn't the place to ask.
I can embed python into a c file, have matlab compile a mex file from it, and load a module then call a non graphical python function from it just fine. In my case I can write hello world to a file. However when I try to use wxPython in the python function matlab just crashes the moment I call the mex file. This is the code I used
mat_function.c
#include <Python.h>
#include <mex.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[])
{
PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
Py_Initialize();
pName = PyString_FromString("py_function");
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\"/home/jarl/embed_python/\")");
pModule = PyImport_Import(pName);
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, "run");
if (PyCallable_Check(pFunc))
{
PyObject_CallObject(pFunc, NULL);
} else
{
PyErr_Print();
}
Py_DECREF(pModule);
Py_DECREF(pName);
Py_Finalize();
}
py_function.py
import wx
def run():
app = wx.App()
frame = wx.Frame(None, -1, 'simple.py')
frame.Show()
app.MainLoop()