【问题标题】:Debugging OOo UNO-Python调试OOo UNO-Python
【发布时间】:2016-11-01 04:17:10
【问题描述】:

我正在尝试在 LibreOffice Calc 中读取和解析 CSV 文件。我需要显示文本以调试我的逻辑,我发现的第一件事是this。令人讨厌的是,它复制了 OOo Basic 中内置的功能。第一个实现尝试使用不存在的函数;如果我直接调用第二个(使用工具菜单中的TestMessageBox),则第二个有效,但是当我从我的pythonpath 目录中包含它时,我得到一个错误:

com.sun.star.uno.RuntimeExceptionError 在调用函数 main 期间 在模块中 file:///C:/path/to/test.py (: 'module' 对象没有属性 '消息框' C:\path\to\test.py:34 在函数 main() [msgbox.MessageBox(parentwin, message, 'Title')]
C:\Program Files (x86)\LibreOffice 5\program\pythonscript.py:870 在 函数调用() [ret = self.func( *args )] )

为什么没有MessageBox属性?

我是这样调用它的:

import msgbox

def main():
    doc = XSCRIPTCONTEXT.getDocument()
    parentwin = doc.CurrentController.Frame.ContainerWindow

    message = "Message"
    msgbox.MessageBox(parentwin, message, 'Title')

    return

这里是 pythonpath/msgbox.py:

import uno

from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE

from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX

def TestMessageBox():
  doc = XSCRIPTCONTEXT.getDocument()
  parentwin = doc.CurrentController.Frame.ContainerWindow

  s = "This a message"
  t = "Title of the box"
  res = MessageBox(parentwin, s, t, QUERYBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)

  s = res
  MessageBox(parentwin, s, t, "infobox")

# Show a message box with the UNO based toolkit
def MessageBox(ParentWin, MsgText, MsgTitle, MsgType=MESSAGEBOX, MsgButtons=BUTTONS_OK):
  ctx = uno.getComponentContext()
  sm = ctx.ServiceManager
  sv = sm.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx) 
  myBox = sv.createMessageBox(ParentWin, MsgType, MsgButtons, MsgTitle, MsgText)
  return myBox.execute()

g_exportedScripts = TestMessageBox,

【问题讨论】:

    标签: python libreoffice libreoffice-calc uno


    【解决方案1】:

    包名msgbox 已在UNO 中使用。见msgbox.MsgBox。为您的模块选择一个不同的名称,例如mymsgbox.py。更好的是,将其移动到pythonpath内的一个包(子目录)中,例如mystuff.msgbox.MessageBox

    其实我刚才试了msgbox.MsgBox,好像有用:

    import msgbox
    
    def main():
        message = "Message"
        myBox = msgbox.MsgBox(XSCRIPTCONTEXT.getComponentContext())
        myBox.addButton("oK")
        myBox.renderFromButtonSize()
        myBox.numberOflines = 2
        myBox.show(message,0,"Title")
    

    【讨论】:

    • 太棒了,LibreOffice 已经发现并解决了这个问题。感谢您的链接!
    猜你喜欢
    • 2019-04-11
    • 2013-07-12
    • 2021-01-31
    • 2020-09-18
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多