From 74bd905025076f3ef12e9e28b14b1c90c063d433 Mon Sep 17 00:00:00 2001 From: Oliver Thomas Date: Mon, 13 Nov 2023 14:44:28 +0100 Subject: [PATCH] fix: compatibility with Python 3.10 and 3.11 * Fix BoundsEditor by patching RangeSlider (https://github.com/enthought/traitsui/issues/1906) * Update versions of dependencies --- CHANGELOG.txt | 3 ++ optoConfig96/editors/bounds_editor.py | 42 +++++++++++++++++++++++++-- setup.py | 8 +++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e69de29..b404ef5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -0,0 +1,3 @@ +## 1.0.6 + +* Fix: compatibility with Python 3.10 and 3.11 (#3) diff --git a/optoConfig96/editors/bounds_editor.py b/optoConfig96/editors/bounds_editor.py index 04c8c04..27e35c1 100644 --- a/optoConfig96/editors/bounds_editor.py +++ b/optoConfig96/editors/bounds_editor.py @@ -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): @@ -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 diff --git a/setup.py b/setup.py index 16527d4..a308875 100644 --- a/setup.py +++ b/setup.py @@ -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', @@ -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',