Spotfire-标记记录并发送到剪贴板 [英] Spotfire - mark records and send to clipboard
问题描述
我想创建一个执行以下操作的Spotfire按钮操作控件
I'd like to create a Spotfire button action control that does the following
- 选择表可视化中的所有行
- 将选定的行发送到剪贴板
第一步很容易处理(从此处)。第二步,我最初尝试使用脚本发送到剪贴板的尝试没有成功(例如,如建议的此处)。通过将ctrl-c编程发送到Spotfire,我在一次后续尝试中取得了部分成功(请参见spotfired.blogspot.co.id/2014/04/pressing-keys-programatically.html)。
First step was handled pretty easily (borrowed from here). For the second step, I was unsuccessful in my initial attempts to send to clipboard with script (e.g. as suggested here). I was partially successful in a followup attempt by sending ctrl-c programatically to spotfire (see spotfired.blogspot.co.id/2014/04/pressing-keys-programatically.html).
这是[主要]功能代码:
Here's the [mostly] functioning code:
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部分起作用(即点击一次会在表格可视化中标记所有行)。
The code works as expected, except that I have to hit the button twice for the ctrl-c part of the script to work (i.e. hitting once results in marking all rows in the table visualization).
我似乎已经解决的另一个问题是,发送ctrl-c击键命令的最初建议语法是 SendKeys.Send((^ + C ))。但是,此操作无效,因此我将其改写为 SendKeys.Send( ^ c),该功能确实有效,但只有在我两次按下按钮后才能使用。
Another issue that I seemed to have resolved is that the originally suggested syntax to send the ctrl-c keystroke command was SendKeys.Send("(^+C)"). However, this didn't work, so I rewrote as SendKeys.Send("^c"), which does work, except only after I hit the button twice.
关于如何解决两次按下动作控制按钮的任何想法?
一种解决方法是避免发送带有脚本的击键并重新访问我的第一次尝试复制到剪贴板功能的代码,但是我的Ironpython技能在这里是一个限制因素。
Any thoughts on how I could fix the issue of having hit the action control button twice? A workaround could be to avoid sending keystrokes with script and revisit my first attempt code the copy-to-clipboard functionality, but my Ironpython skills are a limiting factor here.
推荐答案
使用相同的帖子作为参考,我使用以下代码使用Windows剪贴板
Using the same post as reference I used this code to use the windows clipboard
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)
这篇关于Spotfire-标记记录并发送到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!