0

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!

Trees4theForest
  • 1,267
  • 2
  • 18
  • 48
  • It seems that your `path` doesn't contain a string but a `com.sun.star.lang.EventObject`. How about posting the code where the error actually happens? Posting code that works isn't very useful for debugging. – Aran-Fey Jul 11 '16 at 12:48
  • hi rawling -- that is the code exactly as it appears. something is being passed to the function (I guess) that is causing that error -- ironically, I suspect it's the information I need to get the path I want, but I can't be sure... – Trees4theForest Jul 11 '16 at 12:56

1 Answers1

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/

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • +1 for documentation is confusing... I've been at this for weeks, and still can't find a "here's how you get element x from form y" in a any relevant situation. Everything assumes you magically known this stuff... – Trees4theForest Jul 11 '16 at 21:34