Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QtGui.QStyleOptionSlider: implicit conversion to float fails with Python 3.10 #1906

Open
osthomas opened this issue Mar 2, 2022 · 2 comments · May be fixed by #2048
Open

QtGui.QStyleOptionSlider: implicit conversion to float fails with Python 3.10 #1906

osthomas opened this issue Mar 2, 2022 · 2 comments · May be fixed by #2048

Comments

@osthomas
Copy link

osthomas commented Mar 2, 2022

With Python 3.10, using a traitsui BoundsEditor for a Range fails:

from traits.api import *
from traitsui.api import *
from traitsui.qt4.extra.bounds_editor import BoundsEditor


class Test(HasTraits):
    val = Range(0.3, 10.5)

    _xmin = Float(5.0)
    _xmax = Float(10.0)

    view = View(
        UItem(
            'val',
            editor=BoundsEditor(
                low_name='_xmin',
                high_name='_xmax',
                format='%.2f')
        )
    )

Test().configure_traits()
Traceback (most recent call last):
  File ".../lib/python3.10/site-packages/traitsui/qt4/extra/range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer

The same code works in Python 3.9.

In range_slider.py, the slider position appears to be set like so:

opt = QtGui.QStyleOptionSlider()
opt.sliderPosition = value

This appears to be the reason for the failure because value is a float and implicit conversion fails in Python 3.10.

Python 3.9

Python 3.9.10 (main, Mar  2 2022, 14:03:08) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyface.qt import QtGui
>>> QtGui.QStyleOptionSlider().sliderValue = 5
>>> QtGui.QStyleOptionSlider().sliderValue = 5.5
<stdin>:1: DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

Python 3.10

Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyface.qt import QtGui
>>> QtGui.QStyleOptionSlider().sliderValue = 5
>>> QtGui.QStyleOptionSlider().sliderValue = 5.5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
@corranwebster corranwebster transferred this issue from enthought/pyface Jun 21, 2022
@corranwebster
Copy link
Contributor

This is a traitsui issue - there's nothing that the Pyface code can do to fix this.

@corranwebster
Copy link
Contributor

Thanks for the comprehensive report!

yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Dec 31, 2022
- Add Python 3.10, though the GUI currently cannot load because of TraitsUI issue enthought/traitsui#1906
- Add Python 3.10-3.11 custom dependency support
yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Feb 3, 2023
- Add Python 3.10, though the GUI currently cannot load because of TraitsUI issue enthought/traitsui#1906
- Add Python 3.10-3.11 custom dependency support
osthomas added a commit to osthomas/optoConfig-96-build-test that referenced this issue Nov 13, 2023
* Fix BoundsEditor by patching RangeSlider
  (enthought/traitsui#1906)
* Update versions of dependencies
osthomas added a commit to osthomas/optoConfig-96-build-test that referenced this issue Nov 13, 2023
* Fix BoundsEditor by patching RangeSlider
  (enthought/traitsui#1906)
* Update versions of dependencies
osthomas added a commit to osthomas/optoConfig-96-build-test that referenced this issue Nov 13, 2023
* Fix BoundsEditor by patching RangeSlider
  (enthought/traitsui#1906)
* Update versions of dependencies
@ericpre ericpre linked a pull request May 6, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants