My true motivation is to add a background color to the colorbar widget (when the rendered objects are messy and make the colorbar widget text/colors hard to see). The pyvista package seems to do it directly with vtkScalarBarActor
's GetBackgroundProperty
method. But these are not exposed to ParaView GUI or Python.
Example (after creating a sphere source):
from paraview.simple import *
from paraview import servermanager as sm
lut = GetColorTransferFunction('Normals')
renderView1 = GetActiveViewOrCreate('RenderView')
cbar_widget_repr = GetScalarBar(lut, renderView1)
# <paraview.servermanager.ScalarBarWidgetRepresentation object at 0x7f19c3b0ecd0>
# (paraview.modules.vtkRemotingViews.vtkSMScalarBarWidgetRepresentationProxy)0x7f1a25b017c0
cbar_widget_repr_proxy = cbar_widget_repr.SMProxy
# Following lines give errors like "no attribute 'GetNumberOfOutputPorts'"
sm.Fetch(cbar_widget_repr)
sm.Fetch(cbar_widget_repr_proxy)
sm.Fetch(cbar_widget_repr_proxy.GetRepresentationProxy().GetProperty('ScalarBarActor'))
Update 1:
Now I do get the vtkScalarBarActor
and can have full control of it. But the draw background still does not show up:
repr_proxy = cbar_widget_repr_proxy.GetRepresentationProxy()
actor_as_proxy_prop = repr_proxy.GetProperty('ScalarBarActor')
# paraview.modules.vtkRemotingViews.vtkContext2DScalarBarActor object!
actor = actor_as_proxy_prop.GetProxy(0).GetClientSideObject()
# vtkProperty2D object!
actor_background_props = actor.GetBackgroundProperty()
# following changes do NOT seem to change the colorbar background
actor_background_props.SetColor(0, 1, 0)
actor_background_props.SetOpacity(1)
actor.DrawBackgroundOn()
## following changes do NOT seem to show a frame
actor.DrawFrameOn()
# following title text property changes work
text_props = actor.GetTitleTextProperty()
text_props.SetBackgroundOpacity(1)
text_props.SetBackgroundColor(0.5,0.5,0.5)
text_props.SetFrame(True)
# following label text property changes work
label_props = actor.GetLabelTextProperty()
label_props.SetBackgroundColor(0.8,0.8,1)
label_props.SetBackgroundOpacity(1)