X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/248834a066bf167b0496161f47ad8ca07a1cada6..52df3d15d8df4bdd1efa308aaf7b0f1b7d2c82f8:/wxPython/samples/embedded/embedded.cpp diff --git a/wxPython/samples/embedded/embedded.cpp b/wxPython/samples/embedded/embedded.cpp index 36ccdefc79..44ec367059 100644 --- a/wxPython/samples/embedded/embedded.cpp +++ b/wxPython/samples/embedded/embedded.cpp @@ -41,8 +41,6 @@ public: virtual bool OnInit(); virtual ~MyApp(); void Init_wxPython(); -private: - PyThreadState* main_tstate; }; @@ -83,16 +81,22 @@ void MyApp::Init_wxPython() // module and sets a pointer to a function table located there. wxPyCoreAPI_IMPORT(); + // Ensure that the new classes defined in the wxPython wrappers are + // recognised by the wx RTTI system. (If you don't use wxWindows in + // your C++ app you won't need to do this.) + wxClassInfo::CleanUpClasses(); + wxClassInfo::InitializeClasses(); + // Save the current Python thread state and release the // Global Interpreter Lock. - main_tstate = wxPyBeginAllowThreads(); + wxPyBeginAllowThreads(); } MyApp::~MyApp() { // Restore the thread state and tell Python to cleanup after itself. - wxPyEndAllowThreads(main_tstate); + wxPyEndAllowThreads(true); Py_Finalize(); } @@ -170,13 +174,13 @@ void MyFrame::OnPyFrame(wxCommandEvent& event) // First, whenever you do anyting with Python objects or code, you // *MUST* aquire the Global Interpreter Lock and block other // Python threads from running. - wxPyBeginBlockThreads(); + bool blocked = wxPyBeginBlockThreads(); // Execute the code in the __main__ module PyRun_SimpleString(python_code1); // Finally, release the GIL and let other Python threads run. - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); } @@ -191,9 +195,9 @@ from wxPython.wx import wxPyOnDemandOutputWindow\n\ output = wxPyOnDemandOutputWindow()\n\ sys.stdin = sys.stderr = output\n\ "; - wxPyBeginBlockThreads(); + bool blocked = wxPyBeginBlockThreads(); PyRun_SimpleString(python_redirect); - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); } @@ -212,7 +216,7 @@ wxWindow* MyFrame::DoPythonStuff(wxWindow* parent) // More complex embedded situations will require passing C++ objects to // Python and/or returning objects from Python to be used in C++. This // sample shows one way to do it. NOTE: The above code could just have - // easily come from a file, or the whole thing coupld be in the Python + // easily come from a file, or the whole thing could be in the Python // module that is imported and manipulated directly in this C++ code. See // the Python API for more details. @@ -220,7 +224,7 @@ wxWindow* MyFrame::DoPythonStuff(wxWindow* parent) PyObject* result; // As always, first grab the GIL - wxPyBeginBlockThreads(); + bool blocked = wxPyBeginBlockThreads(); // Now make a dictionary to serve as the global namespace when the code is // executed. Put a reference to the builtins module in it. (Yes, the @@ -271,7 +275,7 @@ wxWindow* MyFrame::DoPythonStuff(wxWindow* parent) Py_DECREF(tuple); // Finally, after all Python stuff is done, release the GIL - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); return window; }