Jump to content
We've recently updated our Privacy Statement, available here. ×

Ironpython for creating filtering relationships between tables: please help making my code more pythonic.


K Rojas

Recommended Posts

Hello,

I am using the code below to pass filter selections from table A to table B in Spotfire. I am doing this to create a filtering relationship between the tables, but skipping the creation of a traditional Spotfire table relationship, as this is not advisable in this setting.

The code is associated with a document property which itself is driven by a simple data function, following the instructions foundhere.

After it is triggered, the code finds a specific filter in table A. It reads the content and creates a list. It checks the length of the list, and if greater than zero, it takes the filter object and passes it to the matching filter in table B. If nothing is selected (len = 0), then the matching filter in table B is reset. The process is repeated for multiple filters.

As far as I can tell it works on my machine. But even as a complete beginner, I can tell it is poorly written. I would appreciate suggestions and feedback on how I can make it better.

Full disclosure: I have also asked this question here, but I haven't gotten much traction. I understand using ironpython within Spotfire is pretty specialized.

from Spotfire.Dxp.Application.Filters import *

from Spotfire.Dxp.Application.Visuals import VisualContent

from System import Guid

 

#Get the active page and filterPanel

page = Application.Document.ActivePageReference

filterPanel = page.FilterPanel

 

##########################reasons#############################################

#get information for the first filter

theFilter = filterPanel.TableGroups[0].GetFilter("Reason")

lbFilter = theFilter.FilterReference.As[ListBoxFilter]()

#get information for the second filter

theFilter2 = filterPanel.TableGroups[1].GetFilter("Reason")

lb2Filter = theFilter2.FilterReference.As[ListBoxFilter]()

 

#check if any selections are made in the first filter

n = []

for value in lbFilter.SelectedValues:

n.append(value)

if len(n)>0:

lb2Filter.IncludeAllValues = False

lb2Filter.SetSelection(lbFilter.SelectedValues)

#if no selections are made, reset the second filter

else:

lb2Filter.Reset()

 

#########################Type#####################################################

theFilterPT = filterPanel.TableGroups[0].GetFilter("Type")

lbFilterPT = theFilterPT.FilterReference.As[ListBoxFilter]()

 

theFilter2PT = filterPanel.TableGroups[1].GetFilter("Type")

lb2FilterPT = theFilter2PT.FilterReference.As[ListBoxFilter]()

 

n = []

for value in lbFilterPT.SelectedValues:

n.append(value)

if len(n)>0:

lb2FilterPT.IncludeAllValues = False

lb2FilterPT.SetSelection(lbFilterPT.SelectedValues)

else:

lb2FilterPT.Reset()

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...