简体   繁体   English

在python中复制和粘贴文本

[英]Copy and paste text in python

I'm currently developing a language transition software for linux using python GTK. 我目前正在使用python GTK开发用于Linux的语言转换软件。 it has two entries. 它有两个条目。 what it basically does is, when the user type some word in a text entry 1, the translated text appears in text entry 2 and when the user press space bar, I want to paste the translated text to another application's text area. 它的基本作用是,当用户在文本条目1中键入某些单词时,翻译后的文本出现在文本条目2中,并且当用户按下空格键时,我想将翻译后的文本粘贴到另一个应用程序的文本区域中。 not to a text entry in my application. 而不是我的应用程序中的文本输入。 I think it needs to switch to the other application, paste the text and switch back to my application. 我认为它需要切换到其他应用程序,粘贴文本并切换回我的应用程序。

As an example, if gedit is opened in background, when a user type a word in my application and press the space bar, the translated word should be pasted in gedit. 例如,如果在后台打开gedit,则当用户在我的应用程序中键入单词并按下空格键时,应将翻译后的单词粘贴到gedit中。

Sometimes it may be possible to complete my task by set my application window as a popup window(type=WINDOW_POPUP) without set it as top level window(type=WINDOW_TOPLEVEL). 有时可以通过将应用程序窗口设置为弹出窗口(类型= WINDOW_POPUP)而不将其设置为顶级窗口(类型= WINDOW_TOPLEVEL)来完成我的任务。 but I'm not clear with that. 但我不清楚。

I think the problem is clear to you. 我认为问题很明显。 If anyone can help me to solve this problem, it would be a great help for me. 如果有人可以帮助我解决这个问题,那对我将是一个很大的帮助。 Thanks all. 谢谢大家

this looks like a dbus solution and not a fun one. 这看起来像是dbus解决方案,而不是有趣的解决方案。 As for clipboard manipulation in GTK http://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html will get you where you need to go, most of the C functions have a direct equivalent in python ( http://developer.gnome.org/pygtk/stable/class-gtkclipboard.html ). 至于GTK中的剪贴板操作, http://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html将带您前往所需的位置,大多数C函数在python中具有直接等效项( http:// developer.gnome.org/pygtk/stable/class-gtkclipboard.html )。 Communication between applications in GTK+ is not a whole lot of fun and when I worked on a project that had to do so, I ended up using DBUS (C++) but there might be a good python port for dbus, I haven't checked. GTK +中的应用程序之间的通信并不是很有趣,当我从事一个必须这样做的项目时,我最终使用了DBUS(C ++),但是对于dbus可能有一个很好的python端口,我没有检查。

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

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