embedding a GUI in a C code

Hi guys,
I wanted to call from C++ a GUI.

I have a py script that I can call from C.
In the script I defined a class that I can instantiate from C.
I can call a method of the class that can start the wxApp,that in turn
open a frame.
Here is a snippet of the C code

    pModule = PyImport_Import(ModuleName);//import the module
    pDict = PyModule_GetDict(pModule);//import the __dict__ of the
module, i.e.the module’s symbol table
    pClass = PyDict_GetItemString(pDict, class_name);//retrieve the
class from the module

    // --Create an instance of the class
    if (PyCallable_Check(pClass))
    {
        pInstance = PyObject_CallObject(pClass, NULL); //
    }
    //call the method that will run the application
    printf("Call the method1\n");
    pValue = PyObject_CallMethod(pInstance, method_name, NULL);

What I would like to do, and I can not figure out how can I do it, is
to modify the frame from C on the run.I cannot do this because once
the wxApp starts,it takes control and until the Frame is open C does
not execute any other instruction.

Any idea is very wellcome!

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

If your C++ application is using wxWidgets then it should be the one to create the app and run the main loop, not the Python code. Otherwise there are a couple approaches you could take.

1. Periodically (such as from a timer) call from Python to some C++ function that has been exposed to Python like in an extension module. That function can then do whatever is needed on the C++ side and when it returns the wxPython code will be in control again (and running in the event loop again.)

2. Run the wxPython code in another thread. This way MainLoop will not block C++ code in the main thread from continuing. Normal multi-thread issues will need to be dealt with however. For example, you should not call any GUI methods directly from the main C++ thread. Instead you can use wx.CallAfter to redirect the call to the GUI thread, something like this:

  def doSomething(self, arg1, arg2):
    wx.CallAfter(self.reallyDoSomething, arg1, arg2)

Then you can call doSomething from your C++ code and it will then send an event to the GUI thread which will cause it to call reallyDoSomething from there when the event is processed.

···

On 4/29/10 7:47 AM, tinauser wrote:

Hi guys,
I wanted to call from C++ a GUI.

I have a py script that I can call from C.
In the script I defined a class that I can instantiate from C.
I can call a method of the class that can start the wxApp,that in turn
open a frame.
Here is a snippet of the C code

     pModule = PyImport_Import(ModuleName);//import the module
     pDict = PyModule_GetDict(pModule);//import the __dict__ of the
module, i.e.the module’s symbol table
     pClass = PyDict_GetItemString(pDict, class_name);//retrieve the
class from the module

     // --Create an instance of the class
     if (PyCallable_Check(pClass))
     {
         pInstance = PyObject_CallObject(pClass, NULL); //
     }
     //call the method that will run the application
     printf("Call the method1\n");
     pValue = PyObject_CallMethod(pInstance, method_name, NULL);

What I would like to do, and I can not figure out how can I do it, is
to modify the frame from C on the run.I cannot do this because once
the wxApp starts,it takes control and until the Frame is open C does
not execute any other instruction.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en