有没有办法在Pyglet中进行简单的“复制和粘贴”?
我需要复制一个文本( ctrl + c )并将其粘贴( ctrl + v )到Pyglet中的IncrementalTextLayout()
对象中,这是可能的吗? ?
我正在使用Python 3.4,Pyglet 1.2.4,我在Windows上运行。
代码示例:
import pyglet
if __name__ == "__main__":
window = pyglet.window.Window(617, 200)
batch = pyglet.graphics.Batch()
document = pyglet.text.document.FormattedDocument("Colar texto aqui!")
document.set_style(0, len(document.text), dict(font_name='Arial', font_size=25, color=(255, 255, 255, 255)))
layout = pyglet.text.layout.IncrementalTextLayout(document, 300, 50, batch=batch)
caret = pyglet.text.caret.Caret(layout, color=(255, 255, 255))
window.push_handlers(caret)
@window.event
def on_draw():
"""Desenha a tela."""
window.clear()
batch.draw()
window.push_handlers(caret)
pyglet.app.run()
答案 0 :(得分:0)
另一位开发人员用Pyperclip解决了这个问题,并将你的函数放在Pyglet中Window的on_key_press方法中。请遵循以下代码:
def on_key_press(self, symbol, modifiers):
if modifiers is 18 and pyglet.window.key.MOD_CTRL and int(symbol) is pyglet.window.key.V:
if self.input_text:
self.on_text(pyperclip.paste())
elif modifiers is 18 and pyglet.window.key.MOD_CTRL and int(symbol) is pyglet.window.key.C:
pyperclip.copy(self.input_text.document.text)