Skip to content

Commit

Permalink
fix(interactive): keep pointer for imagetool, fix typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Apr 25, 2024
1 parent 9c30f1b commit c98c38e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/erlab/interactive/bzplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(

bvec = to_reciprocal(abc2avec(*params))
else:
if not isinstance(params, npt.NDArray):
if not isinstance(params, np.ndarray):
raise TypeError("Lattice vectors must be a numpy array.")
if params.shape != (3, 3):
raise TypeError("Lattice vectors must be a 3 by 3 numpy array.")
Expand Down
5 changes: 3 additions & 2 deletions src/erlab/interactive/imagetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
from typing import TYPE_CHECKING, Any, cast

import numpy as np
import numpy.typing as npt
import xarray as xr
from qtpy import QtCore, QtWidgets
Expand All @@ -43,7 +44,7 @@


def itool(
data: (Sequence[xr.DataArray | npt.NDArray] | xr.DataArray | npt.NDArray),
data: Sequence[xr.DataArray | npt.NDArray] | xr.DataArray | npt.NDArray,
link: bool = False,
link_colors: bool = True,
execute: bool | None = None,
Expand Down Expand Up @@ -94,7 +95,7 @@ def itool(
if isinstance(qapp, QtWidgets.QApplication):
qapp.setStyle("Fusion")

if isinstance(data, npt.NDArray | xr.DataArray):
if isinstance(data, np.ndarray | xr.DataArray):
data = cast(list[npt.NDArray | xr.DataArray], [data])

itool_list = [ImageTool(d, **kwargs) for d in data]
Expand Down
8 changes: 4 additions & 4 deletions src/erlab/interactive/imagetool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def value(self) -> float:
def mouseDragEvent(self, ev: mouseEvents.MouseDragEvent):
if (
QtCore.Qt.KeyboardModifier.ControlModifier
not in self.qapp.keyboardModifiers()
not in QtWidgets.QApplication.keyboardModifiers()
):
if self.movable and ev.button() == QtCore.Qt.MouseButton.LeftButton:
if ev.isStart():
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def mouseDragEvent(self, ev: mouseEvents.MouseDragEvent):
def mouseClickEvent(self, ev: mouseEvents.MouseClickEvent):
if (
QtCore.Qt.KeyboardModifier.ControlModifier
not in self.qapp.keyboardModifiers()
not in QtWidgets.QApplication.keyboardModifiers()
):
super().mouseClickEvent(ev)
else:
Expand All @@ -1025,7 +1025,7 @@ def mouseClickEvent(self, ev: mouseEvents.MouseClickEvent):
def hoverEvent(self, ev):
if (
QtCore.Qt.KeyboardModifier.ControlModifier
not in self.qapp.keyboardModifiers()
not in QtWidgets.QApplication.keyboardModifiers()
):
super().hoverEvent(ev)
else:
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def add_cursor(self, update=True):

self.cursor_lines.append({})
self.cursor_spans.append({})
for c, s, ax in zip(cursors, spans, self.display_axis, strict=True):
for c, s, ax in zip(cursors, spans, self.display_axis, strict=False):
self.cursor_lines[-1][ax] = c
self.cursor_spans[-1][ax] = s
self.addItem(c)
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/interactive/kspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ def show_converted(self):
wait_dialog.setLayout(QtWidgets.QVBoxLayout())
wait_dialog.layout().addWidget(QtWidgets.QLabel("Converting..."))
wait_dialog.open()
itool = ImageTool(
self._itool = ImageTool(
self.data.kspace.convert(bounds=self.bounds, resolution=self.resolution)
)
wait_dialog.close()
itool.show()
self._itool.show()

def copy_code(self):
arg_dict = {}
Expand Down

0 comments on commit c98c38e

Please sign in to comment.