Commit ec254090 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot

Merge topic '18127-python-trace-has-duplicate-entries'

c13bc362 fixes duplicate trace items in Python traces.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !2944
parents 4444c571 c13bc362
Pipeline #126296 failed with stage
in 0 seconds
......@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkPVXMLElement.h"
#include "vtkSMProperty.h"
#include "vtkSMProxyListDomain.h"
#include "vtkSMTrace.h"
#include "vtkSmartPointer.h"
#include "vtkWeakPointer.h"
......@@ -187,11 +188,14 @@ void pqProxySelectionWidget::currentIndexChanged(int idx)
//-----------------------------------------------------------------------------
void pqProxySelectionWidget::apply()
{
if (this->Internal->ProxyWidget)
this->Superclass::apply();
if (auto nestedWidget = this->Internal->ProxyWidget)
{
this->Internal->ProxyWidget->apply();
// we need to block tracing since the "nested proxy" will indeed get traced
// by the parent proxy. See #18127.
SM_SCOPED_TRACE(BlockTraceItems);
nestedWidget->apply();
}
this->Superclass::apply();
}
//-----------------------------------------------------------------------------
......
......@@ -902,6 +902,14 @@ class CleanupAccessor(BookkeepingItem):
import gc
gc.collect()
class BlockTraceItems(NestableTraceItem):
"""Item to block further creation of trace items, even
those that are `NestableTraceItem`. Simply create this and
no trace items will be created by `_create_trace_item_internal`
until this instance is cleaned up.
"""
pass
class PropertiesModified(NestableTraceItem):
"""Traces properties modified on a specific proxy."""
def __init__(self, proxy, comment=None):
......@@ -1488,7 +1496,11 @@ def _create_trace_item_internal(key, args=None, kwargs=None):
args = args if args else []
kwargs = kwargs if kwargs else {}
traceitemtype = g[key]
if len(__ActiveTraceItems) == 0 or issubclass(traceitemtype, NestableTraceItem):
if len(__ActiveTraceItems) == 0 or \
issubclass(traceitemtype, NestableTraceItem):
if len(__ActiveTraceItems) > 0 and \
isinstance(__ActiveTraceItems[-1](), BlockTraceItems):
raise Untraceable("Not tracing since `BlockTraceItems` is active.")
instance = traceitemtype(*args, **kwargs)
if not issubclass(traceitemtype, BookkeepingItem):
__ActiveTraceItems.append(weakref.ref(instance))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment