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
MultistateLEDdemo (community-proposed six-state convention, seeutils/status_palette.py);a
QToolBarofMaterialIconactions.
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
StatusPaletteconvention as the LEDs above it;a checkable action (Pause / Grid / Zoom) whose
MaterialIconcarries two distinct pixmaps, one perQIcon.State(On/Off) — the same mechanismaction_manager.QActionuses for its ownicon_checked/icon_uncheckedpair. Qt swaps between them on its own fromQAction.isChecked(); click a toggle button to see it.Note for anyone reusing this pattern:
QIconis a copy-on-write value type, soQAction(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.