Simple python script to get a libreoffice base field and play on vlc

纵饮孤独 提交于 2019-12-12 03:52:16

问题


I've banged my head for hours on this one, and I don't understand the LibreOffice macro api well enough to know how to make this work:

1) This script works in 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) I've got python scripts working fine in LibreOffice Base, and this script is fired on a button press. The video opens (with an error - see below)

Now, how do open the path found in a given record's field labeled "path" -- ie, what is being passed to python, and how do I pull that relevant bit of info?

Further, whenever I fire this, the video plays, but I also get:

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 )]
)

Please help!


回答1:


For example, say the form is based on a table containing a column called PATH. Assign the button's Execute action event to this function:

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

Documentation for Base macros is confusing, but there is some at: http://www.pitonyak.org/database/



来源:https://stackoverflow.com/questions/38306910/simple-python-script-to-get-a-libreoffice-base-field-and-play-on-vlc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!