From 7e947c56fa9c5f32a3d221160fde1eb665154382 Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Thu, 30 May 2024 20:34:30 +0900 Subject: [PATCH 1/6] Added the way that coordinates are copied to the clipboard --- plottr/plot/mpl/widgets.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index 027329d8..0e647148 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -123,6 +123,11 @@ def metaToClipboard(self) -> None: for k, v in self._meta_info.items()) clipboard.setText(meta_info_string) + def coordinateToClipboard(self, event): + clipboard = QtWidgets.QApplication.clipboard() + coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) + clipboard.setText(coord_info_string) + def setFigureTitle(self, title: str) -> None: """Add a title to the figure.""" self.fig.suptitle(title, @@ -162,6 +167,7 @@ def __init__(self, parent: Optional[PlotWidgetContainer] = None): layout.addWidget(self.plot) layout.addWidget(self.mplBar) self.setLayout(layout) + self.addPlotOptions() def setMeta(self, data: DataDictBase) -> None: """Add meta info contained in the data to the figure. @@ -195,6 +201,10 @@ def addMplBarOptions(self) -> None: self.mplBar.addSeparator() self.mplBar.addAction('Copy Figure', self.plot.toClipboard) self.mplBar.addAction('Copy Meta', self.plot.metaToClipboard) + + def addPlotOptions(self) -> None: + """Add options for copying coordinates to the clipboard""" + self.plot.mpl_connect('button_press_event', self.plot.coordinateToClipboard) def figureDialog() -> Tuple[Figure, QtWidgets.QDialog]: From ebdfc020e2601893f4e359f38c4f228261f20d42 Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Fri, 31 May 2024 10:52:11 +0900 Subject: [PATCH 2/6] remove bug from coordinateToClipboard --- plottr/plot/mpl/widgets.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index 0e647148..f24db4b9 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -123,10 +123,13 @@ def metaToClipboard(self) -> None: for k, v in self._meta_info.items()) clipboard.setText(meta_info_string) - def coordinateToClipboard(self, event): + def coordinateToClipboard(self, event) -> None: clipboard = QtWidgets.QApplication.clipboard() - coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) - clipboard.setText(coord_info_string) + try: + coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) + clipboard.setText(coord_info_string) + except TypeError: + pass def setFigureTitle(self, title: str) -> None: """Add a title to the figure.""" From cb1ae8b66134959c0fdf0242db50b48e87e3f5e7 Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:32:54 +0900 Subject: [PATCH 3/6] Fixed mypy error --- plottr/plot/mpl/widgets.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index f24db4b9..f72ed8bc 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -9,6 +9,7 @@ from matplotlib import rcParams from matplotlib.axes import Axes from matplotlib.figure import Figure +from matplotlib.backend_bases import Event from matplotlib.backends.backend_qt5agg import ( FigureCanvasQTAgg as FCanvas, NavigationToolbar2QT as NavBar, @@ -123,7 +124,7 @@ def metaToClipboard(self) -> None: for k, v in self._meta_info.items()) clipboard.setText(meta_info_string) - def coordinateToClipboard(self, event) -> None: + def coordinateToClipboard(self, event: Event) -> None: clipboard = QtWidgets.QApplication.clipboard() try: coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) From c422f3b89603fed71c905209a68695cdc9ccf0ff Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:24:37 +0900 Subject: [PATCH 4/6] Fixed mypy error 2 --- plottr/plot/mpl/widgets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index f72ed8bc..3dfb37a2 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -9,7 +9,7 @@ from matplotlib import rcParams from matplotlib.axes import Axes from matplotlib.figure import Figure -from matplotlib.backend_bases import Event +from matplotlib.backend_bases import LocationEvent from matplotlib.backends.backend_qt5agg import ( FigureCanvasQTAgg as FCanvas, NavigationToolbar2QT as NavBar, @@ -124,7 +124,7 @@ def metaToClipboard(self) -> None: for k, v in self._meta_info.items()) clipboard.setText(meta_info_string) - def coordinateToClipboard(self, event: Event) -> None: + def coordinateToClipboard(self, event: LocationEvent) -> None: clipboard = QtWidgets.QApplication.clipboard() try: coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) From 5c500591016f5674154376ad17d261f098b7c262 Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:01:29 +0900 Subject: [PATCH 5/6] Fixed mypy error 3 --- plottr/plot/mpl/widgets.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index 3dfb37a2..44829be8 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -9,7 +9,7 @@ from matplotlib import rcParams from matplotlib.axes import Axes from matplotlib.figure import Figure -from matplotlib.backend_bases import LocationEvent +from matplotlib.backend_bases import LocationEvent, Event from matplotlib.backends.backend_qt5agg import ( FigureCanvasQTAgg as FCanvas, NavigationToolbar2QT as NavBar, @@ -124,13 +124,14 @@ def metaToClipboard(self) -> None: for k, v in self._meta_info.items()) clipboard.setText(meta_info_string) - def coordinateToClipboard(self, event: LocationEvent) -> None: - clipboard = QtWidgets.QApplication.clipboard() - try: - coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) - clipboard.setText(coord_info_string) - except TypeError: - pass + def coordinateToClipboard(self, event: Event) -> None: + if isinstance(event, LocationEvent): + clipboard = QtWidgets.QApplication.clipboard() + if event.xdata is not None and event.ydata is not None: + coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) + clipboard.setText(coord_info_string) + else: + pass def setFigureTitle(self, title: str) -> None: """Add a title to the figure.""" From 17c5b3680081e46c02d1aae0b236345e76d6a381 Mon Sep 17 00:00:00 2001 From: yuimuto <48644462+yuiponpon@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:39:53 +0900 Subject: [PATCH 6/6] Change the number of significant figures. --- plottr/plot/mpl/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plottr/plot/mpl/widgets.py b/plottr/plot/mpl/widgets.py index 44829be8..bbbd2e24 100644 --- a/plottr/plot/mpl/widgets.py +++ b/plottr/plot/mpl/widgets.py @@ -128,7 +128,7 @@ def coordinateToClipboard(self, event: Event) -> None: if isinstance(event, LocationEvent): clipboard = QtWidgets.QApplication.clipboard() if event.xdata is not None and event.ydata is not None: - coord_info_string = '({:.4g}, {:.4g})'.format(event.xdata, event.ydata) + coord_info_string = '({:.8g}, {:.8g})'.format(event.xdata, event.ydata) clipboard.setText(coord_info_string) else: pass