#!/usr/bin/python from commands import getoutput def format_with_commas(x): x_str = str(x) outstr = "" for i in range(len(x_str)): if(i%3 == 0): outstr += ',' outstr += x_str[-(i+1)] foutstr = "" for i in range(len(outstr)-1): foutstr += outstr[-(i+1)] return foutstr total = 0; totalsqinches = 0; outlines = getoutput('xrandr | grep " connected" | sed "s/primary//g" | sed "s/[a-Z ]*(.*)//g"').split("\n") for line in outlines: lsp = line.split() # print lsp output_name = lsp[0] xres, yres = [int(r) for r in lsp[2].split('+')[0].split('x')] xsize = int(lsp[3].split('m')[0]) / 25.4 ysize = int(lsp[5].split('m')[0]) / 25.4 print output_name, ":", "Resolution ", xres, "x", yres, print "(", format_with_commas(xres*yres), " pixels)" total += xres*yres; print xsize, " by ", ysize, " inches", xsize*ysize , "square inches" totalsqinches = xsize * ysize print "Total Pixels: ", format_with_commas(total), "(", total/1000000.0, "megapixel)" print "Total Area: ", totalsqinches, " square inches"