Skip to content

Commit

Permalink
Add key events for rotaty encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc committed Apr 10, 2024
1 parent fdb12ae commit 08dd0bc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mantidimaging/gui/windows/main/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QPoint
from PyQt5.QtGui import QIcon, QDragEnterEvent, QDropEvent, QDesktopServices
from PyQt5.QtWidgets import QAction, QDialog, QLabel, QMessageBox, QMenu, QFileDialog, QSplitter, \
QTreeWidgetItem, QTreeWidget
QTreeWidgetItem, QTreeWidget, QDockWidget

from mantidimaging.core.data import ImageStack
from mantidimaging.core.data.dataset import StrictDataset
Expand Down Expand Up @@ -172,6 +172,27 @@ def _window_ready(self) -> None:
perf_logger.info(f"Mantid Imaging ready in {time.monotonic() - process_start_time}")
super()._window_ready()

def keyPressEvent(self, e):
# print(e.key(), e.modifiers())
if e.modifiers() & Qt.ControlModifier:
if e.key() == Qt.Key_F1:
#print("move CCW")
self.rotate(1)
if e.key() == Qt.Key_F2:
#print("move CW")
self.rotate(-1)

def rotate(self, steps: int):
ws = self.findChildren(QDockWidget)
for w in ws:
if not w.visibleRegion().isEmpty():
image_count = w.presenter.get_num_images()
step_size = max(1, image_count // 100)
current_image = w.image_view.currentIndex
#print(f"{image_count=} {step_size=} {current_image=}")
new_image = (current_image + step_size * steps) % image_count
w.image_view.set_selected_image(new_image)

def setup_shortcuts(self):
self.actionLoadDataset.triggered.connect(self.show_image_load_dialog)
self.actionLoadImages.triggered.connect(self.load_image_stack)
Expand Down

0 comments on commit 08dd0bc

Please sign in to comment.