erlab.interactive.colors

Functions for manipulating colors in Qt.

Functions

color_to_QColor(c[, alpha])

Convert a matplotlib color to a PySide6.QtGui.QColor.

is_dark_mode()

Check if the system is in dark mode.

pg_colormap_from_name(name[, skipCache])

Get a pyqtgraph.ColorMap from its name.

pg_colormap_names([source, exclude_local])

Get all valid pyqtgraph colormap names.

pg_colormap_powernorm(cmap, gamma[, ...])

pg_colormap_to_QPixmap(cmap[, w, h, skipCache])

Convert a pyqtgraph.ColorMap to a w-by-h QPixmap thumbnail.

Classes

BetterColorBarItem([parent, image, ...])

BetterImageItem([image])

pyqtgraph.ImageItem with improved colormap support.

ColorCycleDialog(colors, *[, parent, ...])

Dialog for selecting a color cycle.

ColorMapComboBox(*args, **kwargs)

ColorMapGammaWidget([parent, value, ...])

Slider and spinbox for adjusting colormap gamma.

class erlab.interactive.colors.BetterColorBarItem(parent=None, image=None, autoLevels=False, limits=None, pen='c', hoverPen='m', hoverBrush='#FFFFFF33', *, show_colormap_edit_menu=True, **kargs)[source]

Bases: PlotItem

property images
property primary_image
property levels: Sequence[float]
property limits: tuple[float, float]
set_width(width)[source]
set_dimensions(horiz_pad=None, vert_pad=None, font_size=11.0)[source]
level_change()[source]
level_change_fin()[source]
spanRegion()[source]
setSpanRegion(levels)[source]
setLimits(limits)[source]
addImage(image)[source]
removeImage(image)[source]
setImageItem(image, insert_in=None)[source]
image_level_changed()[source]
image_changed()[source]
reset_levels()[source]
setAutoLevels(value)[source]
color_changed()[source]
limit_changed()[source]
mouseDragEvent(ev)[source]
class erlab.interactive.colors.BetterImageItem(image=None, **kwargs)[source]

Bases: ImageItem

pyqtgraph.ImageItem with improved colormap support.

Parameters:
Signals:
  • sigColorChanged()

  • sigLimitChanged(float, float)

set_colormap(cmap, gamma, reverse=False, high_contrast=False, zero_centered=False, update=True)[source]
set_pg_colormap(cmap, update=True)[source]
class erlab.interactive.colors.ColorCycleDialog(colors, *, parent=None, preview_cursors=False, opacity_values=(0.95, 0.75, 0.15, 0.35), default_colors=None)[source]

Bases: QDialog

Dialog for selecting a color cycle.

This dialog takes a list of colors and allows the user to edit each color in the cycle, or overwrite the entire cycle by sampling from a colormap.

Parameters:
  • colors (Iterable[QColor]) – An iterable of colors to use as the initial color cycle.

  • parent (QWidget | None, default: None) – The parent widget for the dialog.

  • preview_cursors (bool, default: False) – If True, the preview will include cursor lines and spans with the selected colors.

  • opacity_values (tuple[float, float, float, float], default: (0.95, 0.75, 0.15, 0.35)) – A tuple of four float values representing the opacity for the cursor line, cursor line hover, span background, and span edge, respectively. Each value should be between 0 and 1, where 1 is fully opaque and 0 is fully transparent.

  • default_colors (Iterable[QColor] | None, default: None) – An iterable of default colors to return to when the user clicks “Restore Defaults”. If None, the restore defaults button will not be shown.

property colors: tuple[QColor]

Return the current color cycle.

setup_ui()[source]
set_from_cmap()[source]

Set the color cycle from a colormap.

reset()[source]
restore_defaults()[source]

Restore the default colors if provided.

accept()[source]

Accept the dialog and emit the new colors.

class erlab.interactive.colors.ColorMapComboBox(*args, **kwargs)[source]

Bases: QComboBox

clear()[source]
showEvent(event)[source]
closeEvent(event)[source]
load_thumbnail(index)[source]
load_all()[source]
showPopup()[source]
setPopupMinimumWidthForItems()[source]
hidePopup()[source]
setDefaultCmap(cmap)[source]
resetCmap()[source]
setCurrentText(text)[source]

Set the current text of the combobox.

class erlab.interactive.colors.ColorMapGammaWidget(parent=None, value=1.0, slider_cls=None, spin_cls=None)[source]

Bases: QWidget

Slider and spinbox for adjusting colormap gamma.

Signals:

valueChanged(float)

value()[source]
setValue(value)[source]
spin_changed(value)[source]
slider_changed(value)[source]
gamma_scale(y)[source]
gamma_scale_inv(x)[source]
erlab.interactive.colors.color_to_QColor(c, alpha=None)[source]

Convert a matplotlib color to a PySide6.QtGui.QColor.

Parameters:
Returns:

PySide6.QtGui.QColor

Return type:

QColor

erlab.interactive.colors.is_dark_mode()[source]

Check if the system is in dark mode.

If a QApplication is not running, this will always return False.

erlab.interactive.colors.pg_colormap_from_name(name, skipCache=True)[source]

Get a pyqtgraph.ColorMap from its name.

Parameters:
Returns:

pyqtgraph.ColorMap

Return type:

ColorMap

erlab.interactive.colors.pg_colormap_names(source='all', exclude_local=False)[source]

Get all valid pyqtgraph colormap names.

Parameters:
  • source (Literal['local', 'all', 'matplotlib'], default: "all") –

    • “local”: only built-in/pyqtgraph colormaps

    • ”matplotlib”: only matplotlib colormaps

    • ”all”: local + colorcet + matplotlib

  • exclude_local (bool, default: False) – If True, drop local colormaps from the final list.

Returns:

list of str – Ordered, de-duplicated list of colormap names.

Return type:

list[str]

erlab.interactive.colors.pg_colormap_powernorm(cmap, gamma, reverse=False, high_contrast=False, zero_centered=False, N=65536)[source]
erlab.interactive.colors.pg_colormap_to_QPixmap(cmap, w=64, h=16, skipCache=True)[source]

Convert a pyqtgraph.ColorMap to a w-by-h QPixmap thumbnail.

Parameters:
  • cmap (str | ColorMap) – The colormap.

  • w (int, default: 64) – Specifies the dimension of the pixmap.

  • h (int, default: 16) – Specifies the dimension of the pixmap.

  • skipCache (bool, optional) – Whether to skip cache, by default True. Passed onto pg_colormap_from_name().

Returns:

PySide6.QtGui.QPixmap

Return type:

QPixmap