Skip to content

Commit

Permalink
Merge pull request #18 from rgw5267/master
Browse files Browse the repository at this point in the history
Fix repeated event binding on figure creation using class attribute
  • Loading branch information
joshburnett authored Jun 24, 2024
2 parents bfb0820 + 7d94436 commit 0fa6d6b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 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.1'
__version__ = '3.2.2'
__version_info__ = tuple(int(i) if i.isdigit() else i for i in __version__.split('.'))

oldfig = plt.figure
Expand Down Expand Up @@ -264,13 +264,19 @@ def copyfig(fig=None, *args, **kwargs):

@wraps(plt.figure)
def newfig(*args, **kwargs):
if not hasattr(newfig, "handler_connected"):
newfig.handler_connected = False

fig = oldfig(*args, **kwargs)

def clipboard_handler(event):
if event.key in ('ctrl+c', 'cmd+c'):
copyfig()

fig.canvas.mpl_connect('key_press_event', clipboard_handler)
if not newfig.handler_connected:
fig.canvas.mpl_connect('key_press_event', clipboard_handler)
newfig.handler_connected = True

return fig


Expand Down

0 comments on commit 0fa6d6b

Please sign in to comment.