spacether/pycalculix

Environment get_dpi() issue on Windows XP and probably also Linux

Closed this issue · 3 comments

I am getting:
File "C:\Anaconda3\lib\site-packages\pycalculix-0.9.3-py3.4.egg\pycalculix\environment.py", line 55, in
DPI = get_dpi()

File "C:\Anaconda3\lib\site-packages\pycalculix-0.9.3-py3.4.egg\pycalculix\environment.py", line 18, in get_dpi
if float(platform.release()) >= 8:

ValueError: could not convert string to float: 'XP'

Solution:
in environment.py add try: clause, like:

    try:
        if float(platform.release()) >= 8:
            # Only run on windows 8 or higher to check high dpi monitors

            import ctypes
            user32 = ctypes.windll.user32
            w_curr = user32.GetSystemMetrics(0)
            user32.SetProcessDPIAware()
            w_phys = user32.GetSystemMetrics(0)
            curr_dpi = round(w_phys*96/w_curr, 0)

            from pylab import rcParams
            rcParams['figure.dpi'] = curr_dpi
            return curr_dpi
    except:
        pass

This is not a Linux issue, just non-numeric windows versions.
Current code correctly returns None as DPI if the system is non-windows.
This is a windows only fix for high DPI monitors (mine):

Current Code:

def get_dpi():
    """Returns an int of current DPI for windows or None."""
    if platform.system() == 'Windows':
        if float(platform.release()) >= 8:
            # Only run on windows 8 or higher to check high dpi monitors

            import ctypes
            user32 = ctypes.windll.user32
            w_curr = user32.GetSystemMetrics(0)
            user32.SetProcessDPIAware()
            w_phys = user32.GetSystemMetrics(0)
            curr_dpi = round(w_phys*96/w_curr, 0)

            from pylab import rcParams
            rcParams['figure.dpi'] = curr_dpi
            return curr_dpi
    else:
        return None

I missed platform. system check, but anyway:

I do not know if you have plan to support Windows XP, but running Pycalculix on it returns error, because platform is Windows.

if float(platform.release()) >= 8:

of course than returns error.

Issue fixed in below commit:
cf096e4
Added code which checks if windows version >= 6.2 (6.2 = Windows 8.0 version major.minor)