mpl-help 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Brendt Wohlberg
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,397 @@
1
+ Metadata-Version: 2.4
2
+ Name: mpl-help
3
+ Version: 0.1.0
4
+ Summary: Backend-independent help windows for matplotlib figures
5
+ Author-email: Brendt Wohlberg <brendt@ieee.org>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/bwohlberg/mpl-help
8
+ Project-URL: Bug Tracker, https://github.com/bwohlberg/mpl-help/issues
9
+ Keywords: matplotlib,help,keyboard shortcuts
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Visualization
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE.txt
22
+ Requires-Dist: matplotlib>=3.6
23
+ Provides-Extra: yaml
24
+ Requires-Dist: pyyaml>=6.0; extra == "yaml"
25
+ Provides-Extra: config
26
+ Requires-Dist: pyyaml>=6.0; extra == "config"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pyyaml>=6.0; extra == "dev"
29
+ Requires-Dist: pytest>=7; extra == "dev"
30
+ Requires-Dist: build; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: mypy; extra == "dev"
33
+ Requires-Dist: types-PyYAML; extra == "dev"
34
+ Requires-Dist: pylint; extra == "dev"
35
+ Requires-Dist: black; extra == "dev"
36
+ Requires-Dist: isort; extra == "dev"
37
+ Requires-Dist: pre-commit; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # mpl-help
41
+
42
+ Backend-independent help windows for [matplotlib](https://matplotlib.org) figures.
43
+
44
+ Press a configurable trigger key (default **h**) inside any matplotlib figure to
45
+ open a styled help panel listing your application's keyboard shortcuts and mouse
46
+ controls.
47
+
48
+ - **No external GUI toolkit** — the help window is itself a matplotlib figure
49
+ - **Config-file driven** — define shortcuts in YAML, TOML, or JSON; no code changes needed per figure type
50
+ - **Dark and light themes**, with full per-colour overrides
51
+ - **Per-section accent colours** — named palette or arbitrary hex
52
+ - **Adjustable key column width** — accommodates both short keyboard shortcuts and longer mouse-event descriptions
53
+ - **Closes with the figure it helps** — or stays open, if you prefer
54
+ - **Works with any matplotlib backend** — TkAgg, Qt5Agg, Qt6Agg, WxAgg, …
55
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ Requires Python ≥ 3.11.
61
+
62
+ ### Local (editable) install
63
+
64
+ ```bash
65
+ git clone https://github.com/bwohlberg/mpl-help
66
+ cd mpl-help
67
+ pip install -e ".[config]" # includes PyYAML for config file support
68
+ ```
69
+
70
+ ### From PyPI (once published)
71
+
72
+ ```bash
73
+ pip install mpl-help # matplotlib only, JSON config works out of the box
74
+ pip install "mpl-help[yaml]" # add YAML support
75
+ pip install "mpl-help[config]" # same, plus any future config extras
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Quickstart
81
+
82
+ ### Programmatic API
83
+
84
+ ```python
85
+ import matplotlib.pyplot as plt
86
+ from mpl_help import HelpManager, HelpSection, KeyBinding
87
+
88
+ fig, ax = plt.subplots()
89
+ ax.plot([1, 2, 3])
90
+
91
+ help_mgr = HelpManager(fig, title="My App — Help", theme="dark")
92
+ help_mgr.add_section(HelpSection(
93
+ title="Navigation",
94
+ accent="blue",
95
+ bindings=[
96
+ KeyBinding("?", "Show this help window"),
97
+ KeyBinding("q / Escape", "Close figure"),
98
+ KeyBinding("← → ↑ ↓", "Pan the active axes"),
99
+ ],
100
+ note="Click a subplot first to make it active.",
101
+ ))
102
+ help_mgr.attach()
103
+
104
+ plt.show()
105
+ ```
106
+
107
+ > **Important:** keep a reference to the `HelpManager` alive (here: `help_mgr`) for
108
+ > the duration of `plt.show()`. matplotlib's callback registry uses weak references,
109
+ > so if the manager is garbage-collected the keypress handler silently stops working.
110
+ > If `attach()` happens in a function that returns before `plt.show()` is called,
111
+ > return the manager from that function and hold onto it at the call site.
112
+
113
+ ### Config-file API
114
+
115
+ ```python
116
+ from mpl_help import load_manager
117
+
118
+ help_mgr = load_manager(fig, "my_app_help.yaml")
119
+ help_mgr.attach()
120
+ plt.show()
121
+ ```
122
+
123
+ `load_manager` auto-detects the format from the file extension. The equivalent
124
+ in-process variants are also available:
125
+
126
+ ```python
127
+ from mpl_help import loads_manager, manager_from_dict
128
+
129
+ help_mgr = loads_manager(fig, yaml_text, fmt="yaml")
130
+ help_mgr = manager_from_dict(fig, config_dict)
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Config file format
136
+
137
+ A minimal YAML config:
138
+
139
+ ```yaml
140
+ title: My App — Keyboard Shortcuts
141
+
142
+ sections:
143
+ - title: Navigation
144
+ accent: blue
145
+ bindings:
146
+ - key: h
147
+ desc: Show this help window
148
+ - key: "q / Escape"
149
+ desc: Close figure
150
+ note: Optional callout text shown below the bindings.
151
+ ```
152
+
153
+ Top-level keys:
154
+
155
+ | Key | Type | Default | Description |
156
+ |---|---|---|---|
157
+ | `title` | `str` | `"Keyboard Shortcuts"` | Heading shown in the help window |
158
+ | `trigger_key` | `str` | `"?"` | Key that opens / closes the help window |
159
+ | `footer` | `str` | auto | Small note at the bottom of the window |
160
+ | `key_column` | `float` | `0.24` | Right edge of the key badge column, as a fraction of figure width |
161
+ | `close_with_figure` | `bool` | `true` | Close the help window when the monitored figure is closed |
162
+ | `sections` | `list` | — | Ordered list of section blocks (required) |
163
+
164
+ Section keys:
165
+
166
+ | Key | Type | Default | Description |
167
+ |---|---|---|---|
168
+ | `title` | `str` | — | Section heading (required) |
169
+ | `accent` | `str` | `"purple"` | Named palette colour or hex string |
170
+ | `bindings` | `list` | — | List of `{key, desc}` pairs (required) |
171
+ | `note` | `str` | none | Optional explanatory text below the bindings |
172
+
173
+ The config file deliberately has **no theme or per-colour content** — those are
174
+ presentation concerns, set at load time (see [Themes and palettes](#themes-and-palettes)
175
+ below), so the same config file works correctly under both themes.
176
+
177
+ See [`examples/example_help.yaml`](examples/example_help.yaml) for a fully
178
+ annotated template, and [`examples/imview_help.yaml`](examples/imview_help.yaml) /
179
+ [`examples/volview_help.yaml`](examples/volview_help.yaml) for real-world
180
+ examples with a wider key column for mouse-event descriptions.
181
+
182
+ ### Supported formats
183
+
184
+ | Format | Extra dependency |
185
+ |---|---|
186
+ | YAML (`.yaml` / `.yml`) | `pip install mpl-help[yaml]` |
187
+ | TOML (`.toml`) | none — stdlib `tomllib` |
188
+ | JSON (`.json`) | none — always available |
189
+
190
+ The same content can also be supplied directly as a Python dict — see
191
+ [`examples/imview_help_dict.py`](examples/imview_help_dict.py) for an example.
192
+
193
+ ---
194
+
195
+ ## Themes and palettes
196
+
197
+ Two built-in themes are available: `"dark"` (default) and `"light"`. Pass
198
+ `theme=` to `HelpManager` or to any of the loader functions:
199
+
200
+ ```python
201
+ HelpManager(fig, theme="light")
202
+ load_manager(fig, "my_app_help.yaml", theme="light")
203
+ ```
204
+
205
+ Named accent colours (`blue`, `green`, `orange`, …) resolve to *different* hex
206
+ values depending on the active theme — deeper, more saturated tones on light
207
+ backgrounds and brighter tones on dark backgrounds — both chosen for
208
+ legibility. The config file only ever specifies the colour *name*; the
209
+ resolved value is purely a function of the active theme at render time.
210
+
211
+ | Name | Light hex | Dark hex |
212
+ |---|---|---|
213
+ | `blue` | `#0969da` | `#58a6ff` |
214
+ | `purple` | `#8250df` | `#bc8cff` |
215
+ | `green` | `#1a7f37` | `#3fb950` |
216
+ | `yellow` | `#9a6700` | `#d29922` |
217
+ | `orange` | `#bc4c00` | `#ffa657` |
218
+ | `red` | `#cf222e` | `#f85149` |
219
+ | `cyan` | `#1b7c83` | `#39c5cf` |
220
+
221
+ Any CSS hex colour (`"#f0a040"`) is also accepted as an accent and is used
222
+ as-is in both themes.
223
+
224
+ ### Overriding individual colours
225
+
226
+ Pass a `palette` dict to override any entry in `DEFAULT_PALETTE`, structural
227
+ or accent. Each value is a `(light_hex, dark_hex)` tuple:
228
+
229
+ ```python
230
+ from mpl_help import HelpManager, DEFAULT_PALETTE
231
+
232
+ print(DEFAULT_PALETTE.keys())
233
+ # dict_keys(['bg', 'surface', 'panel', 'border', 'text', 'muted',
234
+ # 'key_bg', 'key_fg', 'note_fg', 'note_bg', 'note_border',
235
+ # 'alt_row', 'top_bar', 'blue', 'purple', 'green',
236
+ # 'yellow', 'orange', 'red', 'cyan'])
237
+
238
+ help_mgr = HelpManager(
239
+ fig,
240
+ theme="light",
241
+ palette={
242
+ "blue": ("#1a5fb4", "#6ab0f5"), # (light_hex, dark_hex)
243
+ "bg": ("#fafafa", "#0a0d12"),
244
+ },
245
+ )
246
+ ```
247
+
248
+ Unknown palette keys are silently ignored. `palette` is a presentation
249
+ argument like `theme` — it is never read from the config file.
250
+
251
+ ---
252
+
253
+ ## Key column width
254
+
255
+ Short keyboard shortcuts (`h`, `q / Escape`) fit comfortably in the default
256
+ key column. Longer descriptions of mouse interactions — e.g.
257
+ `"Mouse wheel (colorbar bottom half)"` — need more room and will be clipped
258
+ or overflow the left margin at the default width. Widen the column with
259
+ `key_column` (a fraction of figure width, default `0.24`):
260
+
261
+ ```python
262
+ load_manager(fig, "my_app_help.yaml", key_column=0.45)
263
+ ```
264
+
265
+ `key_column` can also be set directly in the config file:
266
+
267
+ ```yaml
268
+ key_column: 0.45
269
+ ```
270
+
271
+ A programmatic `key_column=` argument always overrides a value present in
272
+ the config file.
273
+
274
+ ---
275
+
276
+ ## Closing the help window
277
+
278
+ By default the help window closes with the figure it belongs to: when the
279
+ monitored figure is closed — by its window close button, by matplotlib's
280
+ quit key, or by `plt.close(fig)` — any open help window for it closes too.
281
+
282
+ Pass `close_with_figure=False` to leave it open instead, in which case it is
283
+ closed by the user, by the trigger key, or by `detach()`:
284
+
285
+ ```python
286
+ help_mgr = HelpManager(fig, close_with_figure=False)
287
+ ```
288
+
289
+ The same option can be set in the config file:
290
+
291
+ ```yaml
292
+ close_with_figure: false
293
+ ```
294
+
295
+ `detach()` always closes an open help window, whatever this option is set to.
296
+
297
+ ---
298
+
299
+ ## Examples
300
+
301
+ The [`examples/`](examples) directory includes:
302
+
303
+ - [`demo.py`](examples/demo.py) — exercises all three config-loading routes
304
+ (file / string / dict) and both themes. Can be run from any directory:
305
+ ```bash
306
+ python examples/demo.py file --theme light
307
+ python examples/demo.py string --theme dark
308
+ python examples/demo.py dict --theme light
309
+ ```
310
+ - [`example_help.yaml`](examples/example_help.yaml) /
311
+ [`example_help.toml`](examples/example_help.toml) — fully annotated config
312
+ templates covering every option
313
+ - [`imview_help.yaml`](examples/imview_help.yaml),
314
+ [`imview_help.toml`](examples/imview_help.toml),
315
+ [`imview_help_dict.py`](examples/imview_help_dict.py) — real-world config
316
+ for an image-viewing function, in all three supported formats
317
+ - [`volview_help.yaml`](examples/volview_help.yaml),
318
+ [`volview_help.toml`](examples/volview_help.toml),
319
+ [`volview_help_dict.py`](examples/volview_help_dict.py) — same, extended
320
+ with volume-slice controls
321
+
322
+ ---
323
+
324
+ ## API reference
325
+
326
+ ### `HelpManager(fig, title, trigger_key, footer, theme, palette, key_column, close_with_figure)`
327
+
328
+ | Parameter | Type | Default | Description |
329
+ |---|---|---|---|
330
+ | `fig` | `Figure` | — | The matplotlib figure to monitor |
331
+ | `title` | `str` | `"Keyboard Shortcuts"` | Heading in the help window |
332
+ | `trigger_key` | `str` | `"?"` | Key that opens / closes the help window |
333
+ | `footer` | `str \| None` | auto | Note at the bottom of the window |
334
+ | `theme` | `str` | `"dark"` | `"dark"` or `"light"` |
335
+ | `palette` | `dict \| None` | `None` | Per-instance palette overrides |
336
+ | `key_column` | `float` | `0.24` | Right edge of key badge column (figure-width fraction) |
337
+ | `close_with_figure` | `bool` | `True` | Close the help window when the monitored figure is closed |
338
+
339
+ **Methods:**
340
+
341
+ - `.add_section(section)` — append a `HelpSection`; chainable
342
+ - `.attach()` — start listening for the trigger key on `fig`
343
+ - `.detach()` — stop listening and close the help window if open
344
+ - `.show()` — open the help window programmatically
345
+
346
+ ### `HelpSection(title, bindings, note, accent)`
347
+
348
+ A titled group of key bindings. `accent` accepts a named palette colour, a
349
+ hex string, or `None` (defaults to `"purple"`).
350
+
351
+ ### `KeyBinding(key, description)`
352
+
353
+ A single key/description pair.
354
+
355
+ ### `load_manager(fig, path, theme="dark", palette=None, key_column=None, close_with_figure=None, encoding="utf-8")`
356
+ Builds a `HelpManager` from a config file. Format auto-detected from extension.
357
+
358
+ ### `loads_manager(fig, text, fmt, theme="dark", palette=None, key_column=None, close_with_figure=None)`
359
+ Builds a `HelpManager` by parsing a config string. `fmt` is `"yaml"`, `"toml"`, or `"json"`.
360
+
361
+ ### `manager_from_dict(fig, config, theme="dark", palette=None, key_column=None, close_with_figure=None)`
362
+ Builds a `HelpManager` directly from a Python dict.
363
+
364
+ ### `DEFAULT_PALETTE`
365
+ Dict of `{name: (light_hex, dark_hex)}` — the built-in colour set. Pass a
366
+ subset to `palette=` to override individual entries.
367
+
368
+ ### `ACCENT_NAMES`
369
+ The set of valid named accent colours: `blue`, `purple`, `green`, `yellow`,
370
+ `orange`, `red`, `cyan`.
371
+
372
+ ---
373
+
374
+ ## Development
375
+
376
+ ```bash
377
+ pip install -e ".[dev]"
378
+ pytest
379
+ ```
380
+
381
+ ---
382
+
383
+ ## Changelog
384
+
385
+ See [CHANGELOG.md](CHANGELOG.md).
386
+
387
+ ---
388
+
389
+ ## License
390
+
391
+ BSD 3-Clause — see [LICENSE.txt](LICENSE.txt).
392
+
393
+ ---
394
+
395
+ ## Acknowledgements
396
+
397
+ Development of this package involved extensive use if Claude Code.