GithubHelp home page GithubHelp logo

screeninfo's Introduction

screeninfo

Build

Fetch location and size of physical screens.

Supported environments

  • MS Windows
  • MS Windows: Cygwin
  • GNU/Linux: X11 (through Xinerama)
  • GNU/Linux: DRM (experimental)
  • OSX: (through AppKit)

I don't plan on testing OSX or other environments myself. For this reason, I strongly encourage pull requests.

Installation

pip install screeninfo

Usage

from screeninfo import get_monitors
for m in get_monitors():
    print(str(m))

Output:

Monitor(x=3840, y=0, width=3840, height=2160, width_mm=1420, height_mm=800, name='HDMI-0', is_primary=False)
Monitor(x=0, y=0, width=3840, height=2160, width_mm=708, height_mm=399, name='DP-0', is_primary=True)

Forcing environment

In some cases (emulating X server on Cygwin etc.) you might want to specify the driver directly. You can do so by passing extra parameter to get_monitors() like this:

from screeninfo import get_monitors, Enumerator
for m in get_monitors(Enumerator.OSX):
    print(str(m))

Available drivers: windows, cygwin, x11, osx.

Contributing

git clone https://github.com/rr-/screeninfo.git # clone this repo
cd screeninfo
poetry install # to install the local venv
poetry run pre-commit install # to setup pre-commit hooks
poetry shell # to enter the venv

This project uses poetry for packaging, install instructions at poetry#installation

screeninfo's People

Contributors

anandsshah avatar benshep avatar betafcc avatar boydj avatar brezniczky avatar cedric-uden avatar engineerjoe440 avatar henni avatar hhannine avatar rr- avatar rvl avatar stevoisiak avatar tshirtman avatar y-nak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screeninfo's Issues

Get monitor user friendly name

Each monitor returns a name that simply shows \\.\DISPLAY plus numbers, it is difficult to tell which one, after more than an hour of query, finally got the windows platform display specific model acquisition method, the code is as follows:

cmd = r"""
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi; 
ForEach ($Monitor in $Monitors) 
{ [System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName) }
"""
proc = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
ret = proc.stdout.decode()
print(ret.strip().replace('\x00', '').split())

Maybe the next release can add this 😀

By the way, If you use QT for python development, there is also built-in support for methods for obtaining display information, and qt is cross platform.

dataclasses issues

I have a feeling it has to do with the @dataclass tag above the Monitor class in common.py:

Traceback (most recent call last):
    File "test.py", line 1 in <module>
        from screeninfo import get_monitors
    File "python3/lib/python3.8/site-packages/screeinfo/__init__.py", line 1, in <module>
        from .common import Enumerator, Monitor
    File "python3/lib/python3.8/site-packages/screeinfo/common.py", line 7, in <module>
        class Monitor:
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 958, in dataclass
        return wrap(_cls)
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 950, in wrap
        return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 800, in _process_class
        cls_fields = [_get_field(cls, name, type)
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 800, in <listcomp>
        cls_fields = [_get_field(cls, name, type)
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 659, in _get_field
        if (_is_classvar(a_type, typing)
    File "python3/lib/python3.8/site-packages/dataclasses.py", line 659, in _is_classvar
        return (a_type is typing._ClassVar
AttributeError: module 'typing' has no attribute '_ClassVar'

For some reason my editor seems to have placed an underscore in front of some of the variables. I have looked at the source code and they are not there

No enumerations available: Ubuntu 22.04 on X11

On Ubuntu 22.04 running under X11 (not Wayland).I'm hitting this error as screeninfo is a dependency of https://github.com/threedworld-mit/tdw -- xrandr works fine directly in the command line:

▶︎ python3 -m screeninfo xrandr

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 23, in <module>
    main()
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 18, in main
    for monitor in get_monitors(args.enumerator):
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/screeninfo.py", line 21, in get_monitors
    return list(ENUMERATOR_MAP[Enumerator(name)].enumerate_monitors())
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/enumerators/xrandr.py", line 65, in enumerate_monitors
    xlib = load_library("X11")
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/util.py", line 11, in load_library
    return ctypes.cdll.LoadLibrary(path)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libX11.so.6: cannot open shared object file: No such file or directory


 ▷ python3 -m screeninfo xinerama

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 23, in <module>
    main()
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 18, in main
    for monitor in get_monitors(args.enumerator):
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/screeninfo.py", line 21, in get_monitors
    return list(ENUMERATOR_MAP[Enumerator(name)].enumerate_monitors())
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/enumerators/xinerama.py", line 20, in enumerate_monitors
    xlib = load_library("X11")
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/util.py", line 11, in load_library
    return ctypes.cdll.LoadLibrary(path)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libX11.so.6: cannot open shared object file: No such file or directory

Exception on Raspberry Pi 4

Any chance to support the Raspberry 4?

a common way to check for screen resolution on bullseye is to run fbset -s in the command line. But there i don't get the manufacturer of the screen and other info.

Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from screeninfo import get_monitors
>>> get_monitors()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/screeninfo/screeninfo.py", line 32, in get_monitors
    raise ScreenInfoError("No enumerators available")
screeninfo.common.ScreenInfoError: No enumerators available
>>> 

Function get_monitors() mismatching monitor names and resolutions

I'm trying to get matching monitor names and resolutions per the get_monitors() function. However, I am getting conflicting or inaccurate output.

I have monitor HDMI-0 @ 1920x1080 and DP-4 @ 1280x768. If I specify the Xinerama environment, I get the expected output as indicated in the README (albeit with the exception it doesn't output monitor names)- but, generic usage of get_monitors() doesn't behave the same way.


Code used:

from screeninfo import get_monitors
for monitor in get_monitors():
    print(f"Monitor info: {monitor.name} @ ({monitor.width}x{monitor.height})")

Output:

Monitor info: HDMI-0 @ (1280x768)
Monitor info: DP-4 @ (1920x1080)


At least the raw names are correct, but as previously indicated, the corresponding resolutions are incorrect. As a result I need to do some kind of trickery to work around this. I am unclear if this is intentional or the result of my own system. If there's any relevant information I can provide about my system, please let me know.

Get refresh rate

Hello, could you please implement an attribute called .refresh_rate?
I only managed to get the primary monitor's refresh rate using:

# pip install pywin32
import win32api

device = win32api.EnumDisplayDevices()
settings = win32api.EnumDisplaySettings(device.DeviceName, -1)
hz = settings.DisplayFrequency

print(hz)

I don't know how/if this works on other OSes and with multi-monitor setups.

Install Fails Without Cython

pip install screeninfo fails:

Collecting screeninfo
  Downloading https://files.pythonhosted.org/packages/d1/1d/d9861700fa0692d39f4aaf7233ee3dd9cbebd514546fec9344a824f63af4/screeninfo-0.6.5.tar.gz
Collecting dataclasses (from screeninfo)
  Downloading https://files.pythonhosted.org/packages/26/2f/1095cdc2868052dd1e64520f7c0d5c8c550ad297e944e641dbf1ffbb9a5d/dataclasses-0.6-py3-none-any.whl
Collecting Cython (from screeninfo)
  Downloading https://files.pythonhosted.org/packages/a4/87/d7431a94c7c438af66a91d63089be82cf0a5cb924fe2f74197c539f03568/Cython-0.29.20-cp37-cp37m-macosx_10_9_x86_64.whl (1.9MB)
     |████████████████████████████████| 1.9MB 2.7MB/s 
Collecting pyobjus (from screeninfo)
  Downloading https://files.pythonhosted.org/packages/cb/9e/6425d66cf66892ee99ebdc86204c825d6817458328b6cdc3a6c51ad152d1/pyobjus-1.1.0.tar.gz (72kB)
     |████████████████████████████████| 81kB 12.7MB/s 
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/1t/vl1r8xk10knf16xjsg61zn580000gn/T/pip-install-bi_2vyd6/pyobjus/setup.py", line 18, in <module>
        from Cython.Distutils import build_ext
    ModuleNotFoundError: No module named 'Cython'
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/1t/vl1r8xk10knf16xjsg61zn580000gn/T/pip-install-bi_2vyd6/pyobjus/

If I pip install cython, then try again it works.

Python 3.8.x - sometimes fails

monitors = screeninfo.get_monitors()
print(monitors)

This will, for some reason, in Python 3.8.1 on windows 10 64Bit, sometimes fail. Not always. The way it fails is, that it returns an empty list.

Running the same code results in varying results, even in console:

image

It works fine on Python 3.7.6

get_monitors returns empty on osx when Enumerator not explicitly provided

tl;dr:

>>> from screeninfo import get_monitors, Enumerator
>>> get_monitors()
[]
>>> get_monitors(Enumerator.OSX)
[Monitor(x=0, y=0, width=1680, height=1050, width_mm=None, height_mm=None, name=None)]

On those lines:
https://github.com/rr-/screeninfo/blob/master/screeninfo/screeninfo.py#L29-L33

    for enumerator in Enumerator:
        try:
            return _get_monitors(enumerator)
        except Exception:
            pass

Seems some of the previous enumerator is not raising, so it returns before trying OSX, one solution is to also check for empty return on that try/catch

Breaking Python 2.7

The changes that were made a few hours ago, specifically common.py, break Python 2.7.

dataclasses module not found

I installed the module via pip and when I run from screeninfo import get_monitors I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/screeninfo/__init__.py", line 1, in <module>
    from .common import Enumerator, Monitor
  File "/usr/local/lib/python3.6/dist-packages/screeninfo/common.py", line 3, in <module>
    from dataclasses import dataclass
ModuleNotFoundError: No module named 'dataclasses'

Is there a way to solve that?

Exception: Xinerama is not active

Hi,
this is a really special request since I am working with a production server that runs Debian Jeesie, python 3.4 and screeninfo 0.2.2. I am not allowed to update packages in there so I know this is going to be challenging.

Basically, we have a GUI that should run on a physical screen. This specific system does not have a physical screen connected, however X11 is running and I can take screenshots graphical programs like xterm.

However, when I run the app in this headless server I get the following error:

Traceback (most recent call last): 
 File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
   "__main__", mod_spec)
 File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
   exec(code, run_globals)
 File "tools/start_webview.py", line 50, in <module>
 File "tools/start_webview.py", line 27, in run
 File "/usr/local/lib/python3.4/dist-packages/screeninfo/screeninfo.py", line 192, in get_monitors
   return chosen.get_monitors()
 File "/usr/local/lib/python3.4/dist-packages/screeninfo/screeninfo.py", line 144, in get_monitors
   raise Exception('Xinerama is not active')
Exception: Xinerama is not active

I have tried to enable Xinerama on xorg.conf:

Section "ServerLayout" 
       Identifier     "X.org Configured"
       Screen      0  "Screen0" 0 0
       InputDevice    "Mouse0" "CorePointer"
       InputDevice    "Keyboard0" "CoreKeyboard"
       Option "Xinerama" "1"
EndSection 

And then systemctl restart display-manager. It is using slim. I even restarted the whole server since the issue persisted.

When I run just scrot, I get the following message giblib error: Can't open X display. It *is* running, yeah?but by googling a little bit I managed to make it work by setting the display environment variable for the command like this: DISPLAY=:0 scrot.

Any help to figure out what is going on with this error is more than welcome. I am quite new with trying to launch virtual displays on headless servers.

WSL

On windows sub system for linux it throws an enumeration error.

I often have 2 venvs. a winvenv and venv. The problem with WSL is the ctypes.windll are not avaible. but neither is xrandr

I noticed the only way to do it then was to call to the host from shell to get a value. maybe you could subproccess.?

cmd.exe /c wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value

but that doesn't get the additonal connected monitors only the main one. Let me know if I can assist.

screeninfo could not find dataclasses in python 3.8

Hello,

I tried to use superpaper which depend on screeninfo.
https://github.com/hhannine/superpaper
hhannine/superpaper#39

However, there seems to be an issue where screeninfo could not find dataclasses in python 3.8.
From the link below, dataclasses was merge to python 3.7.
https://pypi.org/project/dataclasses/

Traceback (most recent call last):
  File "/usr/bin/superpaper", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3252, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3235, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3264, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'dataclasses' distribution was not found and is required by screeninfo

Thanks.

python3.5 support

How can I use screeninfo in python 3.5? It seems that the type-checking is invalid in python3.5. Could you help me?

customdisplayprofiles current-path not work

Hi,

When i execute this code in python, the program return this message:

Python Code

colorProfilePath = subprocess.check_output("./customdisplayprofiles current-path", shell=True)

Error

/bin/sh: ./customdisplayprofiles: No such file or directory
Traceback (most recent call last):
  File "/Users/carlosfernandezcabrero/Desktop/useful-scripts/monitors-resolution.py", line 9, in <module>
    colorProfilePath = subprocess.check_output("./customdisplayprofiles current-path", shell=True)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command './customdisplayprofiles current-path' returned non-zero exit status 127.

Operating System: macOS
Operating System Version: macOS Monterey 12.1
Python Version: 3.9.9
Package Version: 0.8

Regards thank you very much

View disabled monitors?

Is there a way to enumerate disable monitors as well as enabled ones? (Looking for on Windows).

Getting No Enumerators Available error when running on pygbag

I'm making a tower defense game and am trying to build it with pygbag for the web. I'm using screeninfo to make to window fullscreen. First build attempt, it can't find screeninfo. No problem. I download the source code of screeninfo. Put it into the folder and build. This time, I get "screeninfo.common.ScreenInfoError: No enumerators available". I think this might be due to pygbag running in an unsupported environment although I can't be sure.

Behavior of get_monitors()

Hello,
I see that the example showing multiple monitors but doesn't specify any differences between them. So I would like to ask: If there are two monitors both available at the same time but only one is active, can we get that specific monitor?

Error when screen inactive.

I seem to get an error when I have a connected, but inactive monitor:

VGA1 Active

[evan@blackbox ~] xrandr
Screen 0: minimum 8 x 8, current 2624 x 900, maximum 32767 x 32767
LVDS1 connected primary 1600x900+1024+0 (normal left inverted right x axis y axis) 310mm x 170mm
   1600x900      60.01*+  59.82    40.00  
   1400x900      59.96    59.88  
   1368x768      60.00    59.88    59.85  
   1280x800      59.81    59.91  
   1280x720      59.86    60.00    59.74  
   1024x768      60.00  
   1024x576      60.00    59.90    59.82  
   960x540       60.00    59.63    59.82  
   800x600       60.32    56.25  
   864x486       60.00    59.92    59.57  
   800x450       60.00  
   640x480       59.94  
   720x405       59.51    60.00    58.99  
   640x360       59.84    59.32    60.00  
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 300mm x 230mm
   1024x768      75.03*+  70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   640x480       75.00    72.81    66.67    59.94  
   720x400       70.08  
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
In [2]: get_monitors()
Out[2]: 
[Monitor(x=1024, y=0, width=1600, height=900, name='LVDS1'),
 Monitor(x=0, y=0, width=1024, height=768, name='VGA1')]

VGA1 Inactive

[evan@blackbox ~] xrandr
Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
LVDS1 connected primary 1600x900+0+0 (normal left inverted right x axis y axis) 310mm x 170mm
   1600x900      60.01*+  59.82    40.00  
   1400x900      59.96    59.88  
   1368x768      60.00    59.88    59.85  
   1280x800      59.81    59.91  
   1280x720      59.86    60.00    59.74  
   1024x768      60.00  
   1024x576      60.00    59.90    59.82  
   960x540       60.00    59.63    59.82  
   800x600       60.32    56.25  
   864x486       60.00    59.92    59.57  
   800x450       60.00  
   640x480       59.94  
   720x405       59.51    60.00    58.99  
   640x360       59.84    59.32    60.00  
VGA1 connected (normal left inverted right x axis y axis)
   1024x768      75.03 +  70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   640x480       75.00    72.81    66.67    59.94  
   720x400       70.08  
In [3]: get_monitors()
X Error of failed request:  BadRRCrtc (invalid Crtc parameter)
  Major opcode of failed request:  139 (RANDR)
  Minor opcode of failed request:  20 (RRGetCrtcInfo)
  Crtc id in failed request: 0x0
  Serial number of failed request:  15
  Current serial number in output stream:  15

osx support through pyobjus?

Not doing a PR yet, but if you are ok with that, support should be simple to add through PyOBJus, i have some custom code in my app to do that.

      from pyobjus import autoclass
      from pyobjus.dylib_manager import load_framework, INCLUDE
      load_framework(INCLUDE.AppKit)
      try:
          s = autoclass('NSScreen').screens().objectAtIndex_(0).frame.size
      except AttributeError:
          s = autoclass('NSScreen').screens().objectAtIndex_(0).frame().size
      return s.width, s.height

that returns the dimensions of the main screen, but can return of any screen, complete support should be easy enough to add when i have more time.

No monitor physical dimensions on MacOS

On MacOS 13.5, the height_mm and width_mm fields of the monitor info are reported as None.

I saw that you're not doing OSX dev; but I figured I'd throw this here to track the issue anyways.

Wrong resolution on Windows when scaled

I have two monitors on a Windows 10 laptop. The inbuilt display is set to 125% scale in Settings - see pic. But screeninfo gives the wrong resolution - it scales it by 125% and returns 1536x864 instead of 1920x1080. Can I have it return an unscaled resolution please?

image

Ubuntu 22.04: No enumerators available

On Ubuntu 22.04 running under X11 (not Wayland), with screeninfo 0.8.1.

I'm hitting this error as screeninfo is a dependency of https://github.com/threedworld-mit/tdw -- xrandr works fine directly in the command line...

▶︎ python3 -m screeninfo xrandr

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 23, in <module>
    main()
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 18, in main
    for monitor in get_monitors(args.enumerator):
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/screeninfo.py", line 21, in get_monitors
    return list(ENUMERATOR_MAP[Enumerator(name)].enumerate_monitors())
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/enumerators/xrandr.py", line 65, in enumerate_monitors
    xlib = load_library("X11")
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/util.py", line 11, in load_library
    return ctypes.cdll.LoadLibrary(path)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libX11.so.6: cannot open shared object file: No such file or directory
 ▷ python3 -m screeninfo xinerama

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 23, in <module>
    main()
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/__main__.py", line 18, in main
    for monitor in get_monitors(args.enumerator):
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/screeninfo.py", line 21, in get_monitors
    return list(ENUMERATOR_MAP[Enumerator(name)].enumerate_monitors())
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/enumerators/xinerama.py", line 20, in enumerate_monitors
    xlib = load_library("X11")
  File "/home/cog5/.virtualenvs/tdw/lib/python3.10/site-packages/screeninfo/util.py", line 11, in load_library
    return ctypes.cdll.LoadLibrary(path)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libX11.so.6: cannot open shared object file: No such file or directory

Installation on Windows fails due to Pyobjus

Tried installing this package using Poetry, and I keep getting the following error:

[NotADirectoryError]
[WinError 267] The directory name is invalid: 'C:\\Users\\sghavam\\AppData\\Local\\Temp\\tmp56okfexg\\unpacked\\pyobjus-1.1.0\\objc_classes\\aux'

Folders named aux (among others) are not permitted on Windows platforms so the installation fails.

`is_primary` boolean for Monitor objects

Hello everyone,

I am interested in using this code in a project of mine, however, I would need a way to recognize the primary displays of a user.
My idea was to add a is_primary boolean for Monitor objects which is returned when calling the get_monitors() function.

If this is something you approve of, I would implement this for all the supported environments and create a pull request. If not, I would simply fork this and add the functionality on my own.

Thank you and have a nice day

Pull specific values from Monitor X

get-_monitors output is type is 'list' with length of one '1' and short of pulling in string methods to get what I need is there another way to pull values from the output of get_monitors - specifically W & H? I would use the values directly in writing another function on top for use with image libraries.

Screen size returned on MacBook Pro with Retina display (macOS BigSur) is wrong.

I just installed screeninfo to test it on my laptop as on paper it does exactly what I am looking for: find the screen size regardless of the platform (Windows, macOS, Linux). I simply ran the small code snippet provided on Pypi.

from screeninfo import get_monitors
for m in get_monitors():
    print(str(m))

You can find the output below. For the build-in Retina display, the resolution is wrong.

Screenshot 2021-06-15 at 16 41 08

`y` for a secondary monitor has a different meaning in darwin vs other systems

I'm working with screeninfo + pyautogui. My code was working fine on Windows, but when I moved to MacOS, I noticed it would only work in my primary monitor (where y=0), not in other monitors. Pyautogui would move the cursor to the wrong coordinates.

The reason:

  • In Windows (and probably Linux), mon.y is the position of the top of the monitor mon relative to the top of the primary monitor. Above primary monitor is negative, below is positive*.
  • In MacOS, mon.y is the position of the bottom of the monitor mon relative to the bottom of the primary monitor. Above primary monitor is positive, below is negative*.

* I think. I'm only submitting the issue today, but I encountered this issue months ago when I actually had an external monitor. My memory might be wrong, and I don't have another monitor anymore to confirm.

Pyautogui uses the Windows' meaning of y in all systems (afaik). I looked into pyautogui's code, but it doesn't seem to make any computations on y, it just passes it straight to the "internal" (Quartz) functions. It uses Quartz underneath though, and I didn't check what Quartz does.

I ended up solving my problem with:

xplatform_y = primary_mon.height - (mon.y + mon.height) if sys.platform == "darwin" else mon.y

Unsure which approach you'd rather take here. Add another field to Monitor for this y? Add a @property? Add some documentation explaining this distinction in semantics?

Invalid syntax error on OSX with Python 3.5

When I try using the latest version, I get the following error. This error shows up all the way back to version 0.3.1 :

  File "/Users/vik748/anaconda3/envs/mb_pc_env/lib/python3.5/site-packages/screeninfo/__init__.py", line 1, in <module>
    from .common import Enumerator, Monitor
  File "/Users/vik748/anaconda3/envs/mb_pc_env/lib/python3.5/site-packages/screeninfo/common.py", line 10
    x: int
     ^
SyntaxError: invalid syntax

Fails on Linux under cron

I'm using this in a Python script that changes the wallpaper. I've got this set up as a cron job so that it runs on a timer. But it fails with a "Could not open display" exception. Any idea what I should do to make it work?

Fall back on Windows if X11 fails

I have Windows 7, and I occasionally use an X11 client (MobaXTerm). I think this has resulted in my DISPLAY environment variable being set. But I don't have a running X server, so screeninfo fails when it tries to find it (ImportError: Could not load X11). The 'standard' ctypes method works fine. Could you either:

  • Re-order the detection so that it uses the MonitorEnumeratorWindows class in preference to MonitorEnumeratorX11
  • Add a parameter to get_monitors to force a particular platform
  • Fall back to MonitorEnumeratorWindows when X11 can't be loaded (perhaps by adding more cleverness to the detect code).

The last one would be my preference, but the other two would be much simpler to implement!

Thanks

Ben

"No enumerators available" - on macOS

I am getting the below error when ran on macOS

>>> from screeninfo import get_monitors
>>> get_monitors()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yash/workspace/projects/unsplash-wallpaper/lib/python3.7/site-packages/screeninfo/screeninfo.py", line 37, in get_monitors
    raise ScreenInfoError("No enumerators available")
screeninfo.common.ScreenInfoError: No enumerators available

python version - 3.7.7
screeninfo version - 0.6.1
macOS catalina version - 10.15.3 (19D76)

Problem with dearpygui

It seems that call to ctypes.windll.shcore.SetProcessDpiAwareness(2) breaks scaling in dearpygui https://github.com/hoffstadt/DearPyGui, see this example (dearpygui 1.8.0) and calling ctypes.windll.shcore.SetProcessDpiAwareness(0) won't help:

import ctypes
import dearpygui.dearpygui as dpg
from screeninfo import screeninfo

dpg.create_context()
dpg.create_viewport(title='Custom Title', width=600, height=300, decorated=False)

with dpg.window(label="Example Window"):
    dpg.add_text("Hello, world")
    dpg.add_button(label="Save")
    dpg.add_input_text(label="string", default_value="Quick brown fox")
    dpg.add_slider_float(label="float", default_value=0.273, max_value=1)

# calling either of
#     screeninfo.get_monitors()
# or
#     ctypes.windll.shcore.SetProcessDpiAwareness(2)
# inevitably changes viewport scale

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

possible GDI Object leak on Windows

Every time get_monitors() is called, the GDI Objects count for the python process on win32 increases.
Once the 10,000 GDI Object hard limit is reached, the desktop becomes lagged, and GUI things break (my script is managing an application's full-screen status, and the result is a corrupted / not-fully-repainted window).

A small test, if you add the GDI Objects column to taskmgr, you can see the count continually increase.

while True:
    for m in get_monitors():
        print(str(m))

Is this broken on Windows 10?

I'm using screeninfo on Win7 with excellent results (thank you!!)

However, when I try to run it on either of my Win10 (Pro 64 bit if it matters) boxes, I get an empty list "[]" returned when I try to call get_monitors().

I don't know enough about the Win32 libs to debug what is going-on, so I come offering only a problem and no solution :( Perhaps you can help?

Thanks!

"No enumerators available" when running in docker container

When I call get_monitors() from inside a docker container, I received the following error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/screeninfo/screeninfo.py", line 29, in get_monitors
    raise ScreenInfoError("No enumerators available")
screeninfo.common.ScreenInfoError: No enumerators available

Steps to reproduce the problem
Environment: Ubuntu 18.04

$ docker run -it --rm python:3 bash
root@5611d6f56e39:/# pip install screeninfo
root@5611d6f56e39:/# python
>>> from screeninfo import get_monitors
>>> m = get_monitors()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/screeninfo/screeninfo.py", line 29, in get_monitors
    raise ScreenInfoError("No enumerators available")
screeninfo.common.ScreenInfoError: No enumerators available

No errors if run from Ubuntu shell.

Feature suggestion: Fetching physical size data from monitors

First of all, thank you kindly for creating this useful tool! I'm using it in Superpaper. I'm looking into automating some of the config out of the users hands and this would need the automatic detection of the display height and width in millimeters, inches etc.; or the detection of the monitor pixel density PPI directly.

Would you think that extension of screeninfo to report these additional data would be appropriate? If it could be considered there's of course the question of how to get at the data. On linux at least xrandr seems to report the width and height in millimeters. On the other hand, on Windows I haven't been able to find any easy way to get at it and with my limited understanding one way would be to read cached EDID data out of the registry.

"no enumerators available" on Linux MInt 20.1

Hi,

I've been trying to get this obs plugin to work:
https://github.com/tryptech/obs-zoom-and-follow

I've installed screeninfo today from pypi, using pip3, with the --user option.

But after including the script into obs, and then starting up obs, it gives me the following message on Linux Mint 20.1 Xfce:

[zoom_and_follow_mouse.py] Traceback (most recent call last):
[zoom_and_follow_mouse.py]   File "/home/username/.config/obs-studio/scripts/obs-zoom-and-follow-master/zoom_and_follow_mouse.py", line 19, in <module>
[zoom_and_follow_mouse.py]     class CursorWindow:
[zoom_and_follow_mouse.py]   File "/home/username/.config/obs-studio/scripts/obs-zoom-and-follow-master/zoom_and_follow_mouse.py", line 26, in CursorWindow
[zoom_and_follow_mouse.py]     d_w = get_monitors()[monitor_idx].width
[zoom_and_follow_mouse.py]   File "/home/username/.local/lib/python3.8/site-packages/screeninfo/screeninfo.py", line 37, in get_monitors
[zoom_and_follow_mouse.py]     raise ScreenInfoError("No enumerators available")
[zoom_and_follow_mouse.py] screeninfo.common.ScreenInfoError: No enumerators available

I'm having two monitors attached, configured from the Xfce settings. Please let me know which information you would need to help fix the problem.

Screeninfo displays wrong information since desktopmagic

Hey there

This seems to be a little buggy,

If I call screeninfoi.get_monitors() in for example a python shell, I get

[Monitor(x=0, y=0, width=1920, height=1080, width_mm=344, height_mm=194, name='\\\\.\\DISPLAY1'), Monitor(x=1920, y=0, width=1920, height=1080, width_mm=531, height_mm=299, name='\\\\.\\DISPLAY2')]

which is completly fine and correct but If I call it in my project then I get the following output:

[Monitor(x=0, y=0, width=1920, height=1080, width_mm=344, height_mm=194, name='\\\\.\\DISPLAY1'), Monitor(x=2400, y=0, width=2400, height=1350, width_mm=531, height_mm=299, name='\\\\.\\DISPLAY2')]

this seems to only occur when I'm using desktopmagic... Well somehow yes and somehow no. Is desktopmagic affecting that?

Import Error for X11

Getting the following error on mac systems:

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/screeninfo/screeninfo.py", line 166, in get_monitors
    return chosen.get_monitors()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/screeninfo/screeninfo.py", line 135, in get_monitors
    xlib = load_library('X11')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/screeninfo/screeninfo.py", line 123, in load_library
    raise ImportError('Could not load ' + name)
ImportError: Could not load X11

Any Ideas?

Is there a way to do this without having X11 installed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.