Repository navigation
Commit a0a9296
feat(base): set_window_title, set the title of a figure's window if it has one (#263)
## Summary
Adds `spatialmath.base.set_window_title(fig, title)`, which sets the
title of the window that contains a figure, if it has one.
A figure has a window only if it is managed by pyplot and the backend
provides one. On a headless backend (`Agg`), or for a figure made
directly with `matplotlib.figure.Figure`, there is no window:
`canvas.manager` is `None`, or the manager has no `set_window_title`.
The function then does nothing and returns `False`, so callers do not
need a `try`/`except` or a guard.
## Why
The Robotics Toolbox for Python and the Machine Vision Toolbox for
Python each set window titles, in several places, with different guards:
RTB reached into `figure.canvas.manager` directly in some places, and
MVTB has a helper on `plt.gcf()` with a bare `except:` as well as direct
calls. Both already depend on `spatialmath.base.graphics` for
`axes_logic` and `plotvol2`, so this is the natural home for one copy.
## Changes
- `spatialmath/base/graphics.py`: `set_window_title`, and a stub that
raises `NotImplementedError` without Matplotlib, as for the other
plotting functions.
- `spatialmath/base/__init__.py`: lazily exported with the other
graphics names.
- `tests/base/test_graphics.py`: a managed figure, a pyplot figure, a
figure without a manager, a manager without the method.
No change to any existing behaviour.
## Test plan
- [x] `pytest tests` (384 passed, 3 skipped)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>1 parent 8c4f022 commit a0a9296
3 files changed
Lines changed: 69 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
391 | 392 | | |
392 | 393 | | |
393 | 394 | | |
| 395 | + | |
394 | 396 | | |
395 | 397 | | |
396 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1791 | 1791 | | |
1792 | 1792 | | |
1793 | 1793 | | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
1794 | 1825 | | |
1795 | 1826 | | |
1796 | 1827 | | |
| |||
1857 | 1888 | | |
1858 | 1889 | | |
1859 | 1890 | | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
12 | 45 | | |
13 | 46 | | |
14 | 47 | | |
| |||
0 commit comments