enthought/pyface

Bug report: AttributeError: type object 'QFont' has no attribute 'Decorative'

opoplawski opened this issue · 3 comments

Environment

OS: Linux
Python version: 3.11
Toolkit: Qt
Qt API: PyQt6

pyface/traitsui 8.0.0

Description

When running the traitsui pyqt6 tests I get:

ERROR: test_create_traitsfont_pyface_font (traitsui.qt.tests.test_font_trait.TestPyQtFont.test_create_traitsfont_pyface_font)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILDROOT/python-traitsui-8.0.0-1.fc39.x86_64/usr/lib/python3.11/site-packages/traitsui/qt/tests/test_font_trait.py", line 89, in test_create_traitsfont_pyface_font
    traits_font = create_traitsfont(font)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-traitsui-8.0.0-1.fc39.x86_64/usr/lib/python3.11/site-packages/traitsui/qt/font_trait.py", line 94, in create_traitsfont
    return TraitsFont(value.to_toolkit())
                      ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pyface/font.py", line 378, in to_toolkit
    font_to_toolkit_font = toolkit_object('font:font_to_toolkit_font')
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pyface/base_toolkit.py", line 127, in __call__
    module = import_module(mname, package)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.11/site-packages/pyface/ui/qt/font.py", line 25, in <module>
    QFont.Decorative: 'fantasy',
    ^^^^^^^^^^^^^^^^
AttributeError: type object 'QFont' has no attribute 'Decorative'

With PyQt6 this is now QFont.StyleHint.Decorative. I don't know how pyface is supposed to handle this difference.

Thanks for the report - due to issues like this PyQt6 is not yet supported.

I think a simple PR to change it to QFont.StyleHint.Decorative would be backward compatible. But it is likely there would be multiple other similar changes. This update process is very hard to automate.

I tried changing it to QFont.StyleHint.Decorative but that seemed to break the Qt5 tests.

A similar problem related to this is:

C:\Users\...\Lib\site-packages\pyface\ui\qt\code_editor\code_widget.py:57: in __init__
    font.setStyleHint(QtGui.QFont.TypeWriter)
E   AttributeError: type object 'QFont' has no attribute 'TypeWriter'