From 38b8c37d0a43d802f59232428d6e55dbd37ddf4f Mon Sep 17 00:00:00 2001 From: Adrian Peter Krone Date: Tue, 24 Sep 2024 16:59:10 +0200 Subject: [PATCH] Adjusted AGEScanViewer --- MANIFEST.in | 2 +- src/agepy/interactive/_interactive.py | 20 ++++++++++++++++++-- src/agepy/interactive/icons/bw-step.svg | 1 + src/agepy/interactive/icons/fw-step.svg | 1 + src/agepy/interactive/photons.py | 17 ++++++----------- 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 src/agepy/interactive/icons/bw-step.svg create mode 100644 src/agepy/interactive/icons/fw-step.svg diff --git a/MANIFEST.in b/MANIFEST.in index e131dcf..41512de 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include src/agepy/ageplot/*.mplstyle -include src/agepy/interactive/icons/roi.svg \ No newline at end of file +include src/agepy/interactive/icons/*.svg \ No newline at end of file diff --git a/src/agepy/interactive/_interactive.py b/src/agepy/interactive/_interactive.py index 676c204..d365d48 100644 --- a/src/agepy/interactive/_interactive.py +++ b/src/agepy/interactive/_interactive.py @@ -56,13 +56,29 @@ def add_toolbar(self): def add_roi_action(self, callback: callable): # Add ROI button to toolbar - with imrsrc.path("agepy.interactive.icons", "roi.svg") as icon_path: - roi = QAction(QIcon(str(icon_path)), "Add ROI", self) + with imrsrc.path("agepy.interactive.icons", "roi.svg") as ipath: + roi = QAction(QIcon(str(ipath)), "Add ROI", self) roi.setCheckable(True) roi.triggered.connect(callback) actions = self.toolbar.actions() self.roi_button = self.toolbar.insertAction(actions[-1], roi) + def add_forward_backward_action(self, + bw_callback: callable, + fw_callback: callable + ) -> None: + actions = self.toolbar.actions() + # Add backward step to toolbar + with imrsrc.path("agepy.interactive.icons", "bw-step.svg") as ipath: + bw = QAction(QIcon(str(ipath)), "Step Backward", self) + bw.triggered.connect(bw_callback) + self.bw = self.toolbar.insertAction(actions[-1], bw) + # Add forward step to toolbar + with imrsrc.path("agepy.interactive.icons", "fw-step.svg") as ipath: + fw = QAction(QIcon(str(ipath)), "Step Forward", self) + fw.triggered.connect(fw_callback) + self.fw = self.toolbar.insertAction(actions[-1], fw) + class AGEpp: def __init__(self, viewer: QMainWindow, *args, **kwargs): self.app = QApplication.instance() diff --git a/src/agepy/interactive/icons/bw-step.svg b/src/agepy/interactive/icons/bw-step.svg new file mode 100644 index 0000000..3416f66 --- /dev/null +++ b/src/agepy/interactive/icons/bw-step.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/agepy/interactive/icons/fw-step.svg b/src/agepy/interactive/icons/fw-step.svg new file mode 100644 index 0000000..77de251 --- /dev/null +++ b/src/agepy/interactive/icons/fw-step.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/agepy/interactive/photons.py b/src/agepy/interactive/photons.py index db6ba28..3c79b5e 100644 --- a/src/agepy/interactive/photons.py +++ b/src/agepy/interactive/photons.py @@ -14,6 +14,12 @@ class AGEScanViewer(AGEDataViewer): def __init__(self, scan, bins: int = 512) -> None: super().__init__() + # Add plot to canvas + self.add_plot() + # Add the toolbar + self.add_toolbar() + # Add forward and backward buttons + self.add_forward_backward_action(self.plot_previous, self.plot_next) # Get the data self.y = [] self.err = [] @@ -24,17 +30,6 @@ def __init__(self, scan, bins: int = 512) -> None: self.err.append(err) # Remember current step self.step = 0 - # Add previous and next buttons - self.prev = QPushButton() - self.prev.clicked.connect(self.plot_previous) - icon_prev = self.style().standardIcon(QStyle.SP_ArrowBack) - self.prev.setIcon(icon_prev) - self.toolbar.addWidget(self.prev) - self.next = QPushButton() - self.next.clicked.connect(self.plot_next) - icon_next = self.style().standardIcon(QStyle.SP_ArrowForward) - self.next.setIcon(icon_next) - self.toolbar.addWidget(self.next) # Plot the first step self.plot(self.step)