简单的python脚本获取libreoffice基本字段并在vlc

时间:2016-07-11 12:27:34

标签: python libreoffice-base

我在这个问题上花了好几个小时,我不明白LibreOffice的宏api知道如何使这个工作:

1)此脚本适用于python:

#!/usr/bin/env python3
import subprocess 
def play_vlc(path="/path/to/video.avi"):
    subprocess.call(['vlc', path])
    return None
play_vlc("/path/to/video.avi")

2)我已经在LibreOffice Base中正常运行python脚本了,这个脚本在按下按钮时触发。视频打开(出现错误 - 见下文)

现在,如何打开在给定记录的标记为“path”的字段中找到的路径 - 即传递给python的内容,以及如何提取相关的信息位? / p>

此外,每当我开火时,视频都会播放,但我也会得到:

com.sun.star.uno.RuntimeExceptionError during invoking function play_vlc in module file:///usr/lib/libreoffice/share/Scripts/python/vlc.py (<class 'TypeError'>: Can't convert 'com.sun.star.lang.EventObject' object to str implicitly
  /usr/lib/python3.5/subprocess.py:1480 in function _execute_child() [restore_signals, start_new_session, preexec_fn)]
  /usr/lib/python3.5/subprocess.py:947 in function __init__() [restore_signals, start_new_session)]
  /usr/lib/python3.5/subprocess.py:557 in function call() [with Popen(*popenargs, **kwargs) as p:]
  /usr/lib/libreoffice/share/Scripts/python/vlc.py:8 in function play_vlc() [subprocess.call(['vlc', path])]
  /usr/lib/libreoffice/program/pythonscript.py:870 in function invoke() [ret = self.func( *args )]
)

请帮忙!

1 个答案:

答案 0 :(得分:1)

例如,假设表单基于包含名为PATH的列的表。将按钮的Execute action事件分配给此功能:

def playvlc_button_pressed(oEvent):
    oForm = oEvent.Source.getModel().getParent()
    lNameCol = oForm.findColumn('PATH')
    sPath = oForm.getString(lNameCol)
    play_vlc(sPath)

基本宏的文档令人困惑,但有一些在: http://www.pitonyak.org/database/