【问题标题】:Add menu to libreoffice that persists app restarts via a script向 libreoffice 添加菜单,通过脚本持久化应用程序重启
【发布时间】:2023-02-05 07:44:05
【问题描述】:

我想运行一个脚本,添加一个通过LibreOffice 重新启动持续存在的菜单。

我知道如何将菜单添加到LibreOfficeas posted here(但它会在应用程序重启时消失)。

我看到可以手动修改启动宏as posted here

是否可以通过单个脚本修改启动脚本并将其添加到autoexec 部分?

【问题讨论】:

  • 我认为我正在寻找的答案涉及“OnStartApp”事件,但我一直没有弄清楚如何使用它。

标签: python libreoffice


【解决方案1】:

Start Application 事件可以设置为运行宏,方法是转到工具 > 宏 > 自定义并保存在下拉列表中的“LibreOffice”下。这花了我两次尝试成功申请和保存,所以看起来有点棘手。

如果您不想手动设置事件,根据this post by librebel,以下代码将执行设置,如果需要,您可以将其转换为 python。

Sub connect_Start_Application_Event()
REM Call this macro once to programmatically connect the LibreOffice "Start Application" event to the Basic macro `on_ApplicationStart()`.
REM
    REM #****  Specify here the Name, Module, and Library of your Basic Macro to be called whenever LibreOffice starts:
    REM #****  This macro should be located inside your "[My Macros & Dialogs].Standard" library:
    REM #****  This macro should be defined with an Event Object as the first parameter:
    Const sMacro As String    = "on_ApplicationStart"   REM The Basic Macro to be called when the Application starts.
    Const sModule As String   = "Module1"   REM The name of the Basic Module that contains the above Macro.
    Const sLibrary As String  = "Standard"  REM The name of the Basic Library that contains the above Module.

    Dim aProps(1) As New com.sun.star.beans.PropertyValue
    aProps(0).Name      = "EventType"
    aProps(0).Value     = "Script"
    aProps(1).Name      = "Script"
    aProps(1).Value     = "vnd.sun.star.script:" & sLibrary & "." & sModule & "." & sMacro & "?language=Basic&location=application"
    
    Dim oGlobalEventBroadcaster As Object
    oGlobalEventBroadcaster = GetDefaultContext().getByName( "/singletons/com.sun.star.frame.theGlobalEventBroadcaster" )
    oGlobalEventBroadcaster.Events.replaceByName( "OnStartApp", aProps() )
    
    Msgbox "Application Event Connected: <OnStartApp> :--->  " &  sLibrary & "." & sModule & "." & sMacro
End Sub

但是,如果您想要的是一个调用 python-uno 代码的持久性菜单,则通常的方法是创建一个扩展。安装后,菜单将一直存在,直到它被卸载。

例如,这是 Addons.xcu 文件的一部分,它添加了一个名为“Linguistics”的菜单,根据 LO 的 UI 语言进行了本地化。在这种情况下,选项“音系设置”调用一个服务(从技术上讲不是宏,但它做同样的事情)在扩展中定义的 python-uno 中编写。

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          oor:name="Addons" oor:package="org.openoffice.Office">
  <node oor:name="AddonUI">
    <node oor:name="OfficeMenuBar">
      <node oor:name="name.JimK.LinguisticTools" oor:op="replace">
        <prop oor:name="Title" oor:type="xs:string">
          <value/>
          <value xml:lang="en">Linguistics</value>
          <value xml:lang="es">Lingüística</value>
          <value xml:lang="fr">Linguistique</value>
        </prop>
        <prop oor:name="Target" oor:type="xs:string">
          <value>_self</value>
        </prop>
        <prop oor:name="ImageIdentifier" oor:type="xs:string">
          <value/>
        </prop>
        <node oor:name="Submenu">
          <node oor:name="m01" oor:op="replace">
            <prop oor:name="URL" oor:type="xs:string">
              <value>service:name.JimK.LinguisticTools.PhonologySettings?execute</value>
            </prop>
            <prop oor:name="Title" oor:type="xs:string">
              <value/>
              <value xml:lang="en">Phonology Settings</value>
              <value xml:lang="es">Configuración de fonología</value>
              <value xml:lang="fr">Configuration de phonologie</value>
            </prop>
            <prop oor:name="Target" oor:type="xs:string">
              <value>_self</value>
            </prop>
            <prop oor:name="Context" oor:type="xs:string">
              <value>com.sun.star.text.TextDocument</value>
            </prop>
          </node>

【讨论】:

    猜你喜欢
    • 2018-02-13
    • 2022-10-08
    • 2011-12-08
    • 2013-05-07
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    相关资源
    最近更新 更多