我有一些没有按预期工作的简单代码。首先,文档说Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY).set_text()
应该只能接受一个带有长度参数选项的参数,但它不起作用(见下文)。最后,粘贴 unicode°
符号会在尝试从剪贴板中检索文本时中断设置文本(并且不会粘贴到其他程序中)。它给出了这个警告:
Gdk-WARNING **:从 UTF8_STRING 转换选择时出错
>>> from gi.repository.Gtk import Clipboard
>>> from gi.repository.Gdk import SELECTION_PRIMARY
>>> d='\u00B0'
>>> print(d)
°
>>> cb=Clipboard
Clipboard
>>> cb=Clipboard.get(SELECTION_PRIMARY)
>>> cb.set_text(d) #this should work
Traceback (most recent call last):
File "<ipython-input-6-b563adc3e800>", line 1, in <module>
cb.set_text(d)
File "/usr/lib/python3/dist-packages/gi/types.py", line 43, in function
return info.invoke(*args, **kwargs)
TypeError: set_text() takes exactly 3 arguments (2 given)
>>> cb.set_text(d, len(d))
>>> cb.wait_for_text()
(.:13153): Gdk-WARNING **: Error converting selection from UTF8_STRING
'\\Uffffffff\\Uffffffff'