diff --git a/qrenderdoc/Code/CaptureContext.cpp b/qrenderdoc/Code/CaptureContext.cpp index 2a5c5fd36..53287851b 100644 --- a/qrenderdoc/Code/CaptureContext.cpp +++ b/qrenderdoc/Code/CaptureContext.cpp @@ -93,6 +93,8 @@ CaptureContext::CaptureContext(PersistentConfig &cfg) : m_Config(cfg) qApp->setApplicationVersion(QString::fromLatin1(RENDERDOC_GetVersionString())); + PythonContext::setCtxGlobal(*this); + m_Icon = new QIcon(); m_Icon->addFile(QStringLiteral(":/logo.svg"), QSize(), QIcon::Normal, QIcon::Off); @@ -614,7 +616,9 @@ void CaptureContext::RegisterWindowMenu(WindowMenu base, const rdcarray return; } - std::function slotcallback = [this, callback]() { callback(this, {}); }; + std::function slotcallback = [this, callback]() { + callback(PythonContext::GetExtensionPyrenderdoc(), {}); + }; // if it's a new menu, GetBaseMenu already did the work, so skip the 0th element of submenus if(base == WindowMenu::NewMenu) @@ -691,7 +695,7 @@ void CaptureContext::MenuDisplaying(ContextMenu contextMenu, QMenu *menu, PythonContext::ConvertPyArgs(data, args); - item->callback(this, args); + item->callback(PythonContext::GetExtensionPyrenderdoc(), args); PythonContext::FreePyArgs(args); }); @@ -711,7 +715,7 @@ void CaptureContext::MenuDisplaying(PanelMenu panelMenu, QMenu *menu, QWidget *e PythonContext::ConvertPyArgs(data, args); - item->callback(this, args); + item->callback(PythonContext::GetExtensionPyrenderdoc(), args); PythonContext::FreePyArgs(args); }); diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index f81b63c98..6c5def58b 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -148,11 +148,17 @@ PyObject *PythonContext::main_dict = NULL; PyObject *PythonContext::m_DebugPy = NULL; PyObject *PythonContext::m_CallWrapper = NULL; PyObject *PythonContext::m_Reflector = NULL; +PyObject *PythonContext::m_pyrenderdoc = NULL; +ICaptureContext *PythonContext::m_CtxWrapper = NULL; QAtomicInt PythonContext::m_DeferredInit = 0; PyObject *PythonContext::m_CallWrapperGlobals = NULL; PythonContext *PythonContext::m_ExtensionContext = NULL; QMap PythonContext::extensions; +// defined in PythonInvokers.cpp +ICaptureContext *MakeCaptureContextInvoker(ICaptureContext &ctx); +void FreeCaptureContextInvoker(ICaptureContext *ctx); + static PyObject *current_global_handle = NULL; static QMutex decrefQueueMutex; @@ -1002,6 +1008,18 @@ except: m_ExtensionContext = new PythonContext(true, NULL); } +void PythonContext::setCtxGlobal(ICaptureContext &ctx) +{ + m_CtxWrapper = MakeCaptureContextInvoker(ctx); + + PyGILState_STATE gil = PyGILState_Ensure(); + + m_pyrenderdoc = + PassObjectToPython((rdcstr(TypeName()) + " *").c_str(), m_CtxWrapper); + + PyGILState_Release(gil); +} + bool PythonContext::initialised() { return main_dict != NULL; @@ -1035,6 +1053,11 @@ PythonContext::PythonContext(bool extensionContext, QObject *parent) : QObject(p Py_XDECREF(redirector); } + if(m_pyrenderdoc) + { + PyDict_SetItemString(context_namespace, "pyrenderdoc", m_pyrenderdoc); + } + // release the GIL again PyGILState_Release(gil); @@ -1121,15 +1144,14 @@ void PythonContext::Finish() PyGILState_Release(gil); } -void PythonContext::PausePythonThreading() +void *PythonContext::PausePythonThreading() { - m_SavedThread = PyEval_SaveThread(); + return PyEval_SaveThread(); } -void PythonContext::ResumePythonThreading() +void PythonContext::ResumePythonThreading(void *ctx) { - PyEval_RestoreThread((PyThreadState *)m_SavedThread); - m_SavedThread = NULL; + PyEval_RestoreThread((PyThreadState *)ctx); } void PythonContext::GlobalShutdown() @@ -1148,6 +1170,8 @@ void PythonContext::GlobalShutdown() PyGILState_Ensure(); Py_Finalize(); + + FreeCaptureContextInvoker(m_CtxWrapper); } QStringList PythonContext::GetApplicationExtensionsPaths() @@ -1300,7 +1324,8 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi ext = PyImport_ReloadModule(extensions[extension]); } - PyObject *pyctx = PassObjectToPython((rdcstr(TypeName()) + " *").c_str(), &ctx); + if(!m_pyrenderdoc) + qCritical() << "pyrenderdoc variable is NULL"; // if import succeeded, store this extension module in our map. If import failed, we might have // failed a reimport in which case the original module is still there and valid, so don't @@ -1323,13 +1348,13 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi PyModule_AddObject(ext, "_renderdoc_internal", ext_context); - Py_XINCREF(pyctx); + Py_XINCREF(m_pyrenderdoc); - int pyret = PyModule_AddObject(ext, "pyrenderdoc", pyctx); + int pyret = PyModule_AddObject(ext, "pyrenderdoc", m_pyrenderdoc); if(pyret != 0) { - Py_XDECREF(pyctx); + Py_XDECREF(m_pyrenderdoc); qCritical() << "Couldn't set pyrenderdoc global in loaded module"; ret += tr("Couldn't set pyrenderdoc global in loaded module\n"); @@ -1347,9 +1372,10 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi if(register_func) { PyObject *retval = NULL; - if(pyctx) + if(m_pyrenderdoc) { - retval = PyObject_CallFunction(register_func, "sO", MAJOR_MINOR_VERSION_STRING, pyctx); + retval = + PyObject_CallFunction(register_func, "sO", MAJOR_MINOR_VERSION_STRING, m_pyrenderdoc); } else { @@ -1380,7 +1406,7 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi ext = NULL; } - Py_XDECREF(pyctx); + Py_XDECREF(m_pyrenderdoc); if(ext) { diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.h b/qrenderdoc/Code/pyrenderdoc/PythonContext.h index a01f3690a..fbaa327e0 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.h +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.h @@ -59,10 +59,11 @@ public: void Finish(); PyThreadState *GetExecutingThreadState() { return m_State; } - void PausePythonThreading(); - void ResumePythonThreading(); + static void *PausePythonThreading(); + static void ResumePythonThreading(void *ctx); static void GlobalInit(PersistentConfig &config); + static void setCtxGlobal(ICaptureContext &ctx); static void GlobalShutdown(); static QStringList GetApplicationExtensionsPaths(); @@ -133,6 +134,8 @@ public: static void AddDebuggableThread(); static void RemoveDebuggableThread(); + // for extension callbacks we want to pass the python wrapper + static ICaptureContext *GetExtensionPyrenderdoc() { return m_CtxWrapper; } static PythonContext *GetExtensionContext() { return m_ExtensionContext; } signals: @@ -167,6 +170,10 @@ private: static PyObject *m_Reflector; static QAtomicInt m_DeferredInit; + // the pyrenderdoc wrapper around ICaptureContext + static PyObject *m_pyrenderdoc; + static ICaptureContext *m_CtxWrapper; + // a statically created PythonContext for extension events/output. // each extension has its own dictionary but this is used so that users can connect to it and receieve events static PythonContext *m_ExtensionContext; diff --git a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp index 48ba2b532..c5adacbc3 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp @@ -32,9 +32,9 @@ template struct UIThreadInvoker : Obj { - UIThreadInvoker(PythonShell *sh, Obj &o) : m_Shell(sh), m_Obj(o) {} + UIThreadInvoker(ICaptureContext &ctx, Obj &o) : m_Ctx(ctx), m_Obj(o) {} virtual ~UIThreadInvoker() {} - PythonShell *m_Shell; + ICaptureContext &m_Ctx; Obj &m_Obj; template @@ -42,12 +42,10 @@ struct UIThreadInvoker : Obj { if(!GUIInvoke::onUIThread()) { - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); - GUIInvoke::blockcall(m_Shell, [this, ptr, params...]() { (m_Obj.*ptr)(params...); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + void *ctx = PythonContext::PausePythonThreading(); + GUIInvoke::blockcall(m_Ctx.GetMainWindow()->Widget(), + [this, ptr, params...]() { (m_Obj.*ptr)(params...); }); + PythonContext::ResumePythonThreading(ctx); return; } @@ -60,13 +58,10 @@ struct UIThreadInvoker : Obj if(!GUIInvoke::onUIThread()) { R ret; - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); - GUIInvoke::blockcall(m_Shell, + void *ctx = PythonContext::PausePythonThreading(); + GUIInvoke::blockcall(m_Ctx.GetMainWindow()->Widget(), [this, &ret, ptr, params...]() { ret = (m_Obj.*ptr)(params...); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + PythonContext::ResumePythonThreading(ctx); return ret; } @@ -76,7 +71,7 @@ struct UIThreadInvoker : Obj struct MiniQtInvoker : UIThreadInvoker { - MiniQtInvoker(PythonShell *shell, IMiniQtHelper &obj) : UIThreadInvoker(shell, obj) {} + MiniQtInvoker(ICaptureContext &ctx, IMiniQtHelper &obj) : UIThreadInvoker(ctx, obj) {} virtual ~MiniQtInvoker() {} void InvokeOntoUIThread(std::function callback) { @@ -349,9 +344,9 @@ struct MiniQtInvoker : UIThreadInvoker struct ExtensionInvoker : UIThreadInvoker { MiniQtInvoker *m_MiniQt; - ExtensionInvoker(PythonShell *shell, IExtensionManager &obj) : UIThreadInvoker(shell, obj) + ExtensionInvoker(ICaptureContext &ctx, IExtensionManager &obj) : UIThreadInvoker(ctx, obj) { - m_MiniQt = new MiniQtInvoker(shell, obj.GetMiniQtHelper()); + m_MiniQt = new MiniQtInvoker(ctx, obj.GetMiniQtHelper()); } virtual ~ExtensionInvoker() { delete m_MiniQt; } // @@ -437,7 +432,7 @@ struct ExtensionInvoker : UIThreadInvoker struct ReplayControllerInvoker : IReplayController { - ReplayControllerInvoker(PythonShell *shell, ICaptureContext &ctx) : m_Shell(shell), m_Ctx(ctx) {} + ReplayControllerInvoker(ICaptureContext &ctx) : m_Ctx(ctx) {} virtual ~ReplayControllerInvoker() {} PythonShell *m_Shell; ICaptureContext &m_Ctx; @@ -445,26 +440,20 @@ struct ReplayControllerInvoker : IReplayController template void InvokeVoidFunction(F ptr, paramTypes... params) { - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); + void *ctx = PythonContext::PausePythonThreading(); m_Ctx.Replay().BlockInvoke( [ptr, params...](IReplayController *replay) { (replay->*ptr)(params...); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + PythonContext::ResumePythonThreading(ctx); } template R InvokeRetFunction(F ptr, paramTypes... params) { R ret = R(); - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); + void *ctx = PythonContext::PausePythonThreading(); m_Ctx.Replay().BlockInvoke( [&ret, ptr, params...](IReplayController *replay) { ret = (replay->*ptr)(params...); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + PythonContext::ResumePythonThreading(ctx); return ret; } @@ -472,13 +461,10 @@ struct ReplayControllerInvoker : IReplayController R &InvokeRetRefFunction(F ptr, paramTypes... params) { R *ret = NULL; - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); + void *ctx = PythonContext::PausePythonThreading(); m_Ctx.Replay().BlockInvoke( [&ret, ptr, params...](IReplayController *replay) { ret = &(replay->*ptr)(params...); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + PythonContext::ResumePythonThreading(ctx); return *ret; } @@ -798,7 +784,7 @@ struct ReplayControllerInvoker : IReplayController struct IMainWindowInvoker : UIThreadInvoker { - IMainWindowInvoker(PythonShell *shell, IMainWindow &obj) : UIThreadInvoker(shell, obj) {} + IMainWindowInvoker(ICaptureContext &ctx, IMainWindow &obj) : UIThreadInvoker(ctx, obj) {} virtual ~IMainWindowInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -815,7 +801,7 @@ struct IMainWindowInvoker : UIThreadInvoker struct IEventBrowserInvoker : UIThreadInvoker { - IEventBrowserInvoker(PythonShell *shell, IEventBrowser &obj) : UIThreadInvoker(shell, obj) {} + IEventBrowserInvoker(ICaptureContext &ctx, IEventBrowser &obj) : UIThreadInvoker(ctx, obj) {} virtual ~IEventBrowserInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -891,7 +877,7 @@ struct IEventBrowserInvoker : UIThreadInvoker struct IAPIInspectorInvoker : UIThreadInvoker { - IAPIInspectorInvoker(PythonShell *shell, IAPIInspector &obj) : UIThreadInvoker(shell, obj) {} + IAPIInspectorInvoker(ICaptureContext &ctx, IAPIInspector &obj) : UIThreadInvoker(ctx, obj) {} virtual ~IAPIInspectorInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -904,7 +890,7 @@ struct IAPIInspectorInvoker : UIThreadInvoker struct IAnnotationViewerInvoker : UIThreadInvoker { - IAnnotationViewerInvoker(PythonShell *shell, IAnnotationViewer &obj) : UIThreadInvoker(shell, obj) + IAnnotationViewerInvoker(ICaptureContext &ctx, IAnnotationViewer &obj) : UIThreadInvoker(ctx, obj) { } virtual ~IAnnotationViewerInvoker() {} @@ -919,7 +905,7 @@ struct IAnnotationViewerInvoker : UIThreadInvoker struct ITextureViewerInvoker : UIThreadInvoker { - ITextureViewerInvoker(PythonShell *shell, ITextureViewer &obj) : UIThreadInvoker(shell, obj) {} + ITextureViewerInvoker(ICaptureContext &ctx, ITextureViewer &obj) : UIThreadInvoker(ctx, obj) {} virtual ~ITextureViewerInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -995,7 +981,7 @@ struct ITextureViewerInvoker : UIThreadInvoker struct IBufferViewerInvoker : UIThreadInvoker { - IBufferViewerInvoker(PythonShell *shell, IBufferViewer &obj) : UIThreadInvoker(shell, obj) {} + IBufferViewerInvoker(ICaptureContext &ctx, IBufferViewer &obj) : UIThreadInvoker(ctx, obj) {} virtual ~IBufferViewerInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -1027,8 +1013,8 @@ struct IBufferViewerInvoker : UIThreadInvoker struct IPipelineStateViewerInvoker : UIThreadInvoker { - IPipelineStateViewerInvoker(PythonShell *shell, IPipelineStateViewer &obj) - : UIThreadInvoker(shell, obj) + IPipelineStateViewerInvoker(ICaptureContext &ctx, IPipelineStateViewer &obj) + : UIThreadInvoker(ctx, obj) { } virtual ~IPipelineStateViewerInvoker() {} @@ -1044,10 +1030,10 @@ struct IPipelineStateViewerInvoker : UIThreadInvoker } }; -struct ICaptureConnectionInvoker : UIThreadInvoker +struct ICaptureConnectionInvoker : public UIThreadInvoker { - ICaptureConnectionInvoker(PythonShell *shell, ICaptureConnection &obj) - : UIThreadInvoker(shell, obj) + ICaptureConnectionInvoker(ICaptureContext &ctx, ICaptureConnection &obj) + : UIThreadInvoker(ctx, obj) { // delete ourself when the connection dies obj.RegisterClosedCallback([this](ICaptureConnection *) { delete this; }); @@ -1109,13 +1095,13 @@ struct ICaptureConnectionInvoker : UIThreadInvoker if(!ret) return ret; - return new ICaptureConnectionInvoker(m_Shell, *ret); + return new ICaptureConnectionInvoker(m_Ctx, *ret); } }; struct ICaptureDialogInvoker : UIThreadInvoker { - ICaptureDialogInvoker(PythonShell *shell, ICaptureDialog &obj) : UIThreadInvoker(shell, obj) {} + ICaptureDialogInvoker(ICaptureContext &ctx, ICaptureDialog &obj) : UIThreadInvoker(ctx, obj) {} virtual ~ICaptureDialogInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -1155,7 +1141,7 @@ struct ICaptureDialogInvoker : UIThreadInvoker if(!ret) return ret; - return new ICaptureConnectionInvoker(m_Shell, *ret); + return new ICaptureConnectionInvoker(m_Ctx, *ret); } void LoadSettings(const rdcstr &filename) { @@ -1171,7 +1157,7 @@ struct ICaptureDialogInvoker : UIThreadInvoker struct IDebugMessageViewInvoker : UIThreadInvoker { - IDebugMessageViewInvoker(PythonShell *shell, IDebugMessageView &obj) : UIThreadInvoker(shell, obj) + IDebugMessageViewInvoker(ICaptureContext &ctx, IDebugMessageView &obj) : UIThreadInvoker(ctx, obj) { } virtual ~IDebugMessageViewInvoker() {} @@ -1181,8 +1167,8 @@ struct IDebugMessageViewInvoker : UIThreadInvoker struct IDiagnosticLogViewInvoker : UIThreadInvoker { - IDiagnosticLogViewInvoker(PythonShell *shell, IDiagnosticLogView &obj) - : UIThreadInvoker(shell, obj) + IDiagnosticLogViewInvoker(ICaptureContext &ctx, IDiagnosticLogView &obj) + : UIThreadInvoker(ctx, obj) { } virtual ~IDiagnosticLogViewInvoker() {} @@ -1192,7 +1178,7 @@ struct IDiagnosticLogViewInvoker : UIThreadInvoker struct ICommentViewInvoker : UIThreadInvoker { - ICommentViewInvoker(PythonShell *shell, ICommentView &obj) : UIThreadInvoker(shell, obj) {} + ICommentViewInvoker(ICaptureContext &ctx, ICommentView &obj) : UIThreadInvoker(ctx, obj) {} virtual ~ICommentViewInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -1205,8 +1191,8 @@ struct ICommentViewInvoker : UIThreadInvoker struct IPerformanceCounterViewerInvoker : UIThreadInvoker { - IPerformanceCounterViewerInvoker(PythonShell *shell, IPerformanceCounterViewer &obj) - : UIThreadInvoker(shell, obj) + IPerformanceCounterViewerInvoker(ICaptureContext &ctx, IPerformanceCounterViewer &obj) + : UIThreadInvoker(ctx, obj) { } virtual ~IPerformanceCounterViewerInvoker() {} @@ -1220,7 +1206,7 @@ struct IPerformanceCounterViewerInvoker : UIThreadInvoker { - IStatisticsViewerInvoker(PythonShell *shell, IStatisticsViewer &obj) : UIThreadInvoker(shell, obj) + IStatisticsViewerInvoker(ICaptureContext &ctx, IStatisticsViewer &obj) : UIThreadInvoker(ctx, obj) { } virtual ~IStatisticsViewerInvoker() {} @@ -1230,7 +1216,7 @@ struct IStatisticsViewerInvoker : UIThreadInvoker struct ITimelineBarInvoker : UIThreadInvoker { - ITimelineBarInvoker(PythonShell *shell, ITimelineBar &obj) : UIThreadInvoker(shell, obj) {} + ITimelineBarInvoker(ICaptureContext &ctx, ITimelineBar &obj) : UIThreadInvoker(ctx, obj) {} virtual ~ITimelineBarInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -1246,7 +1232,7 @@ struct ITimelineBarInvoker : UIThreadInvoker struct IPythonShellInvoker : UIThreadInvoker { - IPythonShellInvoker(PythonShell *shell, IPythonShell &obj) : UIThreadInvoker(shell, obj) {} + IPythonShellInvoker(ICaptureContext &ctx, IPythonShell &obj) : UIThreadInvoker(ctx, obj) {} virtual ~IPythonShellInvoker() {} QWidget *Widget() { return m_Obj.Widget(); } @@ -1278,8 +1264,8 @@ struct IPythonShellInvoker : UIThreadInvoker struct IResourceInspectorInvoker : UIThreadInvoker { - IResourceInspectorInvoker(PythonShell *shell, IResourceInspector &obj) - : UIThreadInvoker(shell, obj) + IResourceInspectorInvoker(ICaptureContext &ctx, IResourceInspector &obj) + : UIThreadInvoker(ctx, obj) { } virtual ~IResourceInspectorInvoker() {} @@ -1296,7 +1282,7 @@ struct IResourceInspectorInvoker : UIThreadInvoker } }; -struct CaptureContextInvoker : UIThreadInvoker +struct CaptureContextInvoker : public UIThreadInvoker { ExtensionInvoker *m_Ext; ReplayControllerInvoker m_ReplayController; @@ -1308,7 +1294,7 @@ struct CaptureContextInvoker : UIThreadInvoker if(!m_invoker##iface || &m_invoker##iface->m_Obj != i) \ { \ delete m_invoker##iface; \ - m_invoker##iface = new iface##Invoker(m_Shell, *i); \ + m_invoker##iface = new iface##Invoker(m_Ctx, *i); \ } \ return m_invoker##iface; \ } @@ -1330,10 +1316,9 @@ struct CaptureContextInvoker : UIThreadInvoker WINDOW_INVOKER(IPythonShell); WINDOW_INVOKER(IResourceInspector); - CaptureContextInvoker(PythonShell *shell, ICaptureContext &obj) - : UIThreadInvoker(shell, obj), m_ReplayController(shell, obj) + CaptureContextInvoker(ICaptureContext &ctx) : UIThreadInvoker(ctx, ctx), m_ReplayController(ctx) { - m_Ext = new ExtensionInvoker(shell, obj.Extensions()); + m_Ext = new ExtensionInvoker(ctx, ctx.Extensions()); } virtual ~CaptureContextInvoker() { delete m_Ext; } // @@ -1556,14 +1541,12 @@ struct CaptureContextInvoker : UIThreadInvoker { if(!GUIInvoke::onUIThread()) { - PythonContext *scriptContext = m_Shell->GetScriptContext(); - if(scriptContext) - scriptContext->PausePythonThreading(); - GUIInvoke::call(m_Shell, [this, milliseconds, callback]() { + IPythonShell *shell = m_Ctx.GetPythonShell(); + void *ctx = PythonContext::PausePythonThreading(); + GUIInvoke::call(m_Ctx.GetMainWindow()->Widget(), [this, milliseconds, callback]() { m_Obj.DelayedCallback(milliseconds, callback); }); - if(scriptContext) - scriptContext->ResumePythonThreading(); + PythonContext::ResumePythonThreading(ctx); return; } @@ -1831,9 +1814,9 @@ struct CaptureContextInvoker : UIThreadInvoker } }; -ICaptureContext *MakeCaptureContextInvoker(PythonShell *shell, ICaptureContext &ctx) +ICaptureContext *MakeCaptureContextInvoker(ICaptureContext &ctx) { - return new CaptureContextInvoker(shell, ctx); + return new CaptureContextInvoker(ctx); } void FreeCaptureContextInvoker(ICaptureContext *ctx) diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index b06178ffb..5058566f3 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -671,8 +671,6 @@ int main(int argc, char *argv[]) ANALYTIC_SET(UIFeatures.PythonInterop, true); - py.ctx().setGlobal("pyrenderdoc", (ICaptureContext *)&ctx); - QObject::connect(&py.ctx(), &PythonContext::exception, [&pythonExited](const QString &, const QString &type, const QString &value, int, QList frames) { diff --git a/qrenderdoc/Windows/PythonShell.cpp b/qrenderdoc/Windows/PythonShell.cpp index 7af65c10f..7e466ee9f 100644 --- a/qrenderdoc/Windows/PythonShell.cpp +++ b/qrenderdoc/Windows/PythonShell.cpp @@ -181,17 +181,11 @@ bool EditorWrapper::checkAllowClose() return true; } -// See PythonInvokers.cpp -ICaptureContext *MakeCaptureContextInvoker(PythonShell *shell, ICaptureContext &ctx); -void FreeCaptureContextInvoker(ICaptureContext *ctx); - PythonShell::PythonShell(ICaptureContext &ctx, QWidget *parent) : QFrame(parent), ui(new Ui::PythonShell), m_Ctx(ctx) { ui->setupUi(this); - m_ThreadCtx = MakeCaptureContextInvoker(this, m_Ctx); - QObject::connect(ui->lineInput, &RDLineEdit::keyPress, this, &PythonShell::interactive_keypress); QObject::connect(ui->helpSearch, &RDLineEdit::keyPress, this, &PythonShell::helpSearch_keypress); @@ -287,7 +281,6 @@ PythonShell::PythonShell(ICaptureContext &ctx, QWidget *parent) }); completionContext = new PythonContext(); - setGlobals(completionContext); // if we're help printing in the completion context, append it to the help text QObject::connect(completionContext, &PythonContext::textOutput, @@ -574,8 +567,6 @@ PythonShell::~PythonShell() completionContext->Finish(); interactiveContext->Finish(); - FreeCaptureContextInvoker(m_ThreadCtx); - delete ui; } @@ -2564,12 +2555,5 @@ PythonContext *PythonShell::newContext() QObject::connect(ret, &PythonContext::exception, this, &PythonShell::exception); QObject::connect(ret, &PythonContext::textOutput, this, &PythonShell::textOutput); - setGlobals(ret); - return ret; } - -void PythonShell::setGlobals(PythonContext *ret) -{ - ret->setGlobal("pyrenderdoc", m_ThreadCtx); -} diff --git a/qrenderdoc/Windows/PythonShell.h b/qrenderdoc/Windows/PythonShell.h index d366f7127..3239e96bf 100644 --- a/qrenderdoc/Windows/PythonShell.h +++ b/qrenderdoc/Windows/PythonShell.h @@ -168,7 +168,6 @@ private slots: private: Ui::PythonShell *ui; ICaptureContext &m_Ctx; - ICaptureContext *m_ThreadCtx = NULL; ScintillaEdit *runningScriptEditor = NULL; @@ -248,7 +247,6 @@ private: void updateScriptOutput(bool fullRefresh); PythonContext *newContext(); - void setGlobals(PythonContext *ret); void doAutocomplete(ScintillaEdit *editor); void doFunccomplete(ScintillaEdit *editor);