i3ipc-python, 一种改进的python 库控制

分享于 

4分钟阅读

GitHub

  繁體 雙語
An improved Python library to control i3wm.
  • 源代码名称:i3ipc-python
  • 源代码网址:http://www.github.com/acrisci/i3ipc-python
  • i3ipc-python源代码文档
  • i3ipc-python源代码下载
  • Git URL:
    git://www.github.com/acrisci/i3ipc-python.git
    Git Clone代码到本地:
    git clone http://www.github.com/acrisci/i3ipc-python
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/acrisci/i3ipc-python
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    i3ipc-python

    改进的python 库来控制 i3wm。

    i3通信( 或者 ipc ) 进程是接口i3wm用来接收来自客户端应用程序( 如 i3-msg )的命令。 它还具有发布/订阅机制,用于通知窗口管理器事件的相关方。

    i3ipc-python是用于控制窗口管理器的python 库。 这个项目适用于一般脚本,和与窗口管理器( 如状态线生成器。通知守护进程) 交互的应用程序。

    在脚本扩展i3wm时,可以将脚本添加到示例文件夹中,或者在问题跟踪程序中生成一个脚本请求。

    安装

    i3ipc在 PyPI上。

    pip install i3ipc

    示例

    #!/usr/bin/env python3import i3ipc# Create the Connection object that can be used to send commands and subscribe# to events.i3 = i3ipc.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:')for output infilter(lambdao: o.active, outputs):
     print(output.name)# Send a command to be executed synchronously.i3.command('focus left')# Take all fullscreen windows out of fullscreenfor container in i3.get_tree().find_fullscreen():
     container.command('fullscreen')# Print the names of all the containers in the treeroot = i3.get_tree()print(root.name)for con in root:
     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.if e.current:
     print('Windows on this workspace:')
     for w in e.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('workspace::focus', on_workspace_focus)
    i3.on("window::focus", on_window_focus)# Start the main loop and wait for events to come in.i3.main()

    请自由报告 Bug,请求功能或者通过提交请求请求添加示例。

    许可证

    这里工作在BSD许可证下可用( 请参阅许可证)

    版权所有 © 2015,Tony Crisci

    保留所有权利。


    IMP  控制  
    相关文章