⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posix_x11.py

📁 skype的API
💻 PY
📖 第 1 页 / 共 2 页
字号:
'''Low level Skype for Linux interface implementedusing XWindows messaging. Uses direct Xlib callsthrough ctypes module.This module handles the options that you can pass to L{ISkype.__init__<skype.ISkype.__init__>}for Linux machines when the transport is set to X11.No further options are currently supported.'''import threadingfrom ctypes import *from ctypes.util import find_libraryimport timefrom Skype4Py.API import ICommand, _ISkypeAPIBasefrom Skype4Py.enums import *from Skype4Py.errors import ISkypeAPIError# some Xlib constants_PropertyChangeMask = 0x400000_PropertyNotify = 28_ClientMessage = 33_PropertyNewValue = 0_PropertyDelete = 1# some Xlib typesc_ulong_p = POINTER(c_ulong)DisplayP = c_void_pAtom = c_ulongAtomP = c_ulong_pXID = c_ulongWindow = XIDBool = c_intStatus = c_intTime = c_ulongc_int_p = POINTER(c_int)# should the structures be aligned to 8 bytes?_align = (sizeof(c_long) == 8 and sizeof(c_int) == 4)# some Xlib structuresclass _XClientMessageEvent(Structure):    if _align:        _fields_ = [('type', c_int),                    ('pad0', c_int),                    ('serial', c_ulong),                    ('send_event', Bool),                    ('pad1', c_int),                    ('display', DisplayP),                    ('window', Window),                    ('message_type', Atom),                    ('format', c_int),                    ('pad2', c_int),                    ('data', c_char * 20)]    else:        _fields_ = [('type', c_int),                    ('serial', c_ulong),                    ('send_event', Bool),                    ('display', DisplayP),                    ('window', Window),                    ('message_type', Atom),                    ('format', c_int),                    ('data', c_char * 20)]class _XPropertyEvent(Structure):    if _align:        _fields_ = [('type', c_int),                    ('pad0', c_int),                    ('serial', c_ulong),                    ('send_event', Bool),                    ('pad1', c_int),                    ('display', DisplayP),                    ('window', Window),                    ('atom', Atom),                    ('time', Time),                    ('state', c_int),                    ('pad2', c_int)]    else:        _fields_ = [('type', c_int),                    ('serial', c_ulong),                    ('send_event', Bool),                    ('display', DisplayP),                    ('window', Window),                    ('atom', Atom),                    ('time', Time),                    ('state', c_int)]class _XErrorEvent(Structure):    if _align:        _fields_ = [('type', c_int),                    ('pad0', c_int),                    ('display', DisplayP),                    ('resourceid', XID),                    ('serial', c_ulong),                    ('error_code', c_ubyte),                    ('request_code', c_ubyte),                    ('minor_code', c_ubyte)]    else:        _fields_ = [('type', c_int),                    ('display', DisplayP),                    ('resourceid', XID),                    ('serial', c_ulong),                    ('error_code', c_ubyte),                    ('request_code', c_ubyte),                    ('minor_code', c_ubyte)]class _XEvent(Union):    if _align:        _fields_ = [('type', c_int),                    ('xclient', _XClientMessageEvent),                    ('xproperty', _XPropertyEvent),                    ('xerror', _XErrorEvent),                    ('pad', c_long * 24)]    else:        _fields_ = [('type', c_int),                    ('xclient', _XClientMessageEvent),                    ('xproperty', _XPropertyEvent),                    ('xerror', _XErrorEvent),                    ('pad', c_long * 24)]XEventP = POINTER(_XEvent)# Xlib error handler typeXErrorHandlerP = CFUNCTYPE(c_int, DisplayP, POINTER(_XErrorEvent))class _ISkypeAPI(_ISkypeAPIBase):    def __init__(self, handler, opts):        _ISkypeAPIBase.__init__(self, opts)        self.RegisterHandler(handler)        # check options        if opts:            raise TypeError('Unexpected parameter(s): %s' % ', '.join(opts.keys()))        # setup Xlib        libpath = find_library('X11')        if not libpath:            raise ImportError('Could not find X11 library')        self.x11 = cdll.LoadLibrary(libpath)        # setup Xlib function prototypes        self.x11.XCloseDisplay.argtypes = (DisplayP,)        self.x11.XCloseDisplay.restype = None        self.x11.XCreateSimpleWindow.argtypes = (DisplayP, Window, c_int, c_int, c_uint,                c_uint, c_uint, c_ulong, c_ulong)        self.x11.XCreateSimpleWindow.restype = Window        self.x11.XDefaultRootWindow.argtypes = (DisplayP,)        self.x11.XDefaultRootWindow.restype = Window        self.x11.XDeleteProperty.argtypes = (DisplayP, Window, Atom)        self.x11.XDeleteProperty.restype = None        self.x11.XDestroyWindow.argtypes = (DisplayP, Window)        self.x11.XDestroyWindow.restype = None        self.x11.XPending.argtypes = (DisplayP,)        self.x11.XPending.restype = c_int        self.x11.XGetAtomName.argtypes = (DisplayP, Atom)        self.x11.XGetAtomName.restype = c_char_p        self.x11.XGetErrorText.argtypes = (DisplayP, c_int, c_char_p, c_int)        self.x11.XGetErrorText.restype = None        self.x11.XGetWindowProperty.argtypes = (DisplayP, Window, Atom, c_long, c_long, Bool,                Atom, AtomP, c_int_p, c_ulong_p, c_ulong_p, POINTER(POINTER(Window)))        self.x11.XGetWindowProperty.restype = c_int        self.x11.XInitThreads.argtypes = ()        self.x11.XInitThreads.restype = Status        self.x11.XInternAtom.argtypes = (DisplayP, c_char_p, Bool)        self.x11.XInternAtom.restype = Atom        self.x11.XNextEvent.argtypes = (DisplayP, XEventP)        self.x11.XNextEvent.restype = None        self.x11.XOpenDisplay.argtypes = (c_char_p,)        self.x11.XOpenDisplay.restype = DisplayP        self.x11.XSelectInput.argtypes = (DisplayP, Window, c_long)        self.x11.XSelectInput.restype = None        self.x11.XSendEvent.argtypes = (DisplayP, Window, Bool, c_long, XEventP)        self.x11.XSendEvent.restype = Status        self.x11.XSetErrorHandler.argtypes = (XErrorHandlerP,)        self.x11.XSetErrorHandler.restype = None        self.x11.XLockDisplay.argtypes = (DisplayP,)        self.x11.XLockDisplay.restype = None        self.x11.XUnlockDisplay.argtypes = (DisplayP,)        self.x11.XUnlockDisplay.restype = None        # init Xlib        self.x11.XInitThreads()        self.error = None        # callback has to be saved to keep reference to bound method        self._error_handler_callback = XErrorHandlerP(self._error_handler)        self.x11.XSetErrorHandler(self._error_handler_callback)        self.disp = self.x11.XOpenDisplay(None)        if not self.disp:            raise ISkypeAPIError('Could not open XDisplay')        self.win_root = self.x11.XDefaultRootWindow(self.disp)        self.win_self = self.x11.XCreateSimpleWindow(self.disp, self.win_root,                                    100, 100, 100, 100, 1, 0, 0)        self.x11.XSelectInput(self.disp, self.win_root, _PropertyChangeMask)        self.win_skype = self.get_skype()        ctrl = 'SKYPECONTROLAPI_MESSAGE'        self.atom_msg = self.x11.XInternAtom(self.disp, ctrl, False)        self.atom_msg_begin = self.x11.XInternAtom(self.disp, ctrl + '_BEGIN', False)        self.loop_event = threading.Event()        self.loop_timeout = 0.0001        self.loop_break = False    def __del__(self):        if hasattr(self, 'x11'):            if hasattr(self, 'disp'):                if hasattr(self, 'win_self'):                    self.x11.XDestroyWindow(self.disp, self.win_self)                self.x11.XCloseDisplay(self.disp)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -