Custom menu for Colorbar on right click#1201
Conversation
There was a problem hiding this comment.
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(subclassingpg.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 Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Benchmark comparisonThreshold: 20% (lower is better). No benchmark regression exceeded the configured threshold. No benchmark improvement exceeded the configured threshold. All benchmark results
|
62b5268 to
a300688
Compare
a300688 to
df43e03
Compare
|
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 |
| 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): |
|
|
||
| class RangeDialog(QDialog): | ||
| """ | ||
| Modal dialog to enter a ``(min, max)`` floating point range. |
There was a problem hiding this comment.
(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. | ||
| """ | ||
|
|
There was a problem hiding this comment.
(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): |
There was a problem hiding this comment.
(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.


Uh oh!
There was an error while loading. Please reload this page.