一个改进的python库来控制i3wm和sway

i3ipc的Python项目详细描述


一个改进的python库来控制i3wmsway

关于

i3的进程间通信(或ipc)是i3wm用来从客户端应用程序(如i3-msg)接收commands的接口。它还具有一个发布/订阅机制,用于通知感兴趣的各方窗口管理器事件。

i3ipc python是一个用于控制窗口管理器的python库。此项目对于常规脚本编写以及与窗口管理器交互的应用程序(如状态行生成器、通知守护进程和窗口寻呼机)非常有用。

如果您想让脚本扩展i3wm,可以将脚本添加到examples folder

有关如何使用库的详细信息,请参见reference documentation

安装

i3ipc在PyPI上。

pip3 install i3ipc

示例

fromi3ipcimportConnection,Event# Create the Connection object that can be used to send commands and subscribe# to events.i3=Connection()# Print the name of the focused windowfocused=i3.get_tree().find_focused()print('Focused window %s is on workspace %s'%(focused.name,focused.workspace().name))# Query the ipc for outputs. The result is a list that represents the parsed# reply of a command like `i3-msg -t get_outputs`.outputs=i3.get_outputs()print('Active outputs:')foroutputinfilter(lambdao:o.active,outputs):print(output.name)# Send a command to be executed synchronously.i3.command('focus left')# Take all fullscreen windows out of fullscreenforcontainerini3.get_tree().find_fullscreen():container.command('fullscreen')# Print the names of all the containers in the treeroot=i3.get_tree()print(root.name)forconinroot:print(con.name)# Define a callback to be called when you switch workspaces.defon_workspace_focus(self,e):# The first parameter is the connection to the ipc and the second is an object# with the data of the event sent from i3.ife.current:print('Windows on this workspace:')forwine.current.leaves():print(w.name)# Dynamically name your workspaces after the current window classdefon_window_focus(i3,e):focused=i3.get_tree().find_focused()ws_name="%s:%s"%(focused.workspace().num,focused.window_class)i3.command('rename workspace to "%s"'%ws_name)# Subscribe to eventsi3.on(Event.WORKSPACE_FOCUS,on_workspace_focus)i3.on(Event.WINDOW_FOCUS,on_window_focus)# Start the main loop and wait for events to come in.i3.main()

异步支持

对异步的支持包含在i3ipc.aio包中。接口类似于阻塞接口,但是与套接字交互的方法是协同的。

fromi3ipc.aioimportConnectionfromi3ipcimportEventimportasyncioasyncdefmain():defon_window(self,e):print(e)c=awaitConnection(auto_reconnect=True).connect()workspaces=awaitc.get_workspaces()c.on(Event.WINDOW,on_window)awaitc.main()asyncio.get_event_loop().run_until_complete(main())

贡献

发展发生在Github。请随时报告错误、请求功能或通过提交拉取请求添加示例。

许可证

这项工作可根据BSD-3条款许可证(见许可证)提供。

版权所有©2015,Tony Crisi

保留所有权利。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
地理编码器java gwt   如何在Java中将Json节点插入到另一个节点中?   java什么会导致重新创建安卓数据库?   java从hashmap中获得5个最高值,同时保留插入顺序   JavaStruts:使用进度条上传文件   不依赖于用户偏好的java时间   启动应用程序的java问题   java如果找不到文件,如何显示错误消息?   java如何知道一个标记是包含一个值还是另一个标记?   另一个类的try-catch块中的java Invoke方法   将GraphML导入OrientDB时发生java OutOfMemoryError   基本Java方法调用   使用Cumber TestNG框架进行java Galen UI测试。获取错误引用错误:未定义“组织”。(<cmd>;第1行)   动态方法中的java InvocationTargetException   使用janusgraph后端HBase时发现MasterNotRunning的java NoClassDef   java不可变集合的实现   java如何使用GOLang调用RESTAPI在BitBucket中创建存储库   java在用户输入字符后跳出无限循环