8.6.2.15. pymodaq_gui.examples.theming_demo module

8.6.2.15.1. PyMoDAQ Theming Demo — Status Color Palette + Material Icon Toolbar

Run this file directly:

python theming_demo.py

8.6.2.15.1.1. One theme control drives two different rebuild strategies

Switching theme (combobox, or the Play button to auto-cycle through every qt_themes theme) calls a single _refresh_colors() that rebuilds everything color-dependent in this window from scratch:

  • the status-color reference table and the live MultistateLED demo (community-proposed six-state convention, see utils/status_palette.py);

  • a QToolBar of MaterialIcon actions.

Rebuilding from scratch is required for the icons specifically: MaterialIcon (pymodaq_gui.resources.material_icons) bakes the active QApplication.palette() color into a rasterized QPixmap exactly once, at construction time (see SVGIcon._init_colors). There is no paletteChanged hook, so simply calling qt_themes.set_theme(...) on an already-built toolbar leaves every icon in its old color — only icons built after the switch pick up the new palette. That is the same change a real DAQ_Move / DAQ_Viewer toolbar would need to retheme live.

The toolbar also shows two independent, non-animated uses of icon color:

  • a momentary action (Refresh / Save / Stop) tinted from the same six-state StatusPalette convention as the LEDs above it;

  • a checkable action (Pause / Grid / Zoom) whose MaterialIcon carries two distinct pixmaps, one per QIcon.State (On/Off) — the same mechanism action_manager.QAction uses for its own icon_checked / icon_unchecked pair. Qt swaps between them on its own from QAction.isChecked(); click a toggle button to see it.

    Note for anyone reusing this pattern: QIcon is a copy-on-write value type, so QAction(icon, ...) takes its own copy at construction time. Both icon states must be set on the icon before it is handed to the QAction – mutating it afterwards detaches and lands only on the local reference, never reaching the action.

class pymodaq_gui.examples.theming_demo.ThemingDemo(parent=None)[source]

Bases: QWidget

Standalone demo: status-color LEDs + a MaterialIcon toolbar, both retheme correctly.

Methods

closeEvent

closeEvent(event)[source]
staticMetaObject = PySide6.QtCore.QMetaObject("ThemingDemo" inherits "QWidget": )
pymodaq_gui.examples.theming_demo.main()[source]