简体   繁体   English

Spotfire中的列表框过滤器的铁python脚本

[英]iron python script for List box filter in spotfire

I have a script like below - 我有一个如下的脚本-

from Spotfire.Dxp.Application import Filters as filters
import Spotfire.Dxp.Application.Filters.ListBoxFilter
from Spotfire.Dxp.Application.Filters import FilterTypeIdentifiers
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Filters import *

CurPanel = Document.ActivePageReference.FilterPanel
FilterA = CurPanel.TableGroups[1].GetFilter("column_name1")
CheckBoxesA = FilterA.FilterReference.As[filters.ListBoxFilter]()
FilterB = CurPanel.TableGroups[0].GetFilter("column_name2")
CheckBoxesB = FilterB.FilterReference.As[filters.CheckBoxFilter]()
print "success1"
for CheckBoxVal in CheckBoxesB.Values: CheckBoxesB.Uncheck(CheckBoxVal)
   print "success2"
str = CheckBoxesA.ToString()
found, nodes = myTable.Columns ["column_name2"].Hierarchy.Levels.LeafLevel.TryGetNodes(int.MaxValue)
for node in nodes:
   if str.Contains("All"): CheckBoxesB.check(node.Value.ValidValue)
   if str.Contains(node.Value.ValidValue): CheckBoxesB.check(node.Value.ValidValue)

This works completely fine when I use CheckBoxFilter in line 10. But for the values more than 100, as spotfire automatically considers list box filter, I should modify the line 10 as below - 当我在第10行中使用CheckBoxFilter时,此方法完全可以正常工作。但是对于大于100的值,由于Spotfire会自动考虑列表框过滤器,因此我应该如下修改第10行-

CheckBoxesB = FilterB.FilterReference.As[filters.ListBoxFilter]()

Then I get the following error message - 然后我收到以下错误消息-

success1 Traceback (most recent call last): File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging File "", line 16, in AttributeError: 'ListBoxFilter' object has no attribute 'Values' success1追溯(最近一次呼叫最近):文件“ Spotfire.Dxp.Application.ScriptSupport”,行不明,在ExecuteForDebugging文件“”行,第16行,AttributeError:'ListBoxFilter'对象没有属性'Values'

System.MissingMemberException: 'ListBoxFilter' object has no attribute 'Values' at stub $619##619(Closure , CallSite , Object , CodeContext ) at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func4 target, CallSite site, Object[] args) at Microsoft.Scripting.Actions.CallSite1.UpdateAndExecute(Object[] args) at Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at $606##606(Closure , Scope , LanguageContext ) at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary2 scope, Stream outputStream) System.MissingMemberException:'ListBoxFilter'对象在存根 $ 619 ## 619(Closure,CallSite,Object,CodeContext)处没有属性'Values'在Microsoft.Scripting.Actions.MatchCaller.Call2 [T0,T1,TRet](Func4 target, CallSite网站,位于Microsoft.Scripting.Actions.CallSite1.UpdateAndExecute(Object [] args),位于Microsoft.Scripting.Actions.UpdateDelegates.Update2 [T,T0,T1,TRet](CallSite网站,T0 arg0, T1 arg1)$ 606 ## 606(Closure,Scope,LanguageContext)在Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode,Dictionary2 scope,Stream outputStream)

I understand issue with uncheck and check functions used in lines 12 and last two lines. 我了解第12行和最后两行中使用的uncheck和check函数的问题。 Is there any equivalent function to be used for list box filter ? 列表框过滤器是否有等效功能?

It doesn't look like there's an exact equivalent, but there are a couple ways you could do this. 看起来并没有完全相同的方法,但是有几种方法可以实现。

First, there is a method IsSelected, where you could determine if All is selected or not, and reset the filter accordingly. 首先,有一个IsSelected方法,您可以在其中确定是否选择了All,然后相应地重置过滤器。

if CheckBoxesB.IsSelected('All') ==  True:
  CheckBoxesA.Reset()

You can set the values if needed using a string list, as shown here: http://spotfired.blogspot.com/2014/03/change-filters-programatically-from.html 您可以根据需要使用字符串列表来设置值,如下所示: http : //spotfired.blogspot.com/2014/03/change-filters-programatically-from.html

If for whatever reason you actually need to get the specific values that have been selected from the filter, you can see them with this addition of this code: 如果出于某种原因您实际上需要从过滤器中获取已选择的特定值,则可以通过添加以下代码来查看它们:

CurPanel.InteractiveSearchPattern = "status:m"
for filters in CurPanel.FiltersMatchingSearchPattern:
    ##Optional Table name to find column in specific table
    #if str(filters.ParentGroup) == "Table_Name":
    print filters.FilterReference.ToString()

Which displays the Filter Column name first, and then the selected values in a string list. 它首先显示“过滤器列”名称,然后显示字符串列表中的选定值。 You can adjust this accordingly. 您可以据此进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM