How to detect (view) an area of the screen surrounding a mouse pointer
Question: I'm on Linux, and want to try to recreate Nattyware's Pixie tool for my web
development. gPick is ok, but Pixie is just all around better.

I want to be able to detect and display the area around the mouse pointer.
I've been trying to find a way to show an area around the mouse pointer,
zoomed in with Python.

I have no idea where to start with something like that. I don't want to _save_
any of the images, just show a zoomed in area of where the mouse is in a
window.

**EDIT** : I got something can potentially works. **DON'T RUN THIS, IT
CRASHES!**

    
    
    import sys, evdev
    from Xlib import display, X
    from PyQt4 import QtGui
    from PyQt4.QtGui import QPixmap, QApplication, QColor
    
    class printImage():
    def __init__(self):
        self.window = QtGui.QMainWindow()
        self.window.setGeometry(0,0,400,200)
    
        self.winId = QApplication.desktop().winId()
        self.width = 150
        self.height = 150
    
        self.label = QtGui.QLabel('Hi')
        self.label.setGeometry(10, 10, 400, 100)
        self.label.show()
    
    def drawView(self, x, y):
        self.label.setText('abc')
        pix = self.getScreenArea(x, y)
        self.pic.setPixmap(pix)
    
    def render(self):
        self.window.show()
    
    def getScreenArea(self, areaX, areaY):
        image = QPixmap.grabWindow(
            self.winId,
            x = areaX,
            y = areaY,
            width = self.width,
            height = self.height
        )
    
        return image
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        view = printImage()
    
        view.render()
    
        display = display.Display(':0')
        root = display.screen().root
    
        root.grab_pointer(
           True, 
           X.PointerMotionMask | X.ButtonReleaseMask, 
           X.GrabModeAsync, 
           X.GrabModeAsync, 
           0, 0, 
           X.CurrentTime
       )
    
        while True:
            ev = display.next_event()
            view.drawView(ev.event_x, ev.event_y)
    
        app.exec_()
    

Any idea why it just destroys itself? It crashes on the grabWindow()
function.. Is there something else that I can use?


Answer: This works for me on linux, probably it is cross-platform:

    
    
    import wx
    ff=wx.App()
    screen = wx.ScreenDC()
    size = screen.GetSize()
    bmp = wx.EmptyBitmap(size[0], size[1])
    mem = wx.MemoryDC(bmp)
    mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
    del mem
    #bmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)
    im = bmp.ConvertToImage()
    

from the `help`:

    
    
    ConvertToImage
    
    Creates a platform-independent image from a platform-dependent
    bitmap. This preserves mask information so that bitmaps and images can
    be converted back and forth without loss in that respect.
    

