我想创建一个执行以下操作的Spotfire按钮操作控件
第一步很容易处理(借鉴here)。对于第二步,我最初尝试使用脚本发送到剪贴板时失败(例如,建议here)。通过以编程方式将ctrl-c发送到spotfire,我在后续尝试中取得了部分成功(请参阅spotfired.blogspot.co.id/2014/04/pressing-keys-programatically.html)。
这是[主要]功能代码:
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
#Get table reference
vc = vis.As[VisualContent]()
dataTable = vc.Data.DataTableReference
#Set marking
marking=vc.Data.MarkingReference
#Setup rows to select from rows to include
rowCount=dataTable.RowCount
rowsToSelect = IndexSet(rowCount, True)
#Set marking
marking.SetSelection(RowSelection(rowsToSelect), dataTable)
#Script to send keystroke to Spotfire
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import SendKeys, Control, Keys
#Send keystroke for CTRL-C Copy-to-clipboard
SendKeys.Send("^c") #Ctrl+C
代码按预期工作,除了我必须按两次按钮以使脚本的ctrl-c部分工作(即点击一次导致在表格可视化中标记所有行) 。
我似乎解决的另一个问题是发送ctrl-c keystroke命令的最初建议语法是 SendKeys.Send(&#34;(^ + C)&#34;)。但是,这没有用,所以我改写为 SendKeys.Send(&#34; ^ c&#34;),这确实有效,除非我按下按钮两次。< / p>
有关如何解决两次击中动作控制按钮的问题的任何想法? 解决方法可能是避免使用脚本发送击键并重新访问我的第一个尝试代码复制到剪贴板功能,但我的Ironpython技能是限制因素。
答案 0 :(得分:2)
使用相同的帖子作为参考我使用此代码来使用Windows剪贴板
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()
tp = mytable.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)
f = open(tempFilename)
html=""
for line in f:
html += "\t".join(line.split("\t")).strip()
html += "\n"
f.close()
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
Clipboard.SetText(html)
答案 1 :(得分:0)
谢谢,说,提科,代码现在为我工作。请参阅下面的更新版本。仍然很想知道如何更好地利用SendKeys.Send(),但在我有一些时间进行实验之后会将其作为单独帖子的主题。
from Spotfire.Dxp.Application.Visuals import VisualContent, TablePlot
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
#get table reference
vc = mytable.As[VisualContent]()
dataTable = vc.Data.DataTableReference
#set marking
marking=vc.Data.MarkingReference
#setup rows to select from rows to include
rowCount=dataTable.RowCount
rowsToSelect = IndexSet(rowCount, True)
#Set marking
marking.SetSelection(RowSelection(rowsToSelect), dataTable)
#Copy marked records to Clipboard
import clr
import sys
clr.AddReference('System.Data')
import System
from System.IO import Path, StreamWriter
from System.Text import StringBuilder
#Temp file for storing the table data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()
#Export TablePlot data to the temp file
tp = mytable.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)
f = open(tempFilename)
#Format table
html=""
for line in f:
html += "\t".join(line.split("\t")).strip()
html += "\n"
f.close()
#Paste to system Clipboard
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
Clipboard.SetText(html)