Skip to content

Commit

Permalink
Fix issue when using the Agg backend on Windows :doesn't support get_…
Browse files Browse the repository at this point in the history
…window_title()
  • Loading branch information
Josh Burnett committed Sep 5, 2024
1 parent 08f3393 commit 1b6bc87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Uses code & concepts from:

Releases
--------
### 3.2.4: 2024-09-03

- Fix [issue when using the Agg backend on Windows](https://github.com/joshburnett/addcopyfighandler/issues/20), which doesn't support get_window_title().

### 3.2.3: 2024-09-03

- Fixed [an issue with copying when there are multiple figures](https://github.com/joshburnett/addcopyfighandler/issues/19).
Expand Down
13 changes: 10 additions & 3 deletions src/addcopyfighandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import matplotlib.backends
import matplotlib.pyplot as plt

__version__ = '3.2.3'
__version__ = '3.2.4'
__version_info__ = tuple(int(i) if i.isdigit() else i for i in __version__.split('.'))

oldfig = plt.figure
Expand Down Expand Up @@ -105,7 +105,11 @@ def copyfig(fig=None, format=None, *args, **kwargs):
fig = fig_to_check
break
else:
fig_window_text = fig.canvas.manager.get_window_title()
try:
fig_window_text = fig.canvas.manager.get_window_title()
except AttributeError:
# A figure was specified, but the backend doesn't support get_window_title(). This happens w/ Agg.
fig_window_text = None

if fig is None:
raise AttributeError('No figure found!')
Expand Down Expand Up @@ -138,7 +142,10 @@ def copyfig(fig=None, format=None, *args, **kwargs):
win32clipboard.SetClipboardData(format_id, data)
win32clipboard.CloseClipboard()

print(f'Figure copied: Window title="{fig_window_text}"')
if fig_window_text is not None:
print(f'Figure copied: Window title="{fig_window_text}"')
else:
print('Figure copied')

elif 'qt' in backend.lower():
# Use Qt version from matplotlib.
Expand Down

0 comments on commit 1b6bc87

Please sign in to comment.