Pyglet 将文本复制并粘贴到 IncrementalTextLayout() 对象中

Pyglet copy and paste a text in an IncrementalTextLayout() object

有没有办法在 Pyglet 中制作一个简单的 "copy and paste"?

我需要复制一段文字 (ctrl + c) 并粘贴 (ctrl + v) 到 IncrementalTextLayout() Pyglet 中的对象,这可能吗?

我正在使用 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()

另一位开发人员使用 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)