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

2024/10/14 15:30:48

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!

Answer

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://en.xdnf.cn/q/117940.html

Related Q&A

Print month using the month and day

I need to print month using the month and day. But I cannot seem to move the numbers after 1 to the next line using Python.# This program shows example of "November" as month and "Sunday…

Maya: Defer a script until after VRay is registered?

Im trying to delay a part of my pipeline tool (which runs during the startup of Maya) to run after VRay has been registered. Im currently delaying the initialization of the tool in a userSetup.py like…

Optimization on Python list comprehension

[getattr(x, contact_field_map[communication_type])for x in curr_role_group.contacts ifgetattr(x, contact_field_map[communication_type])]The above is my list comprehension. The initial function and the …

tensorflow Word2Vec error

I downloaded source code of word2vec in github below. https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec.py I am using tensorflow on pycharm. Im using windows 10. I installed…

Mysterious characters at the end of E-Mail, received with socket in python

I am not sure if this is the right forum to ask, but I give it a try. A device is sending an E-Mail to my code in which I am trying to receive the email via a socket in python, and to decode the E-Mail…

Error when importingPython-vlc

I have installed python-vlc D:\Programing\Python\Python 3.6>python -m pip install python-vlc Requirement already satisfied: python-vlc in d:\programing\python\python 3.6\lib\site-packages\python_vlc…

How to use FEniCS in Jupyter Notebook or Spyder?

I have recently installed FEniCS using Docker with following commandTerminal> curl -s https://get.fenicsproject.org | bashEvery thing works well when I am in fenicsproject session. In this session w…

Error installing polyglot in python 3.5.2

I want to do sentiment analysis on urdu sentences. I searched a python package Polyglot having URDU POS tagger in it. But on installing, it prompts error;Any way out?

How do you turn a dict of lists into a list of dicts with all combinations?

Basically what I am looking for is the equivalent of itertools.product but for dicts.For example, say I want to test a function for all combinations of its keyword arguments, I would like to pass lists…

Django differentiate between the first time user and returning user

I am using django registration redux for login and auth purposes. I want to do the following.if the user logs in for the first time i want to redirect to URL-"profile/create" if the user is a…