def get_screen_res():
    """
    Funcion that check current screen resolution. Raise OSError if can't recognise OS!
    * :return: (width, height) tuple with screen resolution.
    """
    import platform

    system = platform.system()
    if 'Linux' in system:
        import subprocess
        import re

        output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4', shell=True, stdout=subprocess.PIPE)
        output = output.communicate()[0]
        valid_res = lambda x: re.match('^\d{3,4}x\d{3,4}$', x)
        if not valid_res(output):
            output = subprocess.Popen(' xdpyinfo | grep dimensions | cut -d" " -f7', shell=True, stdout=subprocess.PIPE)
            output = output.communicate()[0]
        if not valid_res(output):
            logging.ERROR('OS ERROR - no way of determine screen res')
            raise OSError(
                "Humanity need more time to come up with efficient way of checking screen resolution of your hamster")
        width, height = map(int, output.split('x'))
    elif 'Windows' in system:
        from win32api import GetSystemMetrics

        width = int(GetSystemMetrics(0))
        height = int(GetSystemMetrics(1))
    else:  # can't recognise OS
        logging.ERROR('OS ERROR - no way of determine screen res')
        raise OSError("get_screen_res function can't recognise your OS")
    logging.info('Screen res set as: {}x{}'.format(width, height))
    return OrderedDict(width=width, height=height)
Exemple #2
0
 def _calcSizeRendered(self):
     """DEPRECATED in 1.80.00. This funtionality is now handled by _updateVertices() and verticesPix"""
     #raise DeprecationWarning, "_calcSizeRendered() was deprecated in 1.80.00. This funtionality is nowhanded by _updateVertices() and verticesPix"
     if self.units in ['norm', 'pix', 'height']:
         self._sizeRendered = copy.copy(self.size)
     elif self.units in ['deg', 'degs']:
         self._sizeRendered = deg2pix(self.size, self.win.monitor)
     elif self.units == 'cm':
         self._sizeRendered = cm2pix(self.size, self.win.monitor)
     else:
         logging.ERROR(
             "Stimulus units should be 'height', 'norm', 'deg', 'cm' or 'pix', not '%s'"
             % self.units)
Exemple #3
0
def get_screen_res():
    """
    Funcion that check current screen resolution. Raise OSError if can't recognise OS!
    * :return: (width, height) tuple with screen resolution.
    """
    import platform

    system = platform.system()
    if 'Linux' in system:
        width, height = [
            int(x)
            for x in "b'1920x1080\n'".split('\'')[1].split('\n')[0].split('x')
        ]
    elif 'Windows' in system:
        from win32api import GetSystemMetrics

        width = int(GetSystemMetrics(0))
        height = int(GetSystemMetrics(1))
    else:  # can't recognise OS
        logging.ERROR('OS ERROR - no way of determine screen res')
        raise OSError("get_screen_res function can't recognise your OS")
    logging.info('Screen res set as: {}x{}'.format(width, height))

    return [width, height]