Python Forum
Looking for platform test help
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for platform test help
#11
The following is corrected:
import screeninfo import re import sys """ GetScreenInfo() cross platform creates a dictionary with an entry for each monitor tied to users computer. the key is constructed as follows:    monitor{n} n is sequentiallty assigned beginning with 1 Usage: GetScreenInfo(win_scale=.6, offset_scale=.1)    where: scale is % of full screen, so default .6 = 60 % and           offset is % of scaled width & height each entry contains a nested dictionary with four values:    swidth = scaled_width    sheight = scaled height    hoffset = horizontal offset    voffset = vertical offset4 example: >>> from GetScreenInfo import GetScreenInfo >>> gsi = GetScreenInfo(win_scale=.8, offset_scale=.2) >>> print(gsi.monitor_info) >>> {'monitor1': {'swidth': 1920, 'sheight': 1080, 'hoffset': 384, 'voffset': 216}}    {'monitor1': {'swidth': 1920, 'sheight': 1080, 'hoffset': 384, 'voffset': 216}} Tested on Windows 7 with python 3.6 Needs testing on Linux and Apple """ class GetScreenInfo():    def __init__(self, win_scale=.6, offset_scale=.1):        # use scale of 0 to return unmodified dimensions        if win_scale == 0:            newscale = 1            newoffset = 0        else:            newscale = win_scale            newoffset = offset_scale        platform = sys.platform        platform = platform.rstrip('1234567890')        self.monitor_info = {}        ostypes = {            'linux': 'x11',            'win': 'windows',            'cygwin': 'cygwin',            'darwin': 'osx'        }        # Following hack is for return proper linux value from sys.platform        #  prior to python 3.3 which always starts with 'linux' but may        #  be linux1, linux2 etc.        if platform.startswith('linux'):            montype = ostypes['linux']        mon = screeninfo.get_monitors(ostypes[platform])        print(f'mon: {mon}')        for n, item in enumerate(mon):            m = re.split(r'[()x+]', str(item))            mkey = 'monitor{}'.format(n+1)            self.monitor_info[mkey] = {}            self.monitor_info[mkey]['swidth'] = int(float(m[1]) * newscale)            self.monitor_info[mkey]['sheight'] = int(float(m[2]) * newscale)            self.monitor_info[mkey]['hoffset'] = int(float(m[1]) * newoffset)            self.monitor_info[mkey]['voffset'] = int(float(m[2]) * newoffset) def main(scale, offset):    gsi = GetScreenInfo(win_scale=scale, offset_scale=offset)    print(gsi.monitor_info) if __name__ == '__main__':    main(scale=.8, offset=.2)
result:
Output:
mon: [monitor(1920x1080+0+0)] {'monitor1': {'swidth': 1536, 'sheight': 864, 'hoffset': 384, 'voffset': 216}}
Reply
#12
This is exactly what I get:

[Image: wiwry7xQT6Ky4dQXPCFnhQ.png]

https://prnt.sc/fsjbqq

https://prnt.sc/fsjd85

Why the image is broken
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#13
(Jul-06-2017, 09:01 PM)wavic Wrote: Why the image is broken
it appears that prnt.sc isnt working with img tags?
[Image: wiwry7xQT6Ky4dQXPCFnhQ.png]

but yet imgur works
[Image: dgrCwVq.jpg]

not sure? Although you could always upload the image as an attachment which shows it in post.
Recommended Tutorials:
Reply
#14
Know you were asking for Linux and Mac, but I have Windows on right now Big Grin

Output:
Windows 10; Python 3.6; Single LCD Monitor mon: [monitor(1920x1080+0+0)] {'monitor1': {'swidth': 1536, 'sheight': 864, 'hoffset': 384, 'voffset': 216}} Process finished with exit code 0 ########## Switched screen size mon: [monitor(800x600+0+0)] {'monitor1': {'swidth': 640, 'sheight': 480, 'hoffset': 160, 'voffset': 120}} Process finished with exit code 0
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#15
Thanks all.
I think it's working ok now.
Reply


User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.