Skip to content

Commit

Permalink
Add a check and a fallback for obviously erroneous dpi
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Jan 9, 2024
1 parent 5fa8ba5 commit 287ba08
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/silx/gui/_glutils/OpenGLWidget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2017-2022 European Synchrotron Radiation Facility
# Copyright (c) 2017-2023 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -353,13 +353,17 @@ def getDotsPerInch(self):
:rtype: float
"""
screen = self.window().windowHandle().screen()
if screen is not None:
# TODO check if this is correct on different OS/screen
# OK on macOS10.12/qt5.13.2
dpi = screen.physicalDotsPerInch() * self.getDevicePixelRatio()
else: # Fallback
dpi = 96.0 * self.getDevicePixelRatio()
return dpi
if screen is None:
return 96.0 * self.getDevicePixelRatio()

physicalDPI = screen.physicalDotsPerInch()
if physicalDPI > 1000.0:
_logger.error(
"Reported screen DPI too high: %f, using default value instead",
physicalDPI,
)
physicalDPI = 96.0
return physicalDPI * self.getDevicePixelRatio()

def getOpenGLVersion(self):
"""Returns the available OpenGL version.
Expand Down

0 comments on commit 287ba08

Please sign in to comment.