Exemplo n.º 1
0
def get_number_of_monitors():
    gt.ensure_qtapp()
    desktop = QtWidgets.QDesktopWidget()
    if hasattr(desktop, 'numScreens'):
        n = desktop.numScreens()
    else:
        n = desktop.screenCount()
    return n
Exemplo n.º 2
0
def get_monitor_geometries():
    gt.ensure_qtapp()
    monitor_geometries = {}
    desktop = QtWidgets.QDesktopWidget()
    if hasattr(desktop, 'numScreens'):
        n = desktop.numScreens()
    else:
        n = desktop.screenCount()
    for screenx in range(n):
        rect = desktop.availableGeometry(screen=screenx)
        geom = (rect.x(), rect.y(), rect.width(), rect.height())
        monitor_geometries[screenx] = geom
    return monitor_geometries
Exemplo n.º 3
0
def get_monitor_geom(monitor_num=0):
    r"""
    Args:
        monitor_num (int): (default = 0)

    Returns:
        tuple: geom

    CommandLine:
        python -m wbia.plottool.screeninfo get_monitor_geom --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.plottool.screeninfo import *  # NOQA
        >>> monitor_num = 0
        >>> geom = get_monitor_geom(monitor_num)
        >>> result = ('geom = %s' % (ut.repr2(geom),))
        >>> print(result)
    """
    gt.ensure_qtapp()
    desktop = QtWidgets.QDesktopWidget()
    rect = desktop.availableGeometry(screen=monitor_num)
    geom = (rect.x(), rect.y(), rect.width(), rect.height())
    return geom
Exemplo n.º 4
0
def get_resolution_info(monitor_num=0):
    r"""
    Args:
        monitor_num (int): (default = 0)

    Returns:
        dict: info

    CommandLine:
        python -m wbia.plottool.screeninfo get_resolution_info --show
        xrandr | grep ' connected'
        grep "NVIDIA" /var/log/Xorg.0.log

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.plottool.screeninfo import *  # NOQA
        >>> monitor_num = 1
        >>> for monitor_num in range(get_number_of_monitors()):
        >>>     info = get_resolution_info(monitor_num)
        >>>     print('monitor(%d).info = %s' % (monitor_num, ut.repr3(info, precision=3)))
    """
    import wbia.guitool as gt

    app = gt.ensure_qtapp()[0]  # NOQA
    # screen_resolution = app.desktop().screenGeometry()
    # width, height = screen_resolution.width(), screen_resolution.height()
    # print('height = %r' % (height,))
    # print('width = %r' % (width,))

    desktop = QtWidgets.QDesktopWidget()
    screen = desktop.screen(monitor_num)
    ppi_x = screen.logicalDpiX()
    ppi_y = screen.logicalDpiY()
    dpi_x = screen.physicalDpiX()
    dpi_y = screen.physicalDpiY()
    # This call is not rotated correctly
    # rect = screen.screenGeometry()

    # This call has bad offsets
    rect = desktop.screenGeometry(screen=monitor_num)

    # This call subtracts offsets weirdly
    # desktop.availableGeometry(screen=monitor_num)

    pixels_w = rect.width()
    # for num in range(desktop.screenCount()):
    # pass
    pixels_h = rect.height()
    # + rect.y()

    """
    I have two monitors (screens), after rotation effects they have
    the geometry: (for example)
        S1 = {x: 0, y=300, w: 1920, h:1080}
        S2 = {x=1920, y=0, w: 1080, h:1920}

    Here is a pictoral example
    G--------------------------------------C-------------------
    |                                      |                  |
    A--------------------------------------|                  |
    |                                      |                  |
    |                                      |                  |
    |                                      |                  |
    |                 S1                   |                  |
    |                                      |        S2        |
    |                                      |                  |
    |                                      |                  |
    |                                      |                  |
    |--------------------------------------B                  |
    |                                      |                  |
    |                                      |                  |
    ----------------------------------------------------------D
    Desired Info

    G = (0, 0)
    A = (S1.x, S1.y)
    B = (S1.x + S1.w, S1.y + S1.h)

    C = (S2.x, S2.y)
    D = (S2.x + S1.w, S2.y + S2.h)

    from PyQt4 import QtGui, QtCore
    app = QtCore.QCoreApplication.instance()
    if app is None:
        import sys
        app = QtGui.QApplication(sys.argv)
    desktop = QtGui.QDesktopWidget()
    rect1 = desktop.screenGeometry(screen=0)
    rect2 = desktop.screenGeometry(screen=1)
    """

    # I want to get the relative positions of my monitors
    # pt = screen.pos()
    # pt = screen.mapToGlobal(pt)
    # pt = screen.mapToGlobal(screen.pos())
    # Screen offsets seem bugged
    # off_x = pt.x()
    # off_y = pt.y()
    # print(pt.x())
    # print(pt.y())
    # pt = screen.mapToGlobal(QtCore.QPoint(0, 0))
    # print(pt.x())
    # print(pt.y())
    off_x = rect.x()
    off_y = rect.y()
    # pt.x(), pt.y()

    inches_w = pixels_w / dpi_x
    inches_h = pixels_h / dpi_y
    inches_diag = (inches_w ** 2 + inches_h ** 2) ** 0.5

    mm_w = inches_w * ut.MM_PER_INCH
    mm_h = inches_h * ut.MM_PER_INCH
    mm_diag = inches_diag * ut.MM_PER_INCH

    ratio = min(mm_w, mm_h) / max(mm_w, mm_h)

    # pixel_density = dpi_x / ppi_x
    info = ut.odict(
        [
            ('monitor_num', monitor_num),
            ('off_x', off_x),
            ('off_y', off_y),
            ('ratio', ratio),
            ('ppi_x', ppi_x),
            ('ppi_y', ppi_y),
            ('dpi_x', dpi_x),
            ('dpi_y', dpi_y),
            # 'pixel_density', pixel_density),
            ('inches_w', inches_w),
            ('inches_h', inches_h),
            ('inches_diag', inches_diag),
            ('mm_w', mm_w),
            ('mm_h', mm_h),
            ('mm_diag', mm_diag),
            ('pixels_w', pixels_w),
            ('pixels_h', pixels_h),
        ]
    )
    return info