enthought / pyface

pyface: traits-capable windowing framework
Other
104 stars 55 forks source link

Bug report: SystemMetrics error on headless macos #1232

Closed itziakos closed 1 year ago

itziakos commented 1 year ago

Environment

OS: Mac 12.6.4 Python version: 3.8 Toolkit: Qt Qt API: PySide6

Description

Seen in tests invlding traitsui. Accessing screen_width or screen_height on a macos system logged in through ssh (i.e. there is no user logged in the windows desktop).

[2023-03-30T19:40:42.035Z]     from traitsui.qt4.table_editor import TableView
[2023-03-30T19:40:42.035Z]   File "/Users/builder/.edm/envs/build-env/lib/python3.8/site-packages/traitsui/qt4/table_editor.py", line 69, in <module>
[2023-03-30T19:40:42.035Z]     from .editor import Editor
[2023-03-30T19:40:42.035Z]   File "/Users/builder/.edm/envs/build-env/lib/python3.8/site-packages/traitsui/qt4/editor.py", line 33, in <module>
[2023-03-30T19:40:42.035Z]     from .constants import OKColor, ErrorColor
[2023-03-30T19:40:42.035Z]   File "/Users/builder/.edm/envs/build-env/lib/python3.8/site-packages/traitsui/qt4/constants.py", line 66, in <module>
[2023-03-30T19:40:42.035Z]     screen_dx = SystemMetrics().screen_width
[2023-03-30T19:40:42.035Z]   File "/Users/builder/.edm/envs/build-env/lib/python3.8/site-packages/pyface/ui/qt4/system_metrics.py", line 47, in _get_screen_width
[2023-03-30T19:40:42.035Z]     return QtGui.QApplication.instance().screens()[0].availableGeometry().width()
[2023-03-30T19:40:42.035Z] IndexError: list index out of range

Steps to Reproduce

On a macos system without any user logged into the windows manager desktop.

from pyface.api import SystemMetrics
SystemMetrics().screen_width