Skip to content

Custom menu for Colorbar on right click#1201

Open
wyzula-jan wants to merge 1 commit into
mainfrom
colorbar-menu
Open

Custom menu for Colorbar on right click#1201
wyzula-jan wants to merge 1 commit into
mainfrom
colorbar-menu

Conversation

@wyzula-jan

@wyzula-jan wyzula-jan commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
image

@wyzula-jan wyzula-jan self-assigned this Jun 19, 2026
Copilot AI review requested due to automatic review settings June 19, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a BEC-specific right-click context menu for the full image colorbar (pyqtgraph HistogramLUTItem), replacing pyqtgraph’s generic plot menu on the histogram view with actions that are relevant for image scaling and colormap selection.

Changes:

  • Added BECHistogramLUTItem (subclassing pg.HistogramLUTItem) that installs a custom histogram ViewBox context menu and provides signals for menu-driven colormap / level changes.
  • Wired the new item into ImageBase.enable_colorbar(..., style="full"), connecting menu actions to existing image-level state handling (colormap, vrange, autorange).
  • Added unit tests covering the new menu behavior and cleanup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
bec_widgets/widgets/plots/image/image_base.py Uses BECHistogramLUTItem for full colorbars and connects its menu-request signals into ImageBase state updates.
bec_widgets/widgets/plots/image/bec_histogram_lut_item.py New BECHistogramLUTItem implementation with focused context menu + RangeDialog helper and explicit cleanup.
tests/unit_tests/test_image_view_next_gen.py Adds integration-style tests ensuring the full colorbar uses BECHistogramLUTItem and menu signals update image state.
tests/unit_tests/test_bec_histogram_lut_item.py New unit tests validating menu contents, signal forwarding, context-menu routing, and cleanup idempotency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.48921% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gets/widgets/plots/image/bec_histogram_lut_item.py 87.70% 7 Missing and 8 partials ⚠️
bec_widgets/widgets/plots/image/image_base.py 94.11% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Benchmark comparison

Threshold: 20% (lower is better).
Result: 0 regression(s), 0 improvement(s) beyond threshold.

No benchmark regression exceeded the configured threshold.

No benchmark improvement exceeded the configured threshold.

All benchmark results
Benchmark Baseline Current Change Status
BEC IPython client with companion app 2.132 s 2.25093 s +5.58% ok
BEC IPython client without companion app 2.17844 s 2.19817 s +0.91% ok
Import bec_widgets 0.0135457 s 0.0136371 s +0.68% ok
tests/unit_tests/benchmarks/test_dock_area_benchmark.py::test_add_waveform_to_dock_area 0.1506 s 0.157812 s +4.79% ok

@wyzula-jan wyzula-jan requested a review from a team June 30, 2026 14:26
@wakonig

wakonig commented Jun 30, 2026

Copy link
Copy Markdown
Member

Looks fine. It is a bit strange that there are now two different menus, one for the histogram selector and one for the colormapping. Is there an easy way to combine them?

@wyzula-jan

Copy link
Copy Markdown
Contributor Author

Looks fine. It is a bit strange that there are now two different menus, one for the histogram selector and one for the colormapping. Is there an easy way to combine them?

the one from the color map is the native one and it is not actually part of original widget, I would keep both. Otherwise I have to wrap also that widget

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines 474 to +483
elif style == "full":
self._color_bar = pg.HistogramLUTItem()
self._color_bar = BECHistogramLUTItem()
self._color_bar.setImageItem(self.layer_manager["main"].image)
self.config.color_bar = "full"
self._apply_colormap_to_colorbar(self.config.color_map)
self._color_bar.sigLevelsChanged.connect(disable_autorange)
# Custom colorbar context menu (replaces pyqtgraph's default plot menu).
self._color_bar.sigColorMapChangeRequested.connect(self._set_colormap_from_menu)
self._color_bar.sigColorLevelsChangeRequested.connect(self._set_vrange_from_menu)
self._color_bar.sigAutoLevelsRequested.connect(self._autorange_from_menu)
from bec_widgets.widgets.utility.spinbox.decimal_spinbox import BECSpinBox


class RangeDialog(QDialog):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I played with the colorbar this morning, and found a couple of UI + usage issues. I will list them one by one below, not really realted to the position in code.

(1.) The colormaps view is cut off

Image Image


class RangeDialog(QDialog):
"""
Modal dialog to enter a ``(min, max)`` floating point range.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(2) You can not set the range in non integer values, although the selector indicates this. In Lin range this is no issue, but in log range it is. The simple colorbar also does not support "set_levels" yet, is that intended.

Screen.Recording.2026-07-01.at.08.40.46.mov

"""
Modal dialog to enter a ``(min, max)`` floating point range.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(3) Just to confirm. The histogram range updates to auto values if the range is set. I think that default behavior is how it should be, but just to confirm whether this is intended behavior.

dialog.deleteLater()


class BECHistogramLUTItem(pg.HistogramLUTItem):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(4) Switching between simple and full colorbar resets the levels. My expectation would be that the levels are in sync, and won't reset after switching back and forth.

Screen.Recording.2026-07-01.at.08.48.33.mov

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.

4 participants