繁体   English   中英

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

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

有没有办法在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()

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM