Skip to content

Fix slider in image contrast editor on python >=3.10#76

Merged
ericpre merged 6 commits into
hyperspy:mainfrom
ericpre:fix_rangeslider_issue
May 8, 2024
Merged

Fix slider in image contrast editor on python >=3.10#76
ericpre merged 6 commits into
hyperspy:mainfrom
ericpre:fix_rangeslider_issue

Conversation

@ericpre

@ericpre ericpre commented May 6, 2024

Copy link
Copy Markdown
Member

On python 3.10, the slider of the image contrast editor are broken:

import hyperspy.api as hs
import numpy as np

hs.preferences.GUIs.enable_traitsui_gui = True
hs.preferences.GUIs.enable_ipywidgets_gui = False

s = hs.signals.Signal2D(np.random.random(10000).reshape((100, 100)))
s.plot()

Press on h key to open the image contrast editor and the percentile slider are missing.

The error is:

  File "C:\Users\M0041User\mambaforge\lib\site-packages\traitsui\qt4\extra\range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "C:\Users\M0041User\mambaforge\lib\site-packages\traitsui\qt4\extra\range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "C:\Users\M0041User\mambaforge\lib\site-packages\traitsui\qt4\extra\range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "C:\Users\M0041User\mambaforge\lib\site-packages\traitsui\qt4\extra\range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "C:\Users\M0041User\mambaforge\lib\site-packages\traitsui\qt4\extra\range_slider.py", line 81, in paintEvent
    opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer

xref enthought/traitsui#2048 for a fix in traitsui.

Needs hyperspy/hyperspy#3368


self.control.slider.setLow(self._convert_to_slider(low))
self.low = low
except:

Check notice

Code scanning / CodeQL

Empty except

'except' clause does nothing but pass and there is no explanatory comment.

self.control.slider.setHigh(self._convert_to_slider(high))
self.high = high
except:

Check notice

Code scanning / CodeQL

Empty except

'except' clause does nothing but pass and there is no explanatory comment.
from traitsui.editors.api import RangeEditor
try:
from traitsui.qt.editor import Editor
except:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException'

Except block directly handles BaseException.

self.control.slider.setLow(self._convert_to_slider(low))
self.low = low
except:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException'

Except block directly handles BaseException.
high = eval(str(self._label_hi.text()).strip())
if self.evaluate is not None:
high = self.evaluate(high)
except:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException'

Except block directly handles BaseException.

self.control.slider.setHigh(self._convert_to_slider(high))
self.high = high
except:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException'

Except block directly handles BaseException.
Comment thread hyperspy_gui_traitsui/tools.py Fixed
@codecov

codecov Bot commented May 6, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 41.22137% with 154 lines in your changes are missing coverage. Please review.

Project coverage is 44.83%. Comparing base (7b70620) to head (96fae29).

Files Patch % Lines
hyperspy_gui_traitsui/_external/range_slider.py 18.69% 99 Missing and 1 partial ⚠️
hyperspy_gui_traitsui/_external/bounds_editor.py 60.86% 50 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
- Coverage   47.34%   44.83%   -2.51%     
==========================================
  Files          10       12       +2     
  Lines         452      707     +255     
  Branches       72      104      +32     
==========================================
+ Hits          214      317     +103     
- Misses        230      378     +148     
- Partials        8       12       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ericpre ericpre force-pushed the fix_rangeslider_issue branch from bbce235 to 96fae29 Compare May 7, 2024 08:24
@ericpre

ericpre commented May 8, 2024

Copy link
Copy Markdown
Member Author

Merging this PR to release, to prepare to be able to release soon after hyperspy 2.1 is released.

@ericpre ericpre merged commit 9e90eef into hyperspy:main May 8, 2024
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 this pull request may close these issues.

2 participants