Deepin Linux Desktop, 截图工具剖析(四) python - Xlib gtk.keysyms

本文深入探讨了Python中的Xlib库,介绍了如何利用它与X server建立连接并进行通信。重点讲解了Keymap和keysyms的概念,Keymap是键盘符号到键值的映射,涉及硬件键码、级别和组等信息。文中还给出了一个简单的Python Xlib样本,展示了如何处理特定的按键组合如Ctrl+S、Ctrl+Z、M+S、M+Z、Escape和Return。
摘要由CSDN通过智能技术生成

Python -Xlib

关于Xlib,网上相关都介绍比较少,只能从库文件那里获取信息啦 http://python-xlib.sourceforge.net/?page=home

基本概念就是:程序和X server建立连接,之后进行通信,Event之类都是通过这个链接进行的。至于Pixmap, Graphic Context之类的,还需要进一步学习。


Sample:

#!/usr/bin/env pyhon
# message.py --example program illustrating use message dialog

#import pygtk
#pygtk.require('2.0')
import gtk
from  collections import namedtuple
from Xlib import X, display, Xutil, Xcursorfont

(screenWidth, screenHeight) = gtk.gdk.get_default_root_window().get_size()
disp = display.Display()
rootWindow = disp.screen().root
WM_HINTS = disp.intern_atom("WM_HINTS", True)
WM_STATE = disp.intern_atom("WM_STATE", True)
WM_DESKTOP  = disp.intern_atom("_NET_WM_DESKTOP", True)
def enumXlibWindow():
    ''' enumerate child window of rootWindow'''
    return rootWindow.query_tree().children

def findWindowByProperty(xlibWindow, atom=WM_STATE):
    ''' find Window by property '''
    result = xlibWindow.query_tree().children
    if not result:
        return None
    else:
        for children in result:
            status = children.get_property(atom, WM_HINTS, 0, 0)
            if status:
                child = children
            else:
                child = findWindowByProperty(children, atom)
        return child

def convertCoord(x, y, width, height):
    ''' cut out overlop the screen'''
    xWidth = x + width
    yHeight = y + height
       
    if x < 0 and y > 0 and  y < yHeight < screenHeight:
        return (0, y, width+x, height)
    
    if x < 0 and yHeight > screenHeight:
        return (0, y, width+x, height - (yHeight - screenHeight))
    
    if xWidth > screenWidth and yHeight > screenHeight:
        return (x, y, width - (xWidth - screenWidth), height - (yHeight - screenHeight))
    
    if  x > 0 and x < xWidth < screenWidth a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钱国正

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值