Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么desktop.getCurrentComponent()在PyUNO中不返回任何值?_Python_Libreoffice_Pyuno - Fatal编程技术网

Python 为什么desktop.getCurrentComponent()在PyUNO中不返回任何值?

Python 为什么desktop.getCurrentComponent()在PyUNO中不返回任何值?,python,libreoffice,pyuno,Python,Libreoffice,Pyuno,尝试恢复一个名为Wavelet的PyUNO示例脚本,以了解LO现在是如何工作的,并重新开始。由于LibreOffice&UNO在脚本创建时做了一些更改,我遇到了一些问题 已成功获取桌面对象。现在我想检索打开文档的组件。我如何正确地实现这一点?desktop.getCurrentComponent()调用返回None 图书馆办公室版本:6.4.6.2 系统:Ubuntu MATE 20.04 x86_64 守则如下: #/usr/bin/python3 def TestWave(事件): 小波=小

尝试恢复一个名为Wavelet的PyUNO示例脚本,以了解LO现在是如何工作的,并重新开始。由于LibreOffice&UNO在脚本创建时做了一些更改,我遇到了一些问题

已成功获取桌面对象。现在我想检索打开文档的组件。我如何正确地实现这一点?
desktop.getCurrentComponent()
调用返回
None

图书馆办公室版本:6.4.6.2

系统:Ubuntu MATE 20.04 x86_64

守则如下:

#/usr/bin/python3
def TestWave(事件):
小波=小波(XScript上下文)
小波触发器(())
进口uno
导入辅助对象
导入字符串
从com.sun.star.task导入XJobExecutor
类小波(unohelper.Base,XJobExecutor):
定义初始化(自身,ctx):
self.ctx=ctx
def触发器(自身,参数):
desktop=self.ctx.ServiceManager.createInstanceWithContext(
“com.sun.star.frame.Desktop”,self.ctx)
doc=desktop.getCurrentComponent()
打印('doc:',doc)
#尝试:
search=doc.createSearchDescriptor()
search.SearchRegularExpression=True

search.SearchString=“\\在不给出
desktop.getCurrentComponent()的情况下尝试
一个变量,所以请删除
doc=
。我记得我有这个问题,但不明白它为什么要这样做。我记得的是,不命名它使我的代码工作。这是我能给你的唯一建议。

尝试不给出
desktop.getCurrentComponent()
一个变量,所以请删除
doc=
。我记得我有这个问题,但不明白它为什么要这样做。我记得的是,不命名它使我的代码工作。这是我能给你的唯一建议。

尝试等待文档组件可用。它工作了:

doc = None
while doc is None:
    doc = desktop.getCurrentComponent()

尝试等待文档组件可用。该操作成功:

doc = None
while doc is None:
    doc = desktop.getCurrentComponent()

谢谢你的回答!不幸的是,它不起作用:
回溯(最近一次调用最后一次):
文件“/wavelet.py”,第62行,在
小波.trigger(())
文件“/wavelet.py”,第24行,在trigger
搜索=desktop.getCurrentComponent().createSearchDescriptor()
AttributeError:“非类型”对象没有属性“createSearchDescriptor”
可能我们刚刚发现了一个bug。感谢您的回答!不幸的是,它不起作用:
回溯(最近一次调用):
文件“/wavelet.py”,第62行,在
小波.trigger(())
文件“/wavelet.py”中“,第24行,在触发器
search=desktop.getCurrentComponent().createSearchDescriptor()
AttributeError:“非类型”对象没有属性“createSearchDescriptor”
可能我们刚刚发现了一个错误。