All pastes #1034001 Raw Copy code Copy link Edit

Something

public unlisted python v1 · immutable
#1034001 ·published 2008-05-30 11:53 UTC
rendered paste body
# -*- coding: utf-8 -*-import osimport ctypesimport sipfrom PyQt4 import QtGuiclass Display(ctypes.Structure):    passVisualID = ctypes.c_ulongclass Visual(ctypes.Structure):    _fields_ = [('ext_data', ctypes.c_voidp),                ('visualid', VisualID),                ('c_class', ctypes.c_int),                ('red_mask', ctypes.c_ulong),                ('green_mask', ctypes.c_ulong),                ('blue_mask', ctypes.c_ulong),                ('bits_per_rgb', ctypes.c_int),                ('map_entries', ctypes.c_int)]class XVisualInfo(ctypes.Structure):    _fields_ = [('visual', ctypes.POINTER(Visual)),                ('visualid', VisualID),                ('screen', ctypes.c_int),                ('depth', ctypes.c_int),                ('c_class', ctypes.c_int),                ('red_mask', ctypes.c_ulong),                ('green_mask', ctypes.c_ulong),                ('blue_mask', ctypes.c_ulong),                ('colormap_size', ctypes.c_int),                ('bits_per_rgb', ctypes.c_int),                ]PictFormat = ctypes.c_ulongXID = ctypes.c_ulongColormap = XIDclass XRenderDirectFormat(ctypes.Structure):    _fields_ = [('red', ctypes.c_short),                ('redMask', ctypes.c_short),                ('green', ctypes.c_short),                ('greenMask', ctypes.c_short),                ('blue', ctypes.c_short),                ('blueMask', ctypes.c_short),                ('alpha', ctypes.c_short),                ('alphaMask', ctypes.c_short)]class XRenderPictFormat(ctypes.Structure):    _fields_ = [('id', PictFormat),                ('type', ctypes.c_int),                ('depth', ctypes.c_int),                ('direct', XRenderDirectFormat),                ('colormap', Colormap)]TrueColor = 4VisualScreenMask = 0x02VisualDepthMask = 0x04VisualClassMask = 0x08PictTypeDirect = 1Window = XIDAllocNone = 0class QArgbApplication(QtGui.QApplication):       def __init__(self, argv = None):        xlib = ctypes.CDLL('libX11.so.6')        xlib.XOpenDisplay.restype = ctypes.POINTER(Display)        xlib.XOpenDisplay.argtypes = [ctypes.c_char_p]        xlib.XDefaultScreen.restype = ctypes.c_int        xlib.XDefaultScreen.argtypes = [ctypes.POINTER(Display)]        xlib.XGetVisualInfo.restype = ctypes.POINTER(XVisualInfo)        xlib.XGetVisualInfo.argtypes = [ctypes.POINTER(Display),                                        ctypes.c_long,                                        ctypes.POINTER(XVisualInfo),                                        ctypes.POINTER(ctypes.c_int)]        xlib.XCreateColormap.restype = Colormap        xlib.XCreateColormap.argtypes = [ctypes.POINTER(Display),                                         Window,                                         ctypes.POINTER(Visual),                                         ctypes.c_int]        xlib.XRootWindow.restype = Window        xlib.XRootWindow.argtypes = [ctypes.POINTER(Display),                                     ctypes.c_int]        xrender = ctypes.CDLL('libXrender.so.1')        xrender.XRenderQueryExtension.restype = ctypes.c_int        xrender.XRenderQueryExtension.argtypes = [ctypes.POINTER(Display),                                                  ctypes.POINTER(ctypes.c_int),                                                  ctypes.POINTER(ctypes.c_int)]        xrender.XRenderFindVisualFormat.restype = ctypes.POINTER(XRenderPictFormat)        xrender.XRenderFindVisualFormat.argtypes = [ctypes.POINTER(Display),                                                    ctypes.POINTER(Visual)]        dpy = xlib.XOpenDisplay(ctypes.cast(ctypes.c_void_p(0), ctypes.c_char_p))        #dpy = xlib.XOpenDisplay(":1")        screen = xlib.XDefaultScreen(dpy)        print "screen:", screen        eventBase = ctypes.c_int(0)        errorBase = ctypes.c_int(0)        if xrender.XRenderQueryExtension(dpy, ctypes.byref(eventBase),                                         ctypes.byref(errorBase)):            print "eventBase:", eventBase.value, "errorBase:", errorBase.value            nvi = ctypes.c_int(-1)            templ = XVisualInfo()            templ.screen = screen            templ.depth = ctypes.c_int(32)            templ.c_class = TrueColor            xvi = xlib.XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, ctypes.byref(templ), ctypes.byref(nvi))            print "nvi:", nvi.value            for i in range(0, nvi.value):                format = xrender.XRenderFindVisualFormat(dpy,                                                         xvi[i].visual)                if format.contents.type == PictTypeDirect and \                   format.contents.direct.alphaMask != 0:                    visual = xvi[i].visual                    colormap = xlib.XCreateColormap(dpy, xlib.XRootWindow(dpy, screen),                                                    visual, AllocNone)                    argbVisual = True                    break        else:            print "XRenderQueryExtension return false"        self.__visual = visual        self.__colormap = colormap        qt_visual = long(ctypes.addressof(self.__visual))        qt_colormap = long(self.__colormap)        print "visual = 0x%08x, colormap = 0x%08x" % (qt_visual, qt_colormap)        v = visual.contents        print 'ext_data', v.ext_data, 'visualid', v.visualid, 'c_class', v.c_class, \              'red_mask', v.red_mask, 'green_mask', v.green_mask, 'blue_mask', v.blue_mask, \              'bits_per_rgb', v.bits_per_rgb, 'map_entries', v.map_entries        import signal        signal.alarm(2)        if argbVisual:            print 'Found ARGB visual, starting app...'        else:            print 'No argb visual'        super(QArgbApplication, self).__init__(sip.wrapinstance(ctypes.cast(dpy, ctypes.c_void_p).value,                                                                QtGui.Display),                                               argv, qt_visual, qt_colormap)