Skip to content

Commit

Permalink
fix: compatibility with Python 3.10 and 3.11
Browse files Browse the repository at this point in the history
* Fix BoundsEditor by patching RangeSlider
  (enthought/traitsui#1906)
* Update versions of dependencies
  • Loading branch information
osthomas committed Nov 13, 2023
1 parent 07779a8 commit 74bd905
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.6

* Fix: compatibility with Python 3.10 and 3.11 (#3)
42 changes: 40 additions & 2 deletions optoConfig96/editors/bounds_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
Furthermore, this suffers from the same limitation as the range editor:
Entering commas treats the value as tuple, not a decimal number, which
raises an unhandled TypeError - fixed here.
Also handles explicitly casting slider values to int for dependency with
Python>=3.10
"""

import six

from traitsui.qt4.extra.bounds_editor import _BoundsEditor as _OriginalBoundsEditor
from traitsui.qt4.extra.bounds_editor import BoundsEditor as OriginalBoundsEditor
from traitsui.qt4.extra.range_slider import RangeSlider as OriginalRangeSlider


class _BoundsEditor(_OriginalBoundsEditor):
Expand All @@ -68,7 +71,42 @@ def update_high_on_enter(self):
super().update_high_on_enter()


class BoundsEditor(OriginalBoundsEditor):
class RangeSlider(OriginalRangeSlider):
"""
Add additional indirection to the RangeSlider class in order to explicitly
cast values to int.
Fix for: https://github.com/enthought/traitsui/issues/1906
"""

@property
def _low(self):
try:
return int(self.__low)
except TypeError:
return self.__low

@_low.setter
def _low(self, value):
self.__low = value

@property
def _high(self):
try:
return int(self.__high)
except TypeError:
return self.__high

@_high.setter
def _high(self, value):
self.__high = value


# Dependency injection of fixed RangeEditor
from traitsui.qt4.extra import bounds_editor as DI_bounds_editor
DI_bounds_editor.RangeSlider = RangeSlider


class BoundsEditor(DI_bounds_editor.BoundsEditor):
def _get_simple_editor_class(self):
return _BoundsEditor

Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Operating System :: OS Independent',
],
keywords='biology optogenetics optoplate gui',
install_requires=[
'traits>=6.2.0',
'traitsui>=7.2.1',
'traits>=6.2.0,<7.0',
'traitsui>=7.2.1,<8.0',
'PyQt5>=5.15.4,<=5.15.7',
'pygments>=2.9.0',
'numpy>=1.21.1,<=1.23.5',
Expand All @@ -43,7 +45,7 @@
"pyinstaller>=5.7.0"
]
},
python_requires='>=3.7,<3.10',
python_requires='>=3.7,<3.12',
package_data={
pkg_name: [
'resources/appicon.png',
Expand Down

0 comments on commit 74bd905

Please sign in to comment.