Add a delayed callback helper for python

This commit is contained in:
baldurk
2025-09-08 17:29:27 +01:00
parent b3cec5a4cf
commit b4615dbd18
5 changed files with 22 additions and 0 deletions
+2
View File
@@ -100,6 +100,8 @@ def make_c_type(ret: str, pattern: bool, typelist: List[str]):
ret = 'rdcstrpairs'
elif ret == 'Tuple[str,str]': # special case
ret = 'rdcstrpair'
elif ret == 'Callable[[], None]': # callbacks with parameters or return type should have a *Callback typedef
ret = 'std::function<void\(\)>' if pattern else 'std::function'
elif ret[0:5] == 'List[':
inner = make_c_type(ret[5:-1], pattern, typelist)
ret = '(const )?rdcarray<{}> ?[&*]?'.format(inner) if pattern else 'rdcarray<{}>'.format(inner)
+5
View File
@@ -1799,6 +1799,11 @@ void CaptureContext::RemoveBookmark(uint32_t EID)
RefreshUIStatus({}, true, true);
}
void CaptureContext::DelayedCallback(uint32_t milliseconds, std::function<void()> callback)
{
QTimer::singleShot(milliseconds, callback);
}
void CaptureContext::SetModification(CaptureModifications mod)
{
m_CaptureMods |= mod;
+2
View File
@@ -205,6 +205,8 @@ public:
void SetBookmark(const EventBookmark &mark) override;
void RemoveBookmark(uint32_t EID) override;
void DelayedCallback(uint32_t milliseconds, std::function<void()> callback) override;
IMainWindow *GetMainWindow() override;
IEventBrowser *GetEventBrowser() override;
IAPIInspector *GetAPIInspector() override;
+8
View File
@@ -2390,6 +2390,14 @@ If no bookmark exists, this function will do nothing.
)");
virtual void RemoveBookmark(uint32_t eventId) = 0;
DOCUMENT(R"(Registers a delayed callback to be called after a certain number of milliseconds
on the UI thread.
:param int milliseconds: The number of milliseconds (approximately) to wait before the callback.
:param Callable[[], None] callback: The function to call
)");
virtual void DelayedCallback(uint32_t milliseconds, std::function<void()> callback) = 0;
DOCUMENT(R"(Retrieve the current singleton :class:`MainWindow`.
:return: The current window.
+5
View File
@@ -629,6 +629,7 @@ struct CaptureContextInvoker : ObjectForwarder<ICaptureContext>
{
InvokeVoidFunction(&ICaptureContext::AddMessages, msgs);
}
virtual void ClearMessages() override { InvokeVoidFunction(&ICaptureContext::ClearMessages); }
virtual void SetResourceCustomName(ResourceId id, const rdcstr &name) override
{
InvokeVoidFunction(&ICaptureContext::SetResourceCustomName, id, name);
@@ -646,6 +647,10 @@ struct CaptureContextInvoker : ObjectForwarder<ICaptureContext>
{
InvokeVoidFunction(&ICaptureContext::RemoveBookmark, EID);
}
virtual void DelayedCallback(uint32_t milliseconds, std::function<void()> callback) override
{
InvokeVoidFunction(&ICaptureContext::DelayedCallback, milliseconds, callback);
}
virtual IMainWindow *GetMainWindow() override
{
return InvokeRetFunction<IMainWindow *>(&ICaptureContext::GetMainWindow);