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

Add a logarithmic scale slider class #38

Merged
merged 21 commits into from
Jul 23, 2020

Conversation

GenevieveBuckley
Copy link
Contributor

@GenevieveBuckley GenevieveBuckley commented Jul 21, 2020

Juan originally suggested a log scale slider for napari (napari/napari#938) but this strikes me as something that would also be very useful to have available in magicgui.

Adds numpy as a base requirement.

The main limitation of the log slider is that the available range is restricted from 0 -> 14.5. If you go any higher than 14.5 you get an overflow error from Qt. Qt expects internal values in the range of -2147483647 to +2147483647, so the exponential can cause problems quickly. Still, I think there is some value in having a log slider available, even if there are some restrictions here.

@codecov
Copy link

codecov bot commented Jul 21, 2020

Codecov Report

Merging #38 into master will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage   95.82%   95.98%   +0.15%     
==========================================
  Files          14       16       +2     
  Lines         934      971      +37     
==========================================
+ Hits          895      932      +37     
  Misses         39       39              
Impacted Files Coverage Δ
magicgui/_qt/widgets/__init__.py 100.00% <100.00%> (ø)
magicgui/_qt/widgets/double_slider.py 100.00% <100.00%> (ø)
magicgui/_qt/widgets/log_slider.py 100.00% <100.00%> (ø)
magicgui/_tests/test_qt.py 99.01% <100.00%> (ø)
magicgui/_tests/test_widgets.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db4c816...981efac. Read the comment docs.

@GenevieveBuckley
Copy link
Contributor Author

Ok, something weird is going on with the tests. I can't see how the changes here could possibly have caused this, but here's what I've found.

  • Tests pass on the current master branch (I can reproduce this locally).
  • On this log-slider branch, all the CI test runs report a test failure for magicgui/_tests/test_qt.py::test_event (I can reproduce this locally too).
  • If you run that specific test by itself, it passes fine: 'pytest magicgui/_tests/test_qt.py::test_event`
  • But if you run any other test using a qtbot fixture (or the magic_widget fixture, since that fixture also uses qtbot) before it, test_event will fail because of the line: assert not QtW.QApplication.instance(). I've checked this theory by running an example test before test_event that does nothing but assert True but does take in the qtbot fixture:
def test_example(qtbot):
    assert True

So, what to do?

If we can remove the line assert not QtW.QApplication.instance() from test_event then we'd have no more test failures - but I assume the reason it's there in the first place is because it's checking something important? I don't know why it's important that we see/expect a null pointer here (which is what the Qt docs say is supposed to happen if no instance has been allocated), so I'd really like to hear suggestions.

@tlambert03
Copy link
Member

that was a pretty fragile test to begin with and was very dependent on the order of operations. Once a qtbot makes an app, it sticks around for the rest of the tests. I was asserting that there was no instance so that we could make sure that the event_loop context manager (same as napari.gui_qt basically) was actually creating the app.

I just pushed a fix here, which deletes any pre-existing application instance using sip.delete or shiboken.2 delete... a clever little trick that Phillip recently found on stack overflow.

@GenevieveBuckley
Copy link
Contributor Author

Thank you for the fix! Very helpful :)

@tlambert03
Copy link
Member

welp... looks like pyside2 was ok with that, but not pyqt5. I just skipped the test for pyqt5.

super().__init__(Qt.Horizontal, parent=parent)
self.setMinimum(0)
self.setMaximum(10)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make this slightly more flexible, perhaps we should add an attribute self.base = math.e ... then convert math.exp(value) to math.pow(self.base, value) and math.log(value) to math.log(value, base=self.base)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch, I like this suggestion a lot. Done!

GenevieveBuckley and others added 6 commits July 23, 2020 13:37
Fix for new warnings in the tests: Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
@GenevieveBuckley
Copy link
Contributor Author

Ok I think I've addressed all the reviewer suggestions, and we have a passing test suite now (thanks to Talley). I think things are looking good here.

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@tlambert03 tlambert03 merged commit b1ba82e into pyapp-kit:master Jul 23, 2020
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.

3 participants