Skip to content
Snippets Groups Projects
Verified Commit a82bc092 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Make figure identifier unique

parent e261d03f
Branches
Tags
1 merge request!60Improve responsiveness during acquisition
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import contextlib import contextlib
import os import os
import warnings import warnings
import weakref
from itertools import compress from itertools import compress
from typing import Dict, Any, Optional, Mapping, Tuple, ContextManager, Iterable, Union, List from typing import Dict, Any, Optional, Mapping, Tuple, ContextManager, Iterable, Union, List
...@@ -18,6 +19,8 @@ _styleT = Union[None, _styleT, List[_styleT]] ...@@ -18,6 +19,8 @@ _styleT = Union[None, _styleT, List[_styleT]]
class PlotManager: class PlotManager:
__instances = weakref.WeakSet()
# TODO: blit? # TODO: blit?
PLOT_TYPES = ('main', 'cumulative', 'time') PLOT_TYPES = ('main', 'cumulative', 'time')
LINE_TYPES = ('processed', 'raw') LINE_TYPES = ('processed', 'raw')
...@@ -68,7 +71,7 @@ class PlotManager: ...@@ -68,7 +71,7 @@ class PlotManager:
self.legend_kw = legend_kw or dict() self.legend_kw = legend_kw or dict()
self.legend_kw.setdefault('loc', 'upper right') self.legend_kw.setdefault('loc', 'upper right')
self.figure_kw.setdefault('num', 'Spectrometer') self.figure_kw.setdefault('num', f'Spectrometer {len(self.__instances) + 1}')
if not any('layout' in key for key in self.figure_kw.keys()): if not any('layout' in key for key in self.figure_kw.keys()):
# depending on the matplotlib version, this setting is either # depending on the matplotlib version, this setting is either
# layout='tight' or tight_layout=True # layout='tight' or tight_layout=True
...@@ -76,6 +79,11 @@ class PlotManager: ...@@ -76,6 +79,11 @@ class PlotManager:
if self.subplot_kw.pop('sharex', None) is not None: if self.subplot_kw.pop('sharex', None) is not None:
warnings.warn('sharex in subplot_kw not negotiable, dropping', UserWarning) warnings.warn('sharex in subplot_kw not negotiable, dropping', UserWarning)
# Keep track of instances that are alive for figure counting
self.__instances.add(self)
# TODO: this somehow never executes
weakref.finalize(self, self.__instances.discard, self)
def is_fig_open(self) -> bool: def is_fig_open(self) -> bool:
"""Is the figure currently open, pending all events?""" """Is the figure currently open, pending all events?"""
# Need to flush possible close events before we can be sure! # Need to flush possible close events before we can be sure!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment