Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Improve vline #181

Merged
merged 14 commits into from
Aug 2, 2023
21 changes: 17 additions & 4 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
(0, 255, 255): (0, 139, 139), # 'darkcyan'
}

_vline_color = (0, 191, 0)


def _get_color(color_spec, invert=False):
"""Wrap mkColor to accept all possible matplotlib color-specifiers."""
Expand Down Expand Up @@ -1340,7 +1342,7 @@ class VLineLabel(InfLineLabel):

def __init__(self, vline):
super().__init__(vline, text='{value:.3f} s', position=0.98,
fill='g', color='b', movable=True)
fill=_vline_color, color='k', movable=True)
self.cursorOffset = None

def mouseDragEvent(self, ev):
Expand Down Expand Up @@ -1376,16 +1378,25 @@ def valueChanged(self):
self.setText(self.format.format(value=value))
self.updatePosition()

def hoverEvent(self, ev):
_methpartial(self.line.hoverEvent)(ev)


class VLine(InfiniteLine):
"""Marker to be placed inside the Trace-Plot."""

def __init__(self, mne, pos, bounds):
super().__init__(pos, pen='g', hoverPen='y',
super().__init__(pos, pen={"color": _vline_color, "width": 2}, hoverPen='y',
movable=True, bounds=bounds)
self.mne = mne
self.label = VLineLabel(self)

def setMouseHover(self, hover):
super().setMouseHover(hover)
# Also change color of label
self.label.fill = self.currentPen.color()
self.label.border = self.currentPen


def _q_font(point_size, bold=False):
font = QFont()
Expand Down Expand Up @@ -3411,6 +3422,7 @@ def __init__(self, **kwargs):
# disable histogram of epoch PTP amplitude
del self.mne.keyboard_shortcuts["h"]


def _hidpi_mkPen(self, *args, **kwargs):
kwargs['width'] = self._pixel_ratio * kwargs.get('width', 1.)
return mkPen(*args, **kwargs)
Expand Down Expand Up @@ -4706,10 +4718,11 @@ def closeEvent(self, event):
if getattr(self.mne, 'vline', None) is not None:
if self.mne.is_epochs:
for vl in self.mne.vline:
_disconnect(vl.sigPositionChangeFinished)
_disconnect(vl.sigPositionChangeFinished, allow_error=True)
self.mne.vline.clear()
else:
_disconnect(self.mne.vline.sigPositionChangeFinished)
_disconnect(self.mne.vline.sigPositionChangeFinished,
allow_error=True)
if getattr(self, 'load_thread', None) is not None:
self.load_thread.clean()
self.load_thread = None
Expand Down