首页 > 解决方案 > 尝试使用 python 代码关闭和打开 LibreOffice Impress

问题描述

使用树莓派运行 raspian。我想在触发器发生时打开一个 *.odp,然后当另一个触发器发生时,关闭文件,然后打开另一个 *.odp 文件。问题:一旦 LibreOffice Impress 打开,它似乎不再可用于通过终端接收命令。这些命令似乎只有在我们手动关闭 LibreOffice Impress 后才起作用。

我们已经成功地通过终端直接发送和通过我们的 python 脚本打开一个特定的 *.odp 文件。但是,我们似乎无法关闭演示文稿以便打开另一个演示文稿。

这是一段代码。射频代码是从遥控器接收...

cmd_openShowOn = "sudo libreoffice --nologo --show /home/pi/Documents/memorable.odp"
cmd_openShowOff = "sudo libreoffice --nologo --show /home/pi/Documents/forgettable.odp"
cmd_kill = "pkill soffice.bin"

if rfdevice.rx_code_timestamp != timestamp:
    timestamp = rfdevice.rx_code_timestamp
    logging.info(str(rfdevice.rx_code) +
                 " [pulselength " + str(rfdevice.rx_pulselength) +
                 ", protocol " + str(rfdevice.rx_proto) + "]")
    if str(rfdevice.rx_code) == "87347": # receives code to trigger closing anything that might be open and opening slide show for 'memorable.odp'
        print ("Laser On")
        os.system(cmd_kill)
        os.system(cmd_openShowOn)

    if str(rfdevice.rx_code) == "87356": # receives code to trigger closing anything that might be open and opening slide show for 'forgettable.odp'
        print("Laser Off")
        os.system(cmd_kill)            
        os.system(cmd_openShowOff)
time.sleep(1)

在我们手动终止 LibreOffice Impress 之前,任何来自 LibreOffice Impress 的后续响应都会被忽略。

标签: pythonopenoffice.org

解决方案


推荐阅读