用python获取窗口标题?
我正在尝试编写一个Python程序,每隔X秒检查一次“窗口标题”是否为“last.fm”(http://www.last.fm/download)更改了,如果确实如此(或者这是我第一次运行该程序),它应该使用从窗口标题捕获的字符串来搜索歌曲的歌词并将它们显示给用户。
我目前使用 KDE4 作为桌面环境,我只需要“指向正确的方向”即可捕获属于 last.fm 客户端窗口标题的字符串。
谢谢!
I'm trying to write a python program that checks every X seconds if the 'window title' for 'last.fm' (http://www.last.fm/download) changed, if it did (or it's the first time I run the program) it should use use the string captured from the window title to search for the song's lyrics and display them to the user.
I'm currently using KDE4 as my desktop environment and I just need to be 'pointed in the right direction' on how I can capture the string that belongs to the window title for last.fm client.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过
subprocess
模块使用wmctrl
实用程序。您可以在终端中输入wmctrl -l
并查看从中获得的输出。You can use the
wmctrl
utility through thesubprocess
module. You can typewmctrl -l
into a terminal and see the output you can get from it.我认为通过使用自动化框架,您也许能够将其作为一个子集来实现。
例如尝试dogtail(https://fedorahosted.org/dogtail/),它可以通过名称聚焦于窗口,按名称单击按钮,因此在 src 代码中您也许能够看到如何获取标题。
I think by using a automation framework you may be able to achieve this as a subset.
e.g. try dogtail(https://fedorahosted.org/dogtail/), it can focus on windows by name, click on buttons by name, so in the src code you may be able to see how to get title.
查看 X11 实用程序,特别是
xlsclients
和xprop
。举个例子,这是我用来获取有关我的 Firefox 信息的 shell 命令
窗口:
输出:
Have a look at X11 utilities, specifically
xlsclients
andxprop
.As an example, this is the shell commands I used to get info about my firefox
window:
Output:
尝试使用 dcop 和引导 kwin。您也许可以列出所有窗口标题。
有关如何使用 dcop 的示例,请参阅以下内容:
http://docs.kde.org/stable/en/kdegraphics/ ksnapshot/dcop.html
Try using dcop and piloting kwin. You can probably list all the window titles.
See the following for an example on how to use dcop:
http://docs.kde.org/stable/en/kdegraphics/ksnapshot/dcop.html
另一个答案可能是检查应用程序是否将歌曲更改发布到 DBus。如果确实如此,那么您只需监听该事件并采取行动即可。
another answer maybe to check if the application publishes the song change to DBus. if it does then you can just listen for the event and act on that.