Я пытаюсь прочитать и разбор CSV-файла в LibreOffice Calc. Мне нужно показать текст, чтобы отладить мою логику, и первое, что я нашел, было this. Раздражающе, он дублирует функциональность, встроенную в OOo Basic. Первая реализация пытается использовать несуществующую функцию; вторая работает, если я вызываю его непосредственно (с помощью TestMessageBox
из меню Tools), но когда я включаю его из моего pythonpath
каталога я получаю сообщение об ошибке:Отладка OOo UNO-Python
com.sun.star.uno.RuntimeExceptionError during invoking function main in module file:///C:/path/to/test.py (: 'module' object has no attribute 'MessageBox' C:\path\to\test.py:34 in function main() [msgbox.MessageBox(parentwin, message, 'Title')]
C:\Program Files (x86)\LibreOffice 5\program\pythonscript.py:870 in function invoke() [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,
Awesome, LibreOffice нашли и исправили проблему уже. Спасибо за ссылку! – Grault