def pix2cm(pixels, monitor):
 if (not isinstance(monitor, monitors.Monitor)):
  msg = 'cm2pix requires a monitors.Monitor object as the second argument but received %s'
  raise ValueError((msg % str(type(monitor))))
 scrWidthCm = monitor.getWidth()
 scrSizePix = monitor.getSizePix()
 if (scrSizePix is None):
  msg = 'Monitor %s has no known size in pixels (SEE MONITOR CENTER)'
  raise ValueError((msg % monitor.name))
 if (scrWidthCm is None):
  msg = 'Monitor %s has no known width in cm (SEE MONITOR CENTER)'
  raise ValueError((msg % monitor.name))
 return ((pixels * float(scrWidthCm)) / scrSizePix[0])

def pix2cm ( pixels , monitor ) : if ( not isinstance ( monitor , monitors . Monitor ) ) : msg = 'cm2pix requires a monitors.Monitor object as the second argument but received %s' raise ValueError ( ( msg % str ( type ( monitor ) ) ) ) scrWidthCm = monitor . getWidth ( ) scrSizePix = monitor . getSizePix ( ) if ( scrSizePix is None ) : msg = 'Monitor %s has no known size in pixels (SEE MONITOR CENTER)' raise ValueError ( ( msg % monitor . name ) ) if ( scrWidthCm is None ) : msg = 'Monitor %s has no known width in cm (SEE MONITOR CENTER)' raise ValueError ( ( msg % monitor . name ) ) return ( ( pixels * float ( scrWidthCm ) ) / scrSizePix [ 0 ] )
convert size in pixels to size in cm for a given monitor object .