Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get monitor user friendly name #50

Open
BruceLee569 opened this issue May 2, 2021 · 4 comments
Open

Get monitor user friendly name #50

BruceLee569 opened this issue May 2, 2021 · 4 comments

Comments

@BruceLee569
Copy link

BruceLee569 commented May 2, 2021

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.

@ReenigneArcher
Copy link

+1 for this

@gitagogaming
Copy link

+1 for this as well, would be great to be able to access this with screeninfo

@KillerBOSS2019
Copy link

+1 for this too

@nsde
Copy link

nsde commented Apr 6, 2023

Thanks for providing the code snippet!
Mi Monitor sounds much better than \\\\.\\DISPLAY1.

I know this isn't going to be implemented, as this is way too much bloat for a simple screen info checker. But for anyone interested – I'd just like to mention that using the following script, you can get the actual monitor name:

import wmi
import bs4
import requests

from pprint import pprint

wmi_ = wmi.WMI() 

for monitor in wmi_.Win32_DesktopMonitor():
    monitor_code = monitor.PNPDeviceID.split('\\')[1]
    # monitor_code = 'gbt2701'
    url = f'https://linux-hardware.org/?view=search&name={monitor_code}#list'

    # get the HTML
    html = requests.get(url=url, timeout=10, headers={'User-Agent': 'Mozilla'}).text

    soup = bs4.BeautifulSoup(html, 'html.parser')

    # get the table
    table = soup.select_one('#devices.tbl.highlight.dev_info.dev_list')

    device = table.select_one('td.device').text.split('-inch')[0].replace('.0', '') + '"'
    brand = table.select_one('td.vendor').text

    # now turn the table into a dictionary
    specs = {
        'code': monitor_code,
        'product': ' '.join(device.split()[:-4]),
        'resolution': device.split()[-3],
        'size': device.split()[-2],
        'inches': float(device.split()[-1].replace('"', '')),
        'brand': brand,
    }

    pprint(specs)

Which returns something like:

{
    'brand': 'Gigabyte Technology',
    'code': 'gbt2701',
    'inches': 27.8,
    'product': 'AORUS AD27QD',
    'resolution': '2560x1440',
    'size': '609x355mm'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants