im trying to replicate the screen contens in my application .. i need a certain area of the screen to be drawn in my app...although this code works fine, its very very slow...takes more than 20 seconds with inferior quality and around 30-40 with best quality...
is there a quicker way of doing the same...i want it to b e done within .5 seconds max ...

i tried to do the same by taking a screenshot...but even that takes atleast 5 seconds skipping every alternate pixel...

class Window:
    def __init__(self, display, msg):
        self.display = display
        self.msg = msg
 
        self.screen = self.display.screen()
        self.window = self.screen.root.create_window(
            10, 10, 300, 300, 1,
            self.screen.root_depth,
            background_pixel=self.screen.white_pixel,
            event_mask=X.ExposureMask | X.KeyPressMask,
            )
        self.colormap = self.screen.default_colormap
        color = self.colormap.alloc_color(0, 0, 65535)
        xor_color = color.pixel ^ 0xffffff
        self.gc = self.window.create_gc(
            line_width = 2,
            line_style = X.LineSolid,
            fill_style = X.FillOpaqueStippled,
            fill_rule  = X.WindingRule,
            cap_style  = X.CapButt,
            join_style = X.JoinMiter,
            foreground = xor_color,
            background = self.screen.black_pixel,
            function = X.GXxor, 
            graphics_exposures = False,
            subwindow_mode = X.IncludeInferiors,
            )  
 
        self.window.map()
 
    def loop(self):
        while True:
            e = self.display.next_event()
 
            if e.type == X.Expose:
				i=10
				j=10
				h=10
				k=10
				skip=0
				while j<121:
					while i<121:
						if skip==0:
							o_x_image=self.screen.root.get_image(i, j, 1, 1, Xlib.X.ZPixmap, 0xffffffff)
							o_pil_image_rgb = PIL.Image.fromstring("RGB", (1, 1), o_x_image.data, "raw", "BGRX")
							b = PIL.ImageStat.Stat(o_pil_image_rgb).mean
							b=map(int, b)
							r=b[0]*255
							g=b[1]*255	
							b=b[2]*255
							color = self.colormap.alloc_color(r,g,b)
							xor_color = color.pixel ^ 0xffffff
							self.gc = self.window.create_gc(
								foreground = xor_color,
								function = X.GXxor
								) 
							skip=1
							#print "not skipping"
						elif skip==1:
							skip=0
							#print "skipped"
						self.window.point(self.gc,h,k)
						h+=1
						i+=1
						
					j+=1
					i=10
					k+=1
					h=10
					
            elif e.type == X.KeyPress:
                raise SystemExit

Ouch, mixing tabs and spaces really goofs up the code indentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.