ilp*_*ipe 19 python vim bash autoit stata
我经常在工作中使用stata.我选择的文本编辑器是(g)vim.我一直在使用这里或这里提供的脚本将代码从vim发送到stata.这个功能是非常实用的,实际上是唯一阻止我完全切换到Linux的东西.脚本是用AutoIT编写的,所以我不能在linux中使用它们.它们也基本上独立于文本编辑器的选择,编写它们的人使用的是notepad ++.
基本上,这些脚本与我的vimrc中的几行一起允许我将选择或整个文件发送到正在运行的stata窗口(如果没有打开,则首先启动stata).
我正在寻找一个在linux中执行此操作的解决方案,但我不知道从哪里开始.在linux中有两个不同的stata版本,命令行的stata和xstata是gui版本.我需要使用gui版本,因为命令行版本的功能有限,所以屏幕/ tmux被排除在外.
如果这是微不足道的,我真的很抱歉错过了它,并非常感谢解决方案.我也无法找到我可以使用的vim的现有插件.如果没有,我愿意花一些时间来弄清楚如何实施解决方案.然而,正确方向的指针会非常有用.我对linux和编程一般比较陌生,但愿意学习.
关于工具:我不知道bash,但在某些时候我想要查看它.我已经在python中涉足了一点,所以这也没关系.如果此任务还有其他优势,请告诉我.
任何帮助是极大的赞赏.AutoIT脚本托管在网站上,但如果需要,我可以在此处发布我的Windows设置.
编辑
好的,经过评论中的一些争论,这里是我需要翻译的基本AutoIT脚本.(我更喜欢每次都不会覆盖系统剪贴板内容的解决方案.)
Edit2我想这就是脚本本质上的作用:它检查一个打开的stata窗口,选择它(或执行一个),将要执行的内容粘贴到一个临时文件中,切换到stata窗口,选择命令行使用ctrl-1(以及可能已经使用ctrl-a编写的任何内容),然后粘贴"tempfile"到命令行,然后命令行执行发送的代码.至少这是我理解它的方式.
最后评论
我不久前在bash中编写了一个解决方案,它在这里作为这个问题的先前版本的答案发布.
; Declare variables
Global $ini, $statapath, $statawin, $statacmd, $dofile, $clippause, $winpause, $keypause
; File locations
; Path to INI file
$ini = @ScriptDir & "\rundo.ini"
;; contents of ini file are the following
    ;[Stata]
    ;; Path to Stata executable
    ;statapath = "C:\Program Files\Stata11\StataSE.exe"
    ;; Title of Stata window
    ;statawin = "Stata/SE 11.2"
    ;; Keyboard shortcut for Stata command window
    ;statacmd = "^1"
    ;[Delays]
    ;; Pause after copying of Stata commands to clipboard, in milliseconds
    ;; Use higher number if script fails (default: 100, recommended range: 0 - 200)
    ;clippause = 100
    ;; Pause between window-related operations, in milliseconds
    ;; Use lower number to speed up script, higher number if script fails (default: 200)
    ;winpause = 200
    ;; Pause between key strokes sent to Stata, in milliseconds
    ;; Use lower number to speed up script, higher number if script fails (default: 1)
    ;keypause = 1
; Path to Stata executable
$statapath = IniRead($ini, "Stata", "statapath", "C:\Program Files\Stata11\StataSE.exe")
; Title of Stata window
$statawin = IniRead($ini, "Stata", "statawin", "Stata/SE 11.2")
; Keyboard shortcut for Stata command window
$statacmd = IniRead($ini, "Stata", "statacmd", "^1")
; Path to do-file that is passed to AutoIt
; Edit line to match editor used, if necessary
$dofile = $CmdLine[1]
; Delays
; Pause after copying of Stata commands to clipboard
$clippause = IniRead($ini, "Delays", "clippause", "100")
; Pause between window-related operations
$winpause = IniRead($ini, "Delays", "winpause", "200")
; Pause between keystrokes sent to Stata
$keypause = IniRead($ini, "Delays", "keypause", "1")
; Set WinWaitDelay and SendKeyDelay to speed up or slow down script
Opt("WinWaitDelay", $winpause)
Opt("SendKeyDelay", $keypause)
; If more than one Stata window is open, the window that was most recently active will be matched
Opt("WinTitleMatchMode", 2)
; Check if Stata is already open, start Stata if not
If WinExists($statawin) Then
  WinActivate($statawin)
  WinWaitActive($statawin)
  ; Activate Stata command window and select text (if any)
  Send($statacmd)
  Send("^a")
  ; Run saved do-file
  ; Double quotes around $dofile needed in case path contains blanks
  ClipPut("do " & '"' & $dofile & '"')
  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
  Sleep($clippause)
  Send("^v" & "{Enter}")
Else
  Run($statapath)
  WinWaitActive($statawin)
  ; Activate Stata command window
  Send($statacmd)
  ; Run saved do-file
  ; Double quotes around $dofile needed in case path contains blanks
  ClipPut("do " & '"' & $dofile & '"')
  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
  Sleep($clippause)
  Send("^v" & "{Enter}")
EndIf
IronAHK是AutoHotKey脚本语言的 Linux/Mono 重写版,类似于 AutoIt(一种 GUI 自动化/键盘重新映射工具)。我没有使用过 IronAHK,但 AutoHotkey 可以运行 AutoIt v2 脚本。
你也可以看看@Project Sikuli:“Sikuli是一种使用图像(屏幕截图)来自动化和测试图形用户界面(GUI)的可视化技术。Sikuli包括Sikuli Script(Jython的可视化脚本API)和Sikuli IDE(集成开发环境)用于轻松编写带有屏幕截图的可视化脚本”(来自 sikuli 首页)
另一个不错的选择是Linux 桌面测试项目 (LDTP),可以使用 Python 编写脚本:
例子:
from ldtp import *
from ldtputils import *
try:
    launchapp("gedit")
    if waittillguiexist("*.gedit")==0:
        raise LdtpExecutionError("Gedit window does not exist")
    selectmenuitem("*-gedit", "mnuFile;mnuOpen")
    selectrow("dkgOpenFiles...", "tblFiles", fileName[0])
    ...