2017-05-22 64 views
0

我想創建一個Spotfire中按鈕動作的控制,做以下Spotfire中 - 標記記錄和發送到剪貼板

  1. 在可視化表
  2. 發送選定行到剪貼板
  3. 選中所有行

第一步很容易處理(借用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(「(^ + C)」)。但是,這沒有奏效,所以我重寫爲SendKeys.Send(「^ c」),它可以工作,除非我按了兩次按鈕。

任何想法,我如何解決兩次點擊操作控制按鈕的問題? 解決方法是避免用腳本發送擊鍵,並重新嘗試將我的第一次嘗試代碼複製到剪貼板功能,但是我的Ironpython技能是一個限制因素。

回答

1

使用相同的崗位作爲參考我用這個代碼,使用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) 
0

感謝,sayTibco,代碼爲我工作,現在。請參閱下面的更新版本。仍然很想知道如何更好地利用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)