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

Respect background color when calculating scale bar color #5270

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Oct 26, 2022

Description

Currently color of the scale bar is calculated base on the canvas color assigned in the theme. But since #2270 is possible to overwrite background color. In this PR I add support to respect this option (used for example, in PartSeg).

obraz

Type of change

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

References

How has this been tested?

  • example: the test suite for my feature covers cases x, y, and z
  • example: all tests pass with my change
  • example: I check if my changes works with both PySide and PyQt backends
    as there are small differences between the two Qt bindings.

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • If I included new strings, I have used trans. to make them localizable.
    For more information see our translations guide.

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #5270 (9514f5a) into main (d5ffbac) will increase coverage by 0.27%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5270      +/-   ##
==========================================
+ Coverage   88.76%   89.03%   +0.27%     
==========================================
  Files         579      578       -1     
  Lines       49093    48946     -147     
==========================================
+ Hits        43576    43579       +3     
+ Misses       5517     5367     -150     
Impacted Files Coverage Δ
...apari/_vispy/_tests/test_vispy_scale_bar_visual.py 100.00% <100.00%> (ø)
napari/_vispy/overlays/scale_bar.py 97.50% <100.00%> (+0.06%) ⬆️
napari/utils/_tests/test_key_bindings.py 96.96% <0.00%> (-0.21%) ⬇️
napari/utils/shortcuts.py 100.00% <0.00%> (ø)
napari/_qt/menus/__init__.py 100.00% <0.00%> (ø)
napari/utils/_tests/test_interactions.py 100.00% <0.00%> (ø)
napari/layers/points/_points_key_bindings.py 100.00% <0.00%> (ø)
...ri/_qt/_qapp_model/_tests/test_qapp_model_menus.py 100.00% <0.00%> (ø)
napari/utils/colormaps/vendored/colorconv.py
napari/_qt/menus/help_menu.py
... and 22 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@andy-sweet andy-sweet left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. Not ideal, but I think it's good enough to merge, so I'll do so after 24 hours unless anyone objects.

One optional suggestion is to add a test to cover the original bug. There were some existing issues with the design/implementation here, so I might consider changing some things in the future, but wouldn't want to break this again.

Here's my best attempt at writing a test, which unfortunately needs make_napari_viewer.

def test_box_color_with_background_color_override(make_napari_viewer):
    viewer = make_napari_viewer()
    qt_viewer = viewer.window._qt_viewer

    qt_viewer.canvas.background_color_override = [1, 0, 0]

    np.testing.assert_equal(qt_viewer.scale_bar.node.text.color.rgb, [[0, 1, 1]])

Comment on lines 125 to 126
and hasattr(self.viewer.window, "_qt_viewer")
and self.viewer.window._qt_viewer.canvas.background_color_override
Copy link
Member

Choose a reason for hiding this comment

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

Not great that we have to use private state here (or more generally that the scale bar has access to the whole of the viewer), but I can't think of anything better right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have fixed this by use the parent of node and allowing to use of this fix with ViewerModel not only Viewer.

@Czaki Czaki marked this pull request as draft November 1, 2022 18:02
@Czaki Czaki marked this pull request as ready for review November 1, 2022 20:01
@github-actions github-actions bot added the tests Something related to our tests label Nov 1, 2022
@andy-sweet andy-sweet merged commit c653758 into napari:main Nov 2, 2022
@Czaki Czaki added this to the 0.5.0 milestone Nov 8, 2022
@Czaki Czaki added the bugfix PR with bugfix label Dec 5, 2022
@Czaki Czaki deleted the axes_color_base_on_canvas branch June 7, 2023 10:45
@Czaki Czaki mentioned this pull request Jun 7, 2023
@Czaki Czaki modified the milestones: 0.5.0, 0.4.18 Jun 16, 2023
@Czaki Czaki added the triaged-0.4.18 To mark PR that is triaged in 0.4.18 release process label Jun 16, 2023
Czaki added a commit that referenced this pull request Jun 16, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 17, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 18, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 19, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 21, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 21, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Czaki added a commit that referenced this pull request Jun 21, 2023
* if background_color_override is set then use it for axes color

* improve guard of override

* fix implementation, add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR with bugfix tests Something related to our tests triaged-0.4.18 To mark PR that is triaged in 0.4.18 release process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants