python - How to detect (view) an area of the screen surrounding a mouse pointer -
i'm on linux, , want try recreate nattyware's pixie tool web development. gpick ok, pixie around better.
i want able detect , display area around mouse pointer. i've been trying find way show area around mouse pointer, zoomed in python.
i have no idea start that. don't want save of images, show zoomed in area of mouse in window.
edit: got can potentially works. don't run this, crashes!
import sys, evdev xlib import display, x pyqt4 import qtgui 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 destroys itself? crashes on grabwindow() function.. there else can use?
this works me on linux, 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 help
:
converttoimage creates platform-independent image platform-dependent bitmap. preserves mask information bitmaps , images can converted , forth without loss in respect.
Comments
Post a Comment