You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用IronPython为Spotfire图形表格的图标添加点击动作?

How to Bind Click Actions to Icon Columns in Spotfire GraphicalTable via IronPython

Hey there, I’ve run into the exact same issue before! Spotfire’s public API doesn’t explicitly document how to add click actions to IconMiniatureVisualization columns in a GraphicalTable, but you can absolutely do this by leveraging the inherited Actions property from the base Visualization class.

Here’s how to modify your existing code to add a click action to the icon column:

First, you’ll need to import a couple more namespaces to access the action and trigger classes:

from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Application.Visuals.Miniatures import *
from System.Drawing import Color
# Add these imports for action handling
from Spotfire.Dxp.Application.Actions import *
from Spotfire.Dxp.Application.Visuals.Interactive import *

Then, after configuring your icon column, add the click action logic. I’ll use a simple message box as an example—you can replace the script content with whatever functionality you need:

for vis in Document.ActivePageReference.Visuals:
    if vis.Title == 'Selected Period':
        viz = vis.As[GraphicalTable]()
        # Remove all columns:
        for c in viz.Columns:
            viz.Columns.Remove(c)
        # Add Icon Column
        (status, NewColumn) = viz.Columns.AddNew[IconMiniatureVisualization]()
        NewColumn.AutoConfigure()
        NewColumn.Title = 'Icon'
        NewColumn.IconAxis.Rules.Clear()
        NewColumn.IconAxis.Rules.AddExpressionRule("1=1", Color.FromName("Green"), MarkerShape(MarkerType.Plus))
        
        # ------------------- Add Click Action Here -------------------
        # Define the script that runs when the icon is clicked
        click_action_script = """
from System.Windows.Forms import MessageBox
# Replace this with your custom logic
MessageBox.Show("Icon in Selected Period table was clicked!")
"""
        
        # Create a visualization action with your script
        icon_click_action = VisualizationAction(click_action_script, "Icon Click Handler")
        # Set the trigger to left mouse click
        icon_click_action.Trigger = MouseClickTrigger(MouseButton.Left)
        
        # Add the action to the icon column's visualization
        NewColumn.Actions.Add(icon_click_action)

Key Notes:

  • The IconMiniatureVisualization inherits from Visualization, which exposes the Actions collection—this is the hidden gem you were missing!
  • You can customize the trigger (e.g., right-click, double-click) by changing MouseButton.Left to MouseButton.Right or using MouseDoubleClickTrigger instead.
  • The script inside click_action_script can access Spotfire objects like Document, ActivePage, etc., just like any other IronPython script in Spotfire.

If you need to pass context (like the row that was clicked), you can use ContextValues in your action script to get details about the clicked item—let me know if you need help with that part!

内容的提问来源于stack exchange,提问作者Oliver Drummond

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:26:03